ruuyx Posted March 23, 2007 Share Posted March 23, 2007 Hi I'm pretty new to this and tried to install a Login system to my website. I got 7 php files online that i have edited to my requirements and have created a database on my host. while trying to fill out the register.html file online and running it ( register.php..background) i got this message: Could not insert data because 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 ')' at line 1 what can i do to correct this error so the register.html will load registration infos to the table? this is what my register.php and config.php looks like <?php include("config.php"); // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); // check if the username is taken $check = "select id from $table where username = '".$_POST['username']."';"; $qry = mysql_query($check) or die ("Could not match data because ".mysql_error()); $num_rows = mysql_num_rows($qry); if ($num_rows != 0) { echo "Sorry, there the username $username is already taken.<br>"; echo "<a href=register.html>Try again</a>"; exit; } else { // insert the data $insert = mysql_query("insert into $table values ('NULL', '".$_POST['username']."', '".$_POST['password']."', '".$_POST['firstname']."', '".$_POST['lastname']."', // print a success message echo "Your user account has been created!<br>"; echo "Now you can <a href=login.html>log in</a>"; } ?> [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/43984-solved-syntax-to-use-near-on-mysql-4121/ Share on other sites More sharing options...
AndyB Posted March 23, 2007 Share Posted March 23, 2007 $insert = mysql_query("insert into $table values ('NULL', '".$_POST['username']."', '".$_POST['password']."', '".$_POST['firstname']."', '".$_POST['lastname']."'"); I *hate* convoluted concatenations. As a guideline, separate the construction of the query from the execution and use sensible error trapping: $query = "insert into $table values ..."; $result = mysql_query($query) or die("error: ". mysql_error(). " with query ". $query); Link to comment https://forums.phpfreaks.com/topic/43984-solved-syntax-to-use-near-on-mysql-4121/#findComment-213714 Share on other sites More sharing options...
ruuyx Posted March 24, 2007 Author Share Posted March 24, 2007 Worked like a gem. Thanx Link to comment https://forums.phpfreaks.com/topic/43984-solved-syntax-to-use-near-on-mysql-4121/#findComment-214119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.