Jump to content

Posting data with PHP into MySQL


andygsy

Recommended Posts

Hi,

Can anyone tell me why the following 'gets' the data fine from the database but wont post back in when clicking on the submit within the form (named as 'save'):

<?php
require("inc/conn.php");
if(! isset($_COOKIE['admin'] )) {
header("Location: admin.php");
}
if(isset($_POST['save'])) {
$itemTitle = $_POST['itemTitle'];
$content = $_POST['content'];
$category = $_POST['category'];
$link = $_POST['link'];
if(isset($_POST['itemID'])) {
$itemID = $_POST['itemID'];
$sql = "UPDATE items SET itemTitle = '" . $itemTitle . "', content = '" . $content . "', category = '" . $category . "', link = '" . $link. "' WHERE itemID = " . $itemID;
if ($result = mysql_query($sql)) {
header("Location: controlpanel.php");
}
}

}
if(isset($_GET['itemID']) ) {
$itemID = $_GET['itemID'];
$sql = "SELECT * FROM items WHERE itemID = " . $_GET['itemID'];
if ($result = mysql_query($sql)) {
$row = mysql_fetch_array($result);
$itemTitle = $row['itemTitle'];
$content = $row['content'];
$category = $row['category'];
$link = $row['link'];

}
}else{
$name = 'new item';
}
?>


Cheers for the help.
Link to comment
https://forums.phpfreaks.com/topic/33523-posting-data-with-php-into-mysql/
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.