PDA

View Full Version : Few lines of MYSQL not working - Spent HOURS looking at them!


tom8521
19th March 11, 10:09 PM
I have been looking at these few lines of code for over 3 hours now (I'm not kidding!).

It updates a record already in the database with no trouble at all, but WILL NOT add a new record.

HELP!?

<?php

include '../assets/library/config.php';
include '../assets/library/opendb.php';

$action = $_GET['action'];

$news_title = mysql_real_escape_string( $_POST['news_title']);
$news_story = mysql_real_escape_string( $_POST['news_story']);

$upload_thumb_image = explode('|', (isset($_POST['upload_thumb_image']) ? $_POST['upload_thumb_image'] : '|'));

if ($action == "update"){
$id = $_POST['id'];
$add_news = "UPDATE tbl_news SET NEWS_TITLE = '$news_title', NEWS_STORY = '$news_story', THUMB = '".$upload_thumb_image[0]."' WHERE ID = '$id'";

mysql_query($add_news) or die('Error, query failed : ' . mysql_error());
}
else {

$add_news = "INSERT INTO tbl_news (NEWS_TITLE, NEWS_STORY, THUMB) VALUES ('$news_title', '$news_story', '".$upload_thumb_image[0]."')";

mysql_query($add_news) or die('Error, query failed : ' . mysql_error());
}

include '../assets/library/closedb.php';
header('Location: index.php');

?>

tom8521
19th March 11, 11:53 PM
ALSO: I've noticed a few people looking at my post and not replying... is this because you can't see an error either?

Please let me know if you think the code is fine because it may be the form that is the problem.... although I don't see a problem on there either!

Thanks!

chrishirst
20th March 11, 12:27 PM
Bots can't answer posts.

Have you tested to see if the if .. else structure is working by echoing something to the browser?