TheSky Posted May 18, 2011 Share Posted May 18, 2011 Hey im agen stuck on code i get 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 but i think i have all correct if i submit i get values but that dont add in database <?php //Values if(isset($_POST['Submit'])) { $request = preg_replace("/[^0-9a-zA-Z]/","",$_SERVER['REQUEST_URI']); $ip = preg_replace("/[^0-9a-zA-Z]/","",$_SERVER['REMOTE_ADDR']); $referer = preg_replace("/[^0-9a-zA-Z]/","",$_SERVER['HTTP_REFERER']); $agent = preg_replace("/[^0-9a-zA-Z]/","",$_SERVER['HTTP_USER_AGENT']); //Open connection include('connectx.php'); //Test is there connection available $query=("Select * from Error where date='NOW()'"); $result= mysql_query($query); $num=mysql_num_rows($result); //Add data $query=("INSERT INTO Error (id,request,ip,referer,date,agent) VALUES ('NULL','$request','$ip','$referer',NOW(),'$agent'"); if (@mysql_query($query)) { echo('<p>Error code has succesfuly send</p>'); } else { echo ("Error was in submiting code").mysql_error(); } mysql_close(); } ?> any help will become welcome Quote Link to comment https://forums.phpfreaks.com/topic/236734-error-on-submiting-data-to-database/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 18, 2011 Share Posted May 18, 2011 If you output the $query variable as part of your error checking/error reporting logic, you can probably see what is causing the problem. While it probably doesn't have anything to do with the error, in your first query, NOW() should not be enclosed by single-quotes as that makes it a string made up of the characters 'N O W ( )' and not the mysql function NOW(). Also, NOW() returns a datatime value. I suspect you wanted to use CURDATE() (just the date.) You are also not using the result from the first query. In your second query, NULL should not be enclosed by single-quotes as that makes it a string made up of the characters 'N U L L' and not the mysql keyword NULL. Quote Link to comment https://forums.phpfreaks.com/topic/236734-error-on-submiting-data-to-database/#findComment-1216944 Share on other sites More sharing options...
TheSky Posted May 18, 2011 Author Share Posted May 18, 2011 my mistake was on closing correct $query=("INSERT INTO Error (id,request,ip,referer,agent) VALUES ('NULL','$request','$ip','$referer','$agent')"); but thanks anyways Quote Link to comment https://forums.phpfreaks.com/topic/236734-error-on-submiting-data-to-database/#findComment-1216969 Share on other sites More sharing options...
PFMaBiSmAd Posted May 18, 2011 Share Posted May 18, 2011 If you remove the () from around the outside of your php string (they are unnecessary), it would make it easier to see what your actual sql syntax is. Quote Link to comment https://forums.phpfreaks.com/topic/236734-error-on-submiting-data-to-database/#findComment-1216971 Share on other sites More sharing options...
TheSky Posted May 18, 2011 Author Share Posted May 18, 2011 yes, sure i did it Quote Link to comment https://forums.phpfreaks.com/topic/236734-error-on-submiting-data-to-database/#findComment-1216978 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.