Jump to content

[SOLVED] simple change no longer works!


delphi123

Recommended Posts

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

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.