andr923 Posted August 10, 2007 Share Posted August 10, 2007 $connect = new connector(); $caption = $_POST['caption']; $caption = htmlentities($caption); $img = $_POST['img']; $by = $_POST['by']; $by = htmlentities($by); $insertQuery = "INSERT INTO gallery (img, caption, by) VALUES ('$img','$caption','$by')"; if ($connect->query($insertQuery)){ echo "<center><h4>pic added</h4></center>"; }else{ echo "<center><h4>pic did not get added</h4></center>"; } $connect->close(); That is the code I'm using to try and post the image information into my gallery's database. I mostly copied the code exactly from a similar script I use for my blog table but for some reason this won always fails to insert the query and gives me the "did not get added" message. This is the code for the form that submits the information: <form name="form1" method="post" action="postpic.php"> <p> <input name="img" type="text" value="filename (without .jpg)" size="30"> </p> <p> <input name="by" type="text" value="by" size="30"> </p> <p><br> <textarea name="caption" cols="40" rows="10">caption</textarea> </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form> I know it's gotta be a small thing 'cause this works for my blog script. Quote Link to comment https://forums.phpfreaks.com/topic/64240-solved-script-wont-post-to-mysql/ Share on other sites More sharing options...
andr923 Posted August 10, 2007 Author Share Posted August 10, 2007 I changed all the instances of 'img' or '$img' to 'pic' and '$pic' and all the instances of 'by' and '$by' to 'author' and '$author' and I guess now it works. So i guess maybe one of those variables is reserved by either the php or mysql system? Quote Link to comment https://forums.phpfreaks.com/topic/64240-solved-script-wont-post-to-mysql/#findComment-320267 Share on other sites More sharing options...
HuggieBear Posted August 10, 2007 Share Posted August 10, 2007 You're right, 'by' is a reserved word... MySQL 3.23, 4.0, 4.1 Reserved Words MySQL 5.0 Reserved Words MySQL 5.1 Reserved Words Regards Huggie p.s. Make sure you mark this topic as solved Quote Link to comment https://forums.phpfreaks.com/topic/64240-solved-script-wont-post-to-mysql/#findComment-320334 Share on other sites More sharing options...
wildteen88 Posted August 10, 2007 Share Posted August 10, 2007 When defining column names that are reserved words wrap them in backticks: `img`, `caption`, `by` Quote Link to comment https://forums.phpfreaks.com/topic/64240-solved-script-wont-post-to-mysql/#findComment-320338 Share on other sites More sharing options...
andr923 Posted August 11, 2007 Author Share Posted August 11, 2007 thanks Quote Link to comment https://forums.phpfreaks.com/topic/64240-solved-script-wont-post-to-mysql/#findComment-321323 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.