Jump to content

mySQL error


Kingy

Recommended Posts

i keep getting this 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 're There'' at line 1

 

You're There" is the $title

 

<?php

     $dwncheck = mysql_query("SELECT * FROM downloads WHERE title='$title'") or die(mysql_error());
     $dwncheck = mysql_num_rows($dwncheck);
     if ($dwncheck < 1) {
       $dwninsert = mysql_query("INSERT INTO downloads (title, category) VALUES ('$title', '$category', '$date')") or die(mysql_error());
       echo "<b>$title</b><br /> Category: $category <br /> <br />";
     } 
?> 

Link to comment
https://forums.phpfreaks.com/topic/91191-mysql-error/
Share on other sites

yeah thats not the error, i just pasted an old bit of code sorry, i've fixed that up but its the title that is ruining it..

 

i think its because the title has a ' in it, because the first four entries are inserting no problem but it stops at this entry and gives me this error.

Link to comment
https://forums.phpfreaks.com/topic/91191-mysql-error/#findComment-467370
Share on other sites

You need to use the function mysql_real_escape_string() on any string that is sent from outside of your script:

<?php
$q = "SELECT * FROM downloads WHERE title='" . mysql_real_escape_string($title) . "'";
$rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/91191-mysql-error/#findComment-467383
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.