Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-12-2005, 01:18 AM
TruthElixirX's Avatar
TruthElixirX TruthElixirX is offline
 
Join Date: Sep 2004
Location: Oklahoma
Posts: 517
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Can't connect to database right (PHP/MySQL)

Code:
<?php

$username = "cms";
$password = "***INSERT PASS HERE****";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password)
	or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";

// make CMS the current db
mysql_select_db('CMS');
    or die ("Unable to connect to CMS");
print "Connected to CMS";
{
$comments = mysql_real_escape_string($_GET['comments']);
$body = mysql_real_escape_string($_GET['body']);
$title = mysql_real_escape_string($_GET['title']);

mysql_query('INSERT INTO articles (articlename , body , comments) values ($title, $body, $comments)');
}
mysql_close('CMS');
?>
I keep getting errors. I keep trying so..can someone show me what I'm doing wrong..and yes I knowq the code is a mess..I don't need clean code as of now..jsut functional code..>.
<
Reply With Quote
  #2  
Old 06-12-2005, 01:30 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try:
PHP Code:
<?php

$username 
"cms";
$password "CENSORED";
$hostname "localhost";
$dbh mysql_connect($hostname$username$password);
if (!
$dbh)
{
    echo 
'Unable to connect';
}
print 
"Connected to MySQL<br>";

// make CMS the current db
$db mysql_select_db('CMS');
if (!
$db)
{
    print 
"Unable to connect to CMS";
}
print 
"Connected to CMS";

$comments mysql_real_escape_string($_GET['comments']);
$body mysql_real_escape_string($_GET['body']);
$title mysql_real_escape_string($_GET['title']);

mysql_query("
    INSERT INTO articles (articlename , body , comments) values ('
$title', '$body', '$comments'
"
);

mysql_close("$dbh");
?>
Reply With Quote
  #3  
Old 06-12-2005, 01:32 AM
TruthElixirX's Avatar
TruthElixirX TruthElixirX is offline
 
Join Date: Sep 2004
Location: Oklahoma
Posts: 517
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can you show me what you changed? Cause I'm really trying to learn how o do this on my own.

EDIT:: Oops..forgot to say thanks..so Thanks.


EDIT 2:: After upladoing that and trying to get this ot work I got this error:

Parse error: parse error, unexpected T_LOGICAL_OR in /home/httpd/vhosts/supportcore.org/httpdocs/mycms/articlesubmit.php on line 12

Also I just noticed I put my DB password on here...crap..Could you edit it out for me? In ur post I mean
Reply With Quote
  #4  
Old 06-12-2005, 01:36 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No problem, does it work?

I'm not sure why you put { after print and } after the the $title line. Wasn't supposed to be there, and I just cleaned up your query syntax a bit (added 's and put the whole thing in double quotes).

Try updated one...
Reply With Quote
  #5  
Old 06-12-2005, 01:40 AM
TruthElixirX's Avatar
TruthElixirX TruthElixirX is offline
 
Join Date: Sep 2004
Location: Oklahoma
Posts: 517
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks. No it didn't work. See edits. .

But thanks for the explanation.


EDIT:: Didn't work again:

Parse error: parse error, unexpected T_IF in /home/httpd/vhosts/supportcore.org/httpdocs/mycms/articlesubmit.php on line 7
Reply With Quote
  #6  
Old 06-12-2005, 01:43 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Check it again, should work. Time to do dishes though, bye.
Reply With Quote
  #7  
Old 06-12-2005, 01:53 AM
TruthElixirX's Avatar
TruthElixirX TruthElixirX is offline
 
Join Date: Sep 2004
Location: Oklahoma
Posts: 517
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm... I was geting some errors but fixed them and now only have one and it is this:

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/httpd/vhosts/supportcore.org/httpdocs/mycms/articlesubmit.php on line 29


Also it doesn't seem to be adding the data to the table. It is just conencting to the database and then not closing. It doesn't seem to be doing anything with the user input.

http://www.supportcore.org/mycms/submitarticle.html

And yes..I'm working on a CMS...And yes..I know I'm a super long ways off.


EDIT:: Hmm..I haven't changed anything and I tried again out of sheer curiosity and got the following erros:

Warning: mysql_connect(): Access denied for user: 'cms@localhost' (Using password: YES) in /home/httpd/vhosts/supportcore.org/httpdocs/mycms/articlesubmit.php on line 6
Unable to connectConnected to MySQL

Warning: mysql_select_db(): Access denied for user: 'apache@localhost' (Using password: NO) in /home/httpd/vhosts/supportcore.org/httpdocs/mycms/articlesubmit.php on line 14

Warning: mysql_select_db(): A link to the server could not be established in /home/httpd/vhosts/supportcore.org/httpdocs/mycms/articlesubmit.php on line 14
Connected to CMS
Warning: mysql_real_escape_string(): Access denied for user: 'apache@localhost' (Using password: NO) in /home/httpd/vhosts/supportcore.org/httpdocs/mycms/articlesubmit.php on line 21

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/httpd/vhosts/supportcore.org/httpdocs/mycms/articlesubmit.php on line 21

Warning: mysql_real_escape_string(): Access denied for user: 'apache@localhost' (Using password: NO) in /home/httpd/vhosts/supportcore.org/httpdocs/mycms/articlesubmit.php on line 22

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/httpd/vhosts/supportcore.org/httpdocs/mycms/articlesubmit.php on line 22

Warning: mysql_real_escape_string(): Access denied for user: 'apache@localhost' (Using password: NO) in /home/httpd/vhosts/supportcore.org/httpdocs/mycms/articlesubmit.php on line 23

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/httpd/vhosts/supportcore.org/httpdocs/mycms/articlesubmit.php on line 23

Warning: mysql_query(): Access denied for user: 'apache@localhost' (Using password: NO) in /home/httpd/vhosts/supportcore.org/httpdocs/mycms/articlesubmit.php on line 27

Warning: mysql_query(): A link to the server could not be established in /home/httpd/vhosts/supportcore.org/httpdocs/mycms/articlesubmit.php on line 27

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/httpd/vhosts/supportcore.org/httpdocs/mycms/articlesubmit.php on line 29

But anyways..any reason why it isn't donig anything with the user input?
Reply With Quote
  #8  
Old 06-12-2005, 02:22 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try the updated PHP code again.

Those errors are from insufficient permission to the db.
Reply With Quote
  #9  
Old 06-12-2005, 02:29 AM
TruthElixirX's Avatar
TruthElixirX TruthElixirX is offline
 
Join Date: Sep 2004
Location: Oklahoma
Posts: 517
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I figured out the problem with insuffiecnt privilages. I changed my db pass and forgot to update it. But it still doesn't seem to be sending anything to the database....I double checked to make sure I was lookngi in the right one and I was...hmm...>.<...

And for soem erason it still isn't closing the DB conenction.

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/httpd/vhosts/supportcore.org/httpdocs/mycms/articlesubmit.php on line 29

Could the reason it isn't submitting to the database be an error in my HTML coding?
Reply With Quote
  #10  
Old 06-12-2005, 02:32 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try removing quotes from that last line (around $dbh). Your HTML looked fine when I glanced at it. I'll look tomorrow when I'm not half asleep.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:02 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04766 seconds
  • Memory Usage 2,267KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete