Jump to content
Colourtheory

Where is the error in this?

Recommended Posts

Try this

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

Edited by Mudsaf

Share this post


Link to post
Share on other sites

$sql="INSERT INTO discussions (name, desc, maker)VALUES('".$_POST[name]."', '".$_POST[desc]."', '$id')"; This is the right way to write you can also write in this manner $sql="INSERT INTO discussions (name, desc, maker)VALUES('".$_POST['name']."', '".$_POST['desc']."', '$id')"; ('".$_POST['name']."' this particular key word can accepts the values perfectly.

Edited by xhtmlchamps1

Share this post


Link to post
Share on other sites
$sql="INSERT INTO discussions (name, desc, maker)VALUES('$_POST[name]', '$_POST[desc]', '$id')";

Theres no need to use concatenation operator '.' to add quotes, it looks really messy doing so.

Edited by dsonesuk

Share this post


Link to post
Share on other sites

The error is due to a reserved word being used desc, it is reserved for describing which order you require as in descending or ascending. if you can't change field name try using backticks `desc`. OOPS! i see this has already been pointed out, guys the problem has been found, give it up.

Edited by dsonesuk

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