delphi123 Posted November 27, 2007 Share Posted November 27, 2007 Hi, can anyone help with the below code? I've simply tried to add an extra option of 'text' and it is now echoing "ERROR: News could not be posted." when I hit submit. I've added the correct column to my database. Can anyone spot my mistake? :-\ <?php if(isset($_POST['submitted'])){ include ('mysql_connect.php'); if (empty($_POST['title'])) { echo '<p>You need to enter a title</p>'; } else { $title = $_POST['title']; } if (empty($_POST['img_url'])) { echo '<p>Enter an image you dullard!</p>'; } else { $img_url = $_POST['img_url']; } if (empty($_POST['linkto'])) { echo 'Where do you want to link to, ya\'fool?'; } else { $linkto = $_POST['linkto']; } if(empty($_POST['category'])){ echo 'Pick a category numskull!'; } else{ $category = $_POST['category']; } if(empty($_POST['text'])){ echo 'Add some text numskull!'; } else{ $text = $_POST['text']; } } if ($title){ $query = "INSERT INTO news_posts(category, title, text, img_url, linkto, date) VALUES ('$category','$title','$text',$img_url','$linkto',NOW())"; $result = @mysql_query($query); if ($result) { echo '<p>News Posted!</p>'; } else { echo '<p>ERROR: News could not be posted.</p>'; } } ?> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> Category: <select name="category" value="<?php if(isset($_POST['category'])) echo $_POST['category']; ?>"/> <option></option> <option>News</option> <option>Tutorial</option> <option>Article</option> <option>Featured Artist</option> <option>NEW!</option> </select> <p>News Title: <input type="input" name="title" size="25" maxlength="60" value="<?php if(isset($_POST['title'])) echo $_POST['title']; ?>"/> </p> <p>Image location: <input type="input" name="img_url" size="25" maxlength="250" value="<?php if(isset($_POST['img_url'])) echo $_POST['img_url']; ?>"/> </p> <p>Short text: <input type="input" name="text" size="25" maxlength="128" value="<?php if(isset($_POST['text'])) echo $_POST['text']; ?>"/> </p> <p>URL to be linked to: <input type="input" name="linkto" size="25" maxlength="250" value="<?php if(isset($_POST['linkto'])) echo $_POST['linkto']; ?>"/> </p> <p><input type="submit" name="submit" value="Add News" /> <input type="hidden" name="submitted" value="TRUE" /></p> </form> Link to comment https://forums.phpfreaks.com/topic/79061-solved-simple-change-no-longer-works/ Share on other sites More sharing options...
~n[EO]n~ Posted November 27, 2007 Share Posted November 27, 2007 you change this line $result = @mysql_query($query); to $result=mysql_query($query) or die("Your have an error because:<br />" . mysql_error()); maybe mysql error... Link to comment https://forums.phpfreaks.com/topic/79061-solved-simple-change-no-longer-works/#findComment-400129 Share on other sites More sharing options...
delphi123 Posted November 27, 2007 Author Share Posted November 27, 2007 hmm I get: 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 '','cxbcvb',NOW())' at line 1 (cxbcvb being the rubbish I keyed in!) Link to comment https://forums.phpfreaks.com/topic/79061-solved-simple-change-no-longer-works/#findComment-400132 Share on other sites More sharing options...
delphi123 Posted November 27, 2007 Author Share Posted November 27, 2007 I've moved the column headers around a bit and it always seems to be highlighting the NOW() part - however I haven't changed this!? This was working perfectly, all I've done is add the 'text' column & code? ??? Link to comment https://forums.phpfreaks.com/topic/79061-solved-simple-change-no-longer-works/#findComment-400143 Share on other sites More sharing options...
delphi123 Posted November 27, 2007 Author Share Posted November 27, 2007 got it: $query = "INSERT INTO news_posts(category, title, text, img_url, linkto, date) VALUES ('$category','$title','$text',$img_url','$linkto',NOW())"; missing quote in front of $img_url! doh! $text',$img_url','$linkto',NOW())" Link to comment https://forums.phpfreaks.com/topic/79061-solved-simple-change-no-longer-works/#findComment-400150 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.