Jump to content

Ahhh! Errors!


Zoud

Recommended Posts

[quote]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 'from) VALUES ('blah blah','blah blah','Zoud')' at line 1[/quote]

Here's the page with the error:

[code]<?php require("../../includes/layout_top.php"); ?>

<?php
$con = mysql_connect("-","-","-");
if (!$con)
  {
  die('Error: ' . mysql_error());
  }

mysql_select_db("news", $con);

if(isset($_POST[submit]))  {
$sql="INSERT INTO sitenews (title, info, from) VALUES ('$_POST[title]','$_POST[info]','$_POST[from]')";

if (!mysql_query($sql,$con))
  {
  die('Update was not sent. The error message below was recieved.<br /><br />Error: ' . mysql_error());
  }
  echo "Update has been sent.";
  }
  else  {
  echo "Post update below.<br />";
  echo "<form action='newspost_home.php' method='post'>";
  echo "<br />Username: <input type='text' name='from' />";
  echo "<br />Title: <input type='text' name='title' />";
  echo "<br />Information: <textarea name='info'></textarea>";
  echo "<br /><input type='submit' name='submit' value='Post News!' />";
  echo "</form>";
  }
mysql_close($con)
?>

<?php require("../../includes/layout_bot.php"); ?>[/code]

I have a similar script that enters users into a diffrent DB and it works perfectly. Infact I just copy and pasted the script from that one and altered it into this one. The only diffrences are changes in the form and I added one more row in the INSERT INTO & VALUES.
Link to comment
Share on other sites

[code]
<?php
$sql="INSERT INTO sitenews (title, info, `from`) VALUES ('$_POST[title]','$_POST[info]','$_POST[from]')";
?>
[/code]

from is a reserved word in SQL try what I have typed with the backticks on the word `from` so it uses it as a word not a command

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