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
Share on other sites

Hi,

Thanks for the reply, I've commented out the header and add the php as suggested and the page displays the ID number for the record being viewed but when clicking submit the page loops (?) and nothing is posted into the database.

Cheers,
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.