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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

  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.

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