Tunnleram Posted September 10, 2006 Share Posted September 10, 2006 I'm going through a tutorial (this is after doing several things with php/mysql so I'm not a complete noob, just relearning sorta) and I'm having issues getting it to work locally. I have Xampp installed, php, apache and mysql are all working. I can insert from mysql without an issue, but whenever I try to insert any data using php it fails.When I run the page below I get 'Error, insert query failed', but everything looks right. Am I missing something? PHP Version 5.1.4Mysql 5.0.21 Apache 2.2.2[code]<html><head><title>Add New MySQL User</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><?phpif(isset($_POST['add'])){include 'config.php';include 'opendb.php';$username = $_POST['username'];$password = $_POST['password'];$query = "INSERT INTO user (host, user, password, select_priv, insert_priv, update_ priv) VALUES ('localhost', '$username', PASSWORD('$password'), 'Y', 'Y', 'Y')";mysql_query($query) or die('Error, insert query failed');$query = "FLUSH PRIVILEGES";mysql_query($query) or die('Error, insert query failed');include 'closedb.php';echo "New MySQL user added";}else{?><form method="post"><table width="400" border="0" cellspacing="1" cellpadding="2"><tr> <td width="100">Username</td><td><input name="username" type="text" id="username"></td></tr><tr> <td width="100">Password</td><td><input name="password" type="text" id="password"></td></tr><tr> <td width="100"> </td><td> </td></tr><tr> <td width="100"> </td><td><input name="add" type="submit" id="add" value="Add New User"></td></tr></table></form><?php}?></body></html>[/code]Any help much appreciated. Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 10, 2006 Share Posted September 10, 2006 You can get more useful information by changing the error messages in each case. You can't tell with your present messages which query failed or why.Change:[code]mysql_query($query) or die('Error, insert query failed');[/code]to:[code]$result = mysql_query($query) or die('Error '. mysql_error(). ' with query '. $query);[/code] Quote Link to comment Share on other sites More sharing options...
Tunnleram Posted September 10, 2006 Author Share Posted September 10, 2006 I get this now:[code]Error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'priv) VALUES ('localhost', 'testuser', PASSWORD('password'), 'Y', 'Y', 'Y')' at line 1 with query INSERT INTO user (host, user, password, select_priv, insert_priv, update_ priv) VALUES ('localhost', 'testuser', PASSWORD('password'), 'Y', 'Y', 'Y')[/code] Quote Link to comment Share on other sites More sharing options...
jefkin Posted September 11, 2006 Share Posted September 11, 2006 Hi Tunnleram,looks like you need to change this line:[code]$query = "INSERT INTO user (host, user, password, select_priv, insert_priv, update_ priv) VALUES ('localhost', '$username', PASSWORD('$password'), 'Y', 'Y', 'Y')";[/code]into this:[code]$query = "INSERT INTO user (host, user, password, select_priv, insert_priv, update_priv) VALUES ('localhost', '$username', PASSWORD('$password'), 'Y', 'Y', 'Y')"; ^^^^^^^^^^^[/code]The 'update_' and the 'priv' need to go together!!Jeff Quote Link to comment Share on other sites More sharing options...
Tunnleram Posted September 11, 2006 Author Share Posted September 11, 2006 lol thx! Damn tutorials. I copy and pasted that hehe doh! Quote Link to comment 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.