Jump to content

Recommended Posts

$query="INSERT INTO c$p ('id', 'Date', 'Name', 'Email', 'Entry') VALUES (NULL, NULL, '{$_POST[fname]}', '{$_POST[femail]}', '{$_POST[fentry]}')";

if(!mysql_query($query))
{
die('Error: ' . mysql_error());
}

 

The error report is: 

Error: 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 ''id', 'Date', 'Name', 'Email', 'Entry') VALUES (NULL, NULL, 'sample name', 'samp' at line 1

 

Help?

Link to comment
https://forums.phpfreaks.com/topic/204411-php-forms-insert-into-mysql/
Share on other sites

use backticks instead of single quotes when stating a table column.

 

try this:

 

$query="INSERT INTO c$p (`id`, `Date`, `Name`, `Email`, `Entry`) VALUES (NULL, NULL, '{$_POST[fname]}', '{$_POST[femail]}', '{$_POST[fentry]}')";

if(!mysql_query($query))
{
die('Error: ' . mysql_error());
}

Remove the quotes around the field names.

<?php
$query="INSERT INTO c$p (id, Date, Name, Email, Entry) VALUES (NULL, NULL, '{$_POST[fname]}', '{$_POST[femail]}', '{$_POST[fentry]}')";
?>

 

BTW, it's very unwise to use any data directly from the $_POST or $_GET arrays directly in a query. At the very least use the function mysql_real_escape_string on the data.

<?php
$query="INSERT INTO c$p (id, `Date`, Name, Email, Entry) VALUES (NULL, NULL, '" , mysql_real_escape_string($_POST['fname']) . "', '" . mysql_real_escape_string($_POST['femail']) . "', '" . mysql_real_escape_string($_POST['fentry']) . "')";
?>

 

Ken

 

Warning: include(scripts/posts/1 OR 1=1.php) [function.include]: failed to open stream: No such file or directory in /home/a8646192/public_html/a.php on line 58

 

You are using the URL value to define a file to include!

 

I fixed that with gettype($p)=="integer".  Would that completely fix that loose end?

Warning: include(scripts/posts/1 OR 1=1.php) [function.include]: failed to open stream: No such file or directory in /home/a8646192/public_html/a.php on line 58

 

You are using the URL value to define a file to include!

 

I fixed that with gettype($p)=="integer".  Would that completely fix that loose end?

 

Never mind.  I used $p=intval($p);  Anything else to fix?

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.