Colourtheory 0 Posted December 23, 2012 Report Share Posted December 23, 2012 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 Quote Link to post Share on other sites
Don E 125 Posted December 23, 2012 Report Share Posted December 23, 2012 (edited) For VALUES, try: ($_POST['name'], $_POST['desc'], $id) Edited December 23, 2012 by Don E Quote Link to post Share on other sites
Colourtheory 0 Posted December 23, 2012 Author Report Share Posted December 23, 2012 Doesn't work either Quote Link to post Share on other sites
Don E 125 Posted December 23, 2012 Report Share Posted December 23, 2012 (edited) What does the error message display? Same thing? Try: $sql="INSERT INTO discussions (name, desc, maker)VALUES('". $_POST['name'] . "', '" . $_POST['desc'] . "', $id)"; Edited December 23, 2012 by Don E Quote Link to post Share on other sites
Colourtheory 0 Posted December 23, 2012 Author Report Share Posted December 23, 2012 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 Quote Link to post Share on other sites
Don E 125 Posted December 23, 2012 Report Share Posted December 23, 2012 Check my edited post above with revised query to try. See if that works. Quote Link to post Share on other sites
Colourtheory 0 Posted December 23, 2012 Author Report Share Posted December 23, 2012 The second one turns out to be the exact same as the first error Quote Link to post Share on other sites
Colourtheory 0 Posted December 23, 2012 Author Report Share Posted December 23, 2012 Maybe there is a problem with the PHP part.. Quote Link to post Share on other sites
Don E 125 Posted December 23, 2012 Report Share Posted December 23, 2012 I see. Post the section in the code where this query takes place. Quote Link to post Share on other sites
Colourtheory 0 Posted December 23, 2012 Author Report Share Posted December 23, 2012 <?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);?> Quote Link to post Share on other sites
Don E 125 Posted December 23, 2012 Report Share Posted December 23, 2012 (edited) 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 December 23, 2012 by Don E Quote Link to post Share on other sites
Colourtheory 0 Posted December 23, 2012 Author Report Share Posted December 23, 2012 Let me check.. Also, a few variables have the same name could this be causing the problem? Quote Link to post Share on other sites
Colourtheory 0 Posted December 24, 2012 Author Report Share Posted December 24, 2012 This is so consfusing.. the script came off of a w3 example. I just edited it. Quote Link to post Share on other sites
Don E 125 Posted December 24, 2012 Report Share Posted December 24, 2012 Still getting an error after you edited it? Quote Link to post Share on other sites
Colourtheory 0 Posted December 24, 2012 Author Report Share Posted December 24, 2012 Yeah, this is really upsetting because this is one of the main parts of the website, and something so small is ruining it. Quote Link to post Share on other sites
Colourtheory 0 Posted December 24, 2012 Author Report Share Posted December 24, 2012 (edited) 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 December 24, 2012 by Colourtheory Quote Link to post Share on other sites
Don E 125 Posted December 24, 2012 Report Share Posted December 24, 2012 What exactly is the error display now? Quote Link to post Share on other sites
Colourtheory 0 Posted December 24, 2012 Author Report Share Posted December 24, 2012 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 35 Quote Link to post Share on other sites
Don E 125 Posted December 24, 2012 Report Share Posted December 24, 2012 (edited) Try putting curly braces around the values like the following: : $sql="INSERT INTO discussions (name, desc, maker)VALUES({$_POST['namevalue']},{$_POST['descvalue']},{$id})"; Edited December 24, 2012 by Don E Quote Link to post Share on other sites
niche 133 Posted December 25, 2012 Report Share Posted December 25, 2012 Switch your array ref in the insert to to a non array variable. Quote Link to post Share on other sites
thescientist 231 Posted December 25, 2012 Report Share Posted December 25, 2012 looks like your quotation marks are in the wrong place. check out this example.http://www.w3schools.com/php/php_mysql_insert.asp Quote Link to post Share on other sites
Colourtheory 0 Posted December 29, 2012 Author Report Share Posted December 29, 2012 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. Quote Link to post Share on other sites
Don E 125 Posted December 30, 2012 Report Share Posted December 30, 2012 Don't give up. It can work. Post the code that gave you the error above. There's a solution to the problem. Always! Quote Link to post Share on other sites
justsomeguy 1,135 Posted January 7, 2013 Report Share Posted January 7, 2013 "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. Quote Link to post Share on other sites
xhtmlchamps1 2 Posted January 25, 2013 Report Share Posted January 25, 2013 $sql="INSERT INTO discussions (name, desc, maker)VALUES('".$_POST[name]."', '".$_POST[desc]."', '$id')"; Try this code, will be better use to you Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.