Jump to content

error on submiting data to database


TheSky

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/236734-error-on-submiting-data-to-database/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.