Jump to content

Where is the error in this?


Recommended Posts

I've tried everything I can think of, any idea what's wrong?

$sql="INSERT INTO discussions (name, desc, maker)VALUES('$_POST[name]', '$_POST[desc]', '$id')";

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 'desc, maker) VALUES ('yo', 'yolo', '1')' at line 1

Link to post
Share on other sites
<?php session_start(); require_once 'db.php';if (!$con)  {  die('Could not connect: ' . mysql_error());  }  mysql_select_db("u705429760_main", $con); $id = $_SESSION['user_id']; $sql="INSERT INTO discussions (name, desc, maker)VALUES('$_POST[name]', '$_POST[desc]', $id)"; if (!mysql_query($sql,$con))  {  die('Error: ' . mysql_error());  }echo "Discussion started!"; mysql_close($con);?>

Link to post
Share on other sites

Everything looks alright. Are you sure you're not misspelling(not necessarilly misspelling, but thinking you mean desc but actually mean Desc for example) the column names in the query... for example... maybe you have Desc instead of desc for that column's name. Also not sure if it matters.. but try changing $_POST['desc'] to something else like $_POST['descrip'] in case MySQL is getting confused with desc as the column name and 'desc' in the $_POST. If you do that, don't forget to change the name attribute for desc input in the form to, for ie: <input type="text" name="descrip" />

Edited by Don E
Link to post
Share on other sites

This is the new version

<?php include('themesys.php') ?> <br><Br><div class="bbox">  <center>  <?php session_start(); if (isset($_SESSION['user_id'])){ $con = mysql_connect("mystuff","mystuff","mypw");if (!$con)  {  die('Could not connect: ' . mysql_error());  }  mysql_select_db("mydb", $con); $id = $_SESSION['user_id']; $sql="INSERT INTO discussions (name, desc, maker)VALUES($_POST['namevalue'],$_POST['descvalue'],'$id')"; if (!mysql_query($sql,$con))  {  die('Error: ' . mysql_error());  }echo "Discussion started!"; mysql_close($con); }else{header('Location: login.php');}?> </div></body>

Edited by Colourtheory
Link to post
Share on other sites

Try putting curly braces around the values like the following: :

$sql="INSERT INTO discussions (name, desc, maker)VALUES({$_POST['namevalue']},{$_POST['descvalue']},{$id})";

Edited by Don E
Link to post
Share on other sites

looks like your quotation marks are in the wrong place. check out this example.http://www.w3schools.com/php/php_mysql_insert.asp

Link to post
Share on other sites
  • 2 weeks later...
  • 3 weeks later...

$sql="INSERT INTO discussions (name, desc, maker)VALUES('".$_POST[name]."', '".$_POST[desc]."', '$id')"; Try this code, will be better use to you

Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...