ilikephp Posted January 15, 2008 Share Posted January 15, 2008 hello, i am using a form that contains radio buttons. when I enter the fields and submit I receive this message: Warning: mysql_query() [function.mysql-query]: Access denied for user 'xxx'@'localhost' (using password: NO) in /home/xxx/public_html/form.php on line 45 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/xxx/public_html/form.php on line 45 Access denied for user 'xxx'@'localhost' (using password: NO) the line 45 contains: mysql_query("update `members` SET first_name='$fname', last_name='$lname', age='$age' ") or die(mysql_error()); what should I do please coz I am sure that password is correct; or maybe the code in sql is wrong? the code in sql is: CREATE TABLE members ( id int(4) NOT NULL auto_increment, first_name varchar(100) NOT NULL default '', last_name varchar(100) NOT NULL default '', age bigint(10) NOT NULL default '0', PRIMARY KEY (id) ) TYPE=MyISAM; can u help plzzz!!!! thanks Quote Link to comment https://forums.phpfreaks.com/topic/86177-solved-mysql_query/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 15, 2008 Share Posted January 15, 2008 The error means that when the mysql_query() statement executed, there was no valid connection to the mysql server and a connection using all default values was attempted, which of course failed. To get help with why your mysql_connect() statement is not working, you would need to post your code. Also, is there a reason why you posted this in the Microsoft SQL - MMSQL section since it is a mysql question? Quote Link to comment https://forums.phpfreaks.com/topic/86177-solved-mysql_query/#findComment-440209 Share on other sites More sharing options...
ilikephp Posted January 16, 2008 Author Share Posted January 16, 2008 hello, I posted here because I saw: SQL related to php: I will post all my scripts because I still have the same errors: connect.php: <?php $host="localhost"; // Host name $username="***"; // Mysql username $password="****"; // Mysql password $db_name="*****"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); $datetime=date("y-m-d h:i:s"); //date time $sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')"; $result=mysql_query($sql); //mysql_close(); ?> * I think that there is an error in the last 5 lines inside the phpMyAdmin: CREATE TABLE members ( id int(4) NOT NULL auto_increment, first_name varchar(100) NOT NULL default '', last_name varchar(100) NOT NULL default '', age bigint(10) NOT NULL default '0', PRIMARY KEY (id) ) TYPE=MyISAM; form.php: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php include("connect.php"); echo " <form action=?action=form method=\"post\"> Please selcet your age : <br /> <input type=\"radio\" name=\"age\" value=10 checked>10 years || <input type=\"radio\" name=\"age\" value=11>11 years <br /> <input type=\"radio\" name=\"age\" value=12>12 years || <input type=\"radio\" name=\"age\" value=13>13 years <br /> <input type=\"radio\" name=\"age\" value=14>14 years || <input type=\"radio\" name=\"age\" value=15>15 years <br /> <br /> Now please enter your First name : <br /> <input type=\"text\" name=\"fname\" value=\"First Name\"> <br /><br /> Now please enter your Last name : <br /> <input type=\"text\" name=\"lname\" value=\"Last Name\"> <br /> <br /> <input type=\"submit\" value=\"submit\"> || <input type=\"reset\" value=\"reset fields\"> <br /><br />"; if($_GET['action'] == 'form') { if($_POST['age'] == "" | $_POST['fname'] == "" | $_POST['lname'] == "" ) { echo " Please fill all forms in "; } else { $age = $_POST['age']; $fname = $_POST['fname']; $lname = $_POST['lname']; echo "Hello ".$fname." ".$lname." Your age is ".$age." Record enterd in the database as well."; mysql_query("update `members` set first_name='$fname', last_name='$lname', age='$age' ") or die(mysql_error()); } } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/86177-solved-mysql_query/#findComment-441230 Share on other sites More sharing options...
ilikephp Posted January 17, 2008 Author Share Posted January 17, 2008 can someone try this code plz and report to me why it is not uplading to the database? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/86177-solved-mysql_query/#findComment-441698 Share on other sites More sharing options...
PFMaBiSmAd Posted January 17, 2008 Share Posted January 17, 2008 The include statement - include("connect.php"); is probably failing due to a wrong path or the mysql_close(); statement inside connect.php is not commented out in the actual code and is closing the database connection. Also, the code in connect.php that is setting up a query and executing it appears to be left over from some other script and would be inserting rows with empty values into your database. Check your web server log for errors or turn on full php error reporting to find out if the include() statement is working or not. Quote Link to comment https://forums.phpfreaks.com/topic/86177-solved-mysql_query/#findComment-441744 Share on other sites More sharing options...
ilikephp Posted January 17, 2008 Author Share Posted January 17, 2008 please, how can I check my web server log for errors or turn on full php error reporting ? thanks Quote Link to comment https://forums.phpfreaks.com/topic/86177-solved-mysql_query/#findComment-441759 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.