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');
?>
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');
?>