Jump to content

MySQL Error: error in your SQL syntax


Iceman512

Recommended Posts

Hi all,

 

The following script uploads and re-sizes an image and then inserts the relevant information into the database. It works perfectly (the image is uploaded, resized and the data gets submitted to the db), but instead of displaying the 'upload successful' message, I get the following error every time:

 

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 '1' at line 1

 

Can anyone tell me why?

 

Here the main code for this part:

<?php
if (isset($_POST['linkNew'])){ 
  
  require_once 'config.php';

$site = ucwords($_POST['site_name']);
$link = preg_replace('/\s+/', '_', $_POST['website']);
$date = $_POST['date'];
$description = trim($_POST['description']);

$sql = mysql_query("INSERT INTO table 
        (image, site, link, date, description, publish)  
        VALUES 
        ('$img_thumb', '$site', '$link', '$date', '$description', 'yes')");

if (!mysql_query($sql,$con))
  	  {
  		exit('Error: ' . mysql_error());
  	  }
  
echo '<p>Your link was saved successfully.</p>';

mysql_close($con);

  } 
  else 
  {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
  <b>Upload Image:</b> 
  <input type="file" name="image" size="45" /><br />
    <span style="font-size:10px; color:#666666;">Click <b>browse</b> to select an image</span><br /><br/>
  <b>Link Name:</b>
  <input type="text" name="site_name" size="35" /><br />
  <b>Website:</b>
  <input type="text" name="website" size="35" /><br />
    <span style="font-size:10px; color:#666666;"><b>Eg: </b>http://www.some_site.com</span><br /><br/>
  <b>Date:</b>
  <input type="text" name="date" value="<?php echo date('jS '); echo date('F, Y'); ?>" /><br /><br />
  <b>Site Description:</b> <br />
  <textarea style="width:99%; height:80px; overflow:visible;" name="description"></textarea>
  <input style="padding:5px 10px;" type="submit" value=" Submit " name="linkNew" />
</form>

<?php
}
?>

 

Thank you for any help in advance

 

Regards,

Iceman

Link to comment
https://forums.phpfreaks.com/topic/64258-mysql-error-error-in-your-sql-syntax/
Share on other sites

This:

$sql = mysql_query("INSERT INTO links (image, site, link, date, description, publish) 
VALUES ('$img_thumb', '$site', '$link', '$date', '$description', 'yes')");

if (!mysql_query($sql,$con))

SHould be:

$sql = "INSERT INTO links (image, site, link, date, description, publish) 
VALUES ('$img_thumb', '$site', '$link', '$date', '$description', 'yes')";

if (!mysql_query($sql,$con))

 

Your where running mysql_query within mysql_query. mysql_query was defined within $sql.

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.