sagisgirl Posted December 16, 2012 Share Posted December 16, 2012 hello guys..im new here.. nice to meet u all.. i've a prob..i cant solve it...can someone please help me... i've got an error like this 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 9 and here are my codes.. <?php #Connect to database $conn = mysql_connect("localhost", "root", "root"); mysql_select_db("spidb", $conn); if ( isset($_POST['save']) && ($_POST['save']) != "" ) { if ( ($_POST['userName']) || ($_POST['password']) ) { #Get values from textfield['name kt form'] $groupCode= $_POST['groupCode']; $username = $_POST['userName']; $password = $_POST['password']; $email = $_POST['email']; $userStatus = $_POST['userStatus']; $sql = "INSERT INTO u_user(userID,groupCode,userName,password,email,userStatus) VALUES ( '".$_POST['groupCode']."', '".addslashes(strtoupper($_POST['userName']))."', '".addslashes(strtoupper($_POST['password']))."', '".addslashes(strtoupper($_POST['email']))."', '".addslashes(strtoupper($_POST['userStatus']))."', )"; $rslt = mysql_query($sql,$conn); if (!$rslt) { die('Error: ' . mysql_error()); } } } $query_recCode = "SELECT * FROM u_usergroup ORDER BY groupDesc"; $rc_recCode = mysql_query($query_recCode); $totalRows_recCode = mysql_num_rows($rc_recCode); ?> <head><title>..::ADD USER::..</title></head> <body> <h2 align="center" style="font-style:inherit"> ADD USER</h2> <form action="<? $_SERVER['../PHP_SELF']; ?>" method="post"> <span class="alert"><?php echo $alert; ?></span> <?php if($rslt){ ?> <h3 align="center" style="margin:5px; background:#CCCCCC; font-family:'Times New Roman', Times, serif; font-size:18px; border:1px solid #CCC; color:#OOO; border-radius:10px 10px 10px 10px; text-align:center; margin-top:15px; width:500px; margin-left:200px"> You have successfully add users!</h3> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/272042-can-someone-help-meplleeaase/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 16, 2012 Share Posted December 16, 2012 Look at the end of line 8 in your query, for an extra character that implies there are more data values. Quote Link to comment https://forums.phpfreaks.com/topic/272042-can-someone-help-meplleeaase/#findComment-1399619 Share on other sites More sharing options...
sagisgirl Posted December 16, 2012 Author Share Posted December 16, 2012 i'm sorry, but i still didnt get it..sholud i change this if ( isset($_POST['save']) && ($_POST['save']) != "" ) { if ( ($_POST['userName']) || ($_POST['password']) ) to this if ( isset($_POST['save']) && $_POST['save'] != "" ) { if ( $_POST['userName'] || $_POST['password'] ) i remove some brackets there.. Quote Link to comment https://forums.phpfreaks.com/topic/272042-can-someone-help-meplleeaase/#findComment-1399630 Share on other sites More sharing options...
PFMaBiSmAd Posted December 16, 2012 Share Posted December 16, 2012 (edited) ^^^ That's not a line in your query. Those are lines of php code. This is your error message - 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 9 This is the code producing the SQL query statement - $sql = "INSERT INTO u_user(userID,groupCode,userName,password,email,userStatus) VALUES ( '".$_POST['groupCode']."', '".addslashes(strtoupper($_POST['userName']))."', '".addslashes(strtoupper($_POST['password']))."', '".addslashes(strtoupper($_POST['email']))."', '".addslashes(strtoupper($_POST['userStatus']))."', )"; Edited December 16, 2012 by PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/272042-can-someone-help-meplleeaase/#findComment-1399670 Share on other sites More sharing options...
sagisgirl Posted December 19, 2012 Author Share Posted December 19, 2012 ok.. then i change the code to this.. <?php #Connect to database $conn = mysql_connect("localhost", "root", "root"); mysql_select_db("spidb", $conn); if ( isset($_POST['save']) && $_POST['save'] != "" ) { if ( $_POST['userName'] || $_POST['password'] ) { $sql = "INSERT INTO u_user(userID,groupCode,userName,password,email,userStatus) VALUES ( '".$_POST['groupCode']."', '".addslashes(strtoupper($_POST['userName']))."', '".addslashes(strtoupper($_POST['password']))."', '".addslashes(strtoupper($_POST['email']))."', '".addslashes(strtoupper($_POST['userStatus']))."', )"; $rslt = mysql_query($sql,$conn); if (!$rslt) { die('Error: ' . mysql_error()); } } } $query_recCode = "SELECT * FROM u_usergroup ORDER BY groupDesc"; $rc_recCode = mysql_query($query_recCode); $totalRows_recCode = mysql_num_rows($rc_recCode); ?> <html> <head> <!-- <link rel="stylesheet" href="css/style.css"/>--> <title>..::TAMBAH PENGGUNA::..</title> </head> <body> <h3 align="center"> SISTEM PEMANTAUAN INVENTORI </h3> <h2 align="center" style="font-style:inherit"> Tambah Pengguna </h2> <form action="<? $_SERVER['../PHP_SELF']; ?>" method="post"> <span class="alert"><?php echo $alert; ?></span> <?php if($rslt) { ?> <h3 align="center" style="margin:5px; background:#CCCCCC; font-family:'Times New Roman', Times, serif; font-size:18px; border:1px solid #CCC; color:#OOO; border-radius:10px 10px 10px 10px; text-align:center; margin-top:15px; width:500px; margin-left:200px"> Pengguna telah berjaya ditambah!</h3> <? } ?> but i still got the same error, 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 ')' at line 9 why..? Im so confused right now..please help me solve it.. :'( Quote Link to comment https://forums.phpfreaks.com/topic/272042-can-someone-help-meplleeaase/#findComment-1400222 Share on other sites More sharing options...
jazzman1 Posted December 19, 2012 Share Posted December 19, 2012 That one is wrong too: http://dev.mysql.com...rting-rows.html "SELECT * FROM u_usergroup ORDER BY groupDesc" Quote Link to comment https://forums.phpfreaks.com/topic/272042-can-someone-help-meplleeaase/#findComment-1400229 Share on other sites More sharing options...
sagisgirl Posted December 19, 2012 Author Share Posted December 19, 2012 jazzman... that query is wrong? what is wrong with that query? Quote Link to comment https://forums.phpfreaks.com/topic/272042-can-someone-help-meplleeaase/#findComment-1400234 Share on other sites More sharing options...
sagisgirl Posted December 19, 2012 Author Share Posted December 19, 2012 (edited) im writting this code again on the another file. then im getting a new error. the error : Warning: mysql_query() expects at least 1 parameter, 0 given in C:\AppServ\www\Epic_SPI\aUser1.php on line 22 Error: <?php #conect to database $conn = mysql_connect("localhost","root","root"); mysql_select_db("spidb",$conn); if ( isset($_POST['save']) && $_POST['save'] != "") { if ($_POST['userName'] || $_POST['password'] ) { $sql = "INSERT INTO u_user (userName,groupCode,userName,password,email,userStatus) VALUES '".$_POST['groupCode']."', '".addslashes(strtoupper($_POST['userName']))."', '".addslashes(strtoupper($_POST['password']))."', '".addslashes(strtoupper($_POST['email']))."', '".addslashes(strtoupper($_POST['userStatus']))."')"; $rslt = mysql_query($sql,$conn); if (!$rslt) { die('Error:'. mysql_query()); } } } $query_recCode = "SELECT * FROM u_usergroup ORDER BY groupDesc"; $rc_recCode = mysql_query($query_recCode); $totalRows_recCode = mysql_num_rows($rc_recCode); ?> <html> <head><title></title></head> <body> <h3 align="center">SPI </h3> <h2 align="center" style="font-style:inherit"> User </h2> <form action="<? $_SERVER['../PHP_SELF']; ?>" method="post"> <span class="alert"><?php echo $alert; ?></span> <?php if($rslt) { ?> <h3 align="center" style="margin:5px; background:#CCCCCC; font-family:'Times New Roman', Times, serif; font-size:18px; border:1px solid #CCC; color:#OOO; border-radius:10px 10px 10px 10px; text-align:center; margin-top:15px; width:500px; margin-left:200px"> Pengguna telah berjaya ditambah!</h3> <? } ?> actually there is not much different with the one that i posted. what is the error means? im new in php.please help me. Edited December 19, 2012 by sagisgirl Quote Link to comment https://forums.phpfreaks.com/topic/272042-can-someone-help-meplleeaase/#findComment-1400238 Share on other sites More sharing options...
Barand Posted December 19, 2012 Share Posted December 19, 2012 I think that you meant die('Error:'. mysql_error()); instead of die('Error:'. mysql_query()); Quote Link to comment https://forums.phpfreaks.com/topic/272042-can-someone-help-meplleeaase/#findComment-1400251 Share on other sites More sharing options...
sagisgirl Posted December 20, 2012 Author Share Posted December 20, 2012 Thanks for the reply..ok, i already change it to die('Error:' . mysql_error()); but then i got another error on line 4.. error in your SQL syntax; what does it mean...? is it the query for connect to database is incorrect? Quote Link to comment https://forums.phpfreaks.com/topic/272042-can-someone-help-meplleeaase/#findComment-1400512 Share on other sites More sharing options...
sagisgirl Posted December 20, 2012 Author Share Posted December 20, 2012 ok..i already got it...i left a bracket after VALUES... haha..silly me..thanks to all of you helping me..thank you so much... Quote Link to comment https://forums.phpfreaks.com/topic/272042-can-someone-help-meplleeaase/#findComment-1400521 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.