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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.