Jump to content
Colourtheory

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

Share this post


Link to post
Share on other sites

What does the error message display? Same thing? Try:

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

Edited by Don E

Share this post


Link to post
Share on other sites

It whites out the entire page and says Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/u705429760/public_html/newdiscussion.php on line 23

Share this post


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);?>

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

Switch your array ref in the insert to to a non array variable.

Share this post


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

Share this post


Link to post
Share on other sites

I give up, it's just not working..

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 (hi,hi,1)' at line 1

Sucks, I worked so hard on this website.

Share this post


Link to post
Share on other sites

Don't give up. It can work. Post the code that gave you the error above. There's a solution to the problem. Always! :)

Share this post


Link to post
Share on other sites

"desc" is a reserved word in SQL, for using ORDER BY. If you're using reserved words as table or column identifiers then you need to quote them with backticks.

Share this post


Link to post
Share on other sites

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

Share this post


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