Iceman512 Posted August 10, 2007 Share Posted August 10, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/64258-mysql-error-error-in-your-sql-syntax/ Share on other sites More sharing options...
wildteen88 Posted August 10, 2007 Share Posted August 10, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/64258-mysql-error-error-in-your-sql-syntax/#findComment-320326 Share on other sites More sharing options...
Iceman512 Posted August 10, 2007 Author Share Posted August 10, 2007 Hi there, Yup, that fixed it immediately! Man... I gotta get some sleep. Thank you very much! Regards, Iceman Quote Link to comment https://forums.phpfreaks.com/topic/64258-mysql-error-error-in-your-sql-syntax/#findComment-320331 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.