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
https://forums.phpfreaks.com/topic/115342-solved-cant-spot-the-error-in-1-line/
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

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', '[email protected]', '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

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.