Jump to content

Recommended Posts

I am getting the 'Notice: Undefined index' message for the 'id' field of my query. I have tried loads of different ways of trying to sort this out, checked all spellings, checked I'm calling everything from the tables that I should be, and still can't get this thing to work. Could someone have a glance over my code and let me know if they see anything that could be causing this problem.

 

Thanks!

 

  $id = $_GET['id'];

	      if(isset($_POST['submit']))
		  {
		  $Site_Status = addslashes($_POST['Site_Status']);
		  $Inactive_msg = addslashes($_POST['Inactive_msg']);
		  $Main_Inactive_msg = addslashes($_POST['Main_Inactive_msg']);
		  $NewReleaseMsg = addslashes($_POST['NewReleaseMsg']);
		  
		  $result = mysql_query("UPDATE status (Site_Status, Inactive_msg, Main_Inactive_msg, NewReleaseMsg) VALUES ('$Site_Status', '$Inactive_msg', '$Main_Inactive_msg', '$NewReleaseMsg') WHERE StatusID='$id' " ,$conn);
		  }
		  elseif($id)
		  {
		  
        $result = mysql_query("SELECT * FROM status WHERE StatusID='$id' ",$conn);
        	while($myrow = mysql_fetch_assoc($result))
             {
		$Site_Status = $myrow['Site_Status'];
		$Inactive_msg = $myrow['Inactive_msg'];
		$Main_Inactive_msg = $myrow['Main_Inactive_msg'];
		$NewReleaseMsg = $myrow['NewReleaseMsg'];

Link to comment
https://forums.phpfreaks.com/topic/142169-notice-undefined-index/
Share on other sites

I didn't think that UPDATE was formatted like that, I though that was for INSERT.

 

Isn't it supposed to be?

 

UPDATE status SET Site_Status = '$Site_Status', Inactive_msg = '$Inactive_msg', Main_Inactive_msg = '$Main_Inactive_msg', NewReleaseMsg = '$NewReleaseMsg' WHERE StatusID='$id'

 

 

add or die(mysql_error()) after your query executions.

 

You should also put your queries in strings before you execute them so you can echo them out and see what's actually being passed in.

I didn't think that UPDATE was formatted like that, I though that was for INSERT.

 

The syntax is fine, either way is valid for an UPDATE.

 

Your entire block of code should be wrapped within another if statement. eg;

 

if (isset($_GET['id'])) {
  $id = $_GET['id'];
  // rest of code
}

 

I have a feeling $_GET['id'] is not defined.

I didn't think that UPDATE was formatted like that, I though that was for INSERT.

 

The syntax is fine, either way is valid for an UPDATE.

 

Thanks for clearing that up, I thought I remembered people using it that way, but I never have.

Okay, well I've changed the UPDATE query as suggesed.

 

I actually missed a bit from my original question though. The error occurs when I click the submit button. The address i'm using to test the page is status.php?id=1 and it's bringing up the correct details. However, when I click submit this error occurs. This is the tag I'm using the form:

 

<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">

 

This is causing the page to lose the ?id=1 off the end of the link. Why would it do this?

 

Thanks for your help!

Hi,

I'm still having problems with this script and really can't figure out why. When I click submit the screen simply becomes blank. I have double checked all entries against those in the database and made sure all entries are spelt correctly. I have error reporting turn on but no errors come up at all. If anyone has any ideas regarding this could they please let me know. Thanks!

 

This is my current script:

 

  include '../library/opendb.php';
error_reporting(E_ALL);
  ini_set("display_errors", 1);
  $id = $_GET['id'];

	      if(isset($_POST['submit']))
		  {
		  $Site_Status = addslashes($_POST['Site_Status']);
		  $Inactive_msg = addslashes($_POST['Inactive_msg']);
		  $Main_Inactive_msg = addslashes($_POST['Main_Inactive_msg']);
		  $NewReleaseMsg = addslashes($_POST['NewReleaseMsg']);
		  
		  $result = mysql_query("UPDATE status SET Site_Status='$Site_Status', Inactive_msg='$Inactive_msg', Main_Inactive_msg='$Main_Inactive_msg', NewReleaseMsg='$NewReleaseMsg') WHERE StatusID='$id' " ,$conn);
		  
		  echo "Status Updated Successfully!";
		  }
		  elseif($id)
		  {
		  
        $result = mysql_query("SELECT * FROM status WHERE StatusID='$id' ",$conn);
        	while($myrow = mysql_fetch_assoc($result))
             {
		$Site_Status = $myrow['Site_Status'];
		$Inactive_msg = $myrow['Inactive_msg'];
		$Main_Inactive_msg = $myrow['Main_Inactive_msg'];
		$NewReleaseMsg = $myrow['NewReleaseMsg'];

?>
<form method="post" action="?id=<?php echo $_GET['id']; ?>">
    <input type="hidden" name="id" value="<?php echo $myrow['id']; ?>" />
            <select name="Site_Status" id="Site_Status" value="<?php echo $Site_Status;?>">
		<option value="In-Active">In-Active</option>
		<option value="Active">Active</option>
            </select>
            <textarea name="NewReleaseMsg" cols="40" rows="4" wrap="VIRTUAL"><?php echo $NewReleaseMsg;?></textarea> 
            <textarea name="Main_Inactive_msg" cols="40" rows="4" wrap="VIRTUAL"><?php echo $Main_Inactive_msg;?></textarea> 
                <textarea name="Inactive_msg" cols="40" rows="4" wrap="VIRTUAL"><?php echo $Inactive_msg;?></textarea>
                <input name="submit" type="submit" id="submit" value="Save Settings">
  </form>
}
}
include '../library/closedb.php';
?>

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.