Jump to content

Where is the error in this?


Colourtheory
 Share

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 comment
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 comment
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 comment
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 comment
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 comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...