Colourtheory Posted December 23, 2012 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 Link to comment Share on other sites More sharing options...
Don E Posted December 23, 2012 Share Posted December 23, 2012 (edited) For VALUES, try: ($_POST['name'], $_POST['desc'], $id) Edited December 23, 2012 by Don E Link to comment Share on other sites More sharing options...
Colourtheory Posted December 23, 2012 Author Share Posted December 23, 2012 Doesn't work either Link to comment Share on other sites More sharing options...
Don E Posted December 23, 2012 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 Link to comment Share on other sites More sharing options...
Colourtheory Posted December 23, 2012 Author 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 Link to comment Share on other sites More sharing options...
Don E Posted December 23, 2012 Share Posted December 23, 2012 Check my edited post above with revised query to try. See if that works. Link to comment Share on other sites More sharing options...
Colourtheory Posted December 23, 2012 Author Share Posted December 23, 2012 The second one turns out to be the exact same as the first error Link to comment Share on other sites More sharing options...
Colourtheory Posted December 23, 2012 Author Share Posted December 23, 2012 Maybe there is a problem with the PHP part.. Link to comment Share on other sites More sharing options...
Don E Posted December 23, 2012 Share Posted December 23, 2012 I see. Post the section in the code where this query takes place. Link to comment Share on other sites More sharing options...
Colourtheory Posted December 23, 2012 Author 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);?> Link to comment Share on other sites More sharing options...
Don E Posted December 23, 2012 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 Link to comment Share on other sites More sharing options...
Colourtheory Posted December 23, 2012 Author Share Posted December 23, 2012 Let me check.. Also, a few variables have the same name could this be causing the problem? Link to comment Share on other sites More sharing options...
Colourtheory Posted December 24, 2012 Author Share Posted December 24, 2012 This is so consfusing.. the script came off of a w3 example. I just edited it. Link to comment Share on other sites More sharing options...
Don E Posted December 24, 2012 Share Posted December 24, 2012 Still getting an error after you edited it? Link to comment Share on other sites More sharing options...
Colourtheory Posted December 24, 2012 Author 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. Link to comment Share on other sites More sharing options...
Colourtheory Posted December 24, 2012 Author 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 Link to comment Share on other sites More sharing options...
Don E Posted December 24, 2012 Share Posted December 24, 2012 What exactly is the error display now? Link to comment Share on other sites More sharing options...
Colourtheory Posted December 24, 2012 Author 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 Link to comment Share on other sites More sharing options...
Don E Posted December 24, 2012 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 Link to comment Share on other sites More sharing options...
niche Posted December 25, 2012 Share Posted December 25, 2012 Switch your array ref in the insert to to a non array variable. Link to comment Share on other sites More sharing options...
thescientist Posted December 25, 2012 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 Link to comment Share on other sites More sharing options...
Colourtheory Posted December 29, 2012 Author 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. Link to comment Share on other sites More sharing options...
Don E Posted December 30, 2012 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! Link to comment Share on other sites More sharing options...
justsomeguy Posted January 7, 2013 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. Link to comment Share on other sites More sharing options...
xhtmlchamps1 Posted January 25, 2013 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now