The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
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'); ?> < |
#2
|
||||
|
||||
Try:
PHP Code:
|
#3
|
||||
|
||||
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 |
#4
|
||||
|
||||
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... |
#5
|
||||
|
||||
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 |
#6
|
||||
|
||||
Check it again, should work. Time to do dishes though, bye.
|
#7
|
||||
|
||||
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? |
#8
|
||||
|
||||
Try the updated PHP code again.
Those errors are from insufficient permission to the db. |
#9
|
||||
|
||||
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? |
#10
|
||||
|
||||
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.
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|