Jump to content

[SOLVED] Can't spot the error in 1 line.


Potatis

Recommended Posts

I can't spot it. This is code I have used several times before.

 

"Fatal error: SQL in /home/.hebrew/dclfilez/domain.com/folder/contact_process.php on line 17"

 

The page is to process a simple contact form. Here is line 17:

 

mysql_query("INSERT INTO contact (time, ip, name, email, message, unread, read) VALUES ('$time', '$ip', '$name', '$email', '$message', '$unread', '$read')") or trigger_error("SQL", E_USER_ERROR);

 

The full code for this processing page"

 

<?php

require_once("includes/constants.php");
require_once("includes/connection.php");

$b = time ();
$timezone = (date_default_timezone_set("Australia/Sydney"));
$time = date ("Y-m-d H:i:s,$b");

$ip = mysql_real_escape_string($_POST['ip']);
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
$message = mysql_real_escape_string($_POST['message']);
$unread = "1";
$read = "0";

mysql_query("INSERT INTO contact (time, ip, name, email, message, unread, read) VALUES ('$time', '$ip', '$name', '$email', '$message', '$unread', '$read')") or trigger_error("SQL", E_USER_ERROR);



header("Location: index.php");




?>

 

I hope someone can see what I can't.

Link to comment
Share on other sites

Change this:

<?php
mysql_query("INSERT INTO contact (time, ip, name, email, message, unread, read) VALUES ('$time', '$ip', '$name', '$email', '$message', '$unread', '$read')") or trigger_error("SQL", E_USER_ERROR);
?>

to

<?php
$q = "INSERT INTO contact (time, ip, name, email, message, unread, read) VALUES ('$time', '$ip', '$name', '$email', '$message', '$unread', '$read')";
$rs = mysql_query($q) or die("Problem with the query: $q on line " . __LINE__ . '<br>' . mysql_error());
?>

 

Doing this will give you a much better indication as to the error that is causing the problem.

 

Ken

Link to comment
Share on other sites

Thanks for that, it did give me more info, but I can't see what it has a problem with.. It's really weird.

 

I crossed out the IP. It was just a test post.

 

Problem with the query: INSERT INTO contact (time, ip, name, email, message, unread, read) VALUES ('2008-07-18 13:50:00,1216353000', 'xxx.xxx.xxx.xx', 'Herr Moose', 'none@ofyourbusiness.com', 'HELLO!!!!!!!!', '1', '0') on line 18

 

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 'read) VALUES ('2008-07-18 13:50:00,1216353000', 'xxx.xxx.xxx.xx', 'Herr Moose ' at line 1

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.