php undefined index

jonofat
jonofat used Ask the Experts™
on
I am getting an annoying undefined index error and can't figure out why?

$colname_Recordset1 = "-1";
if (isset($_POST['email'])) {
  $colname_Recordset1 = $_POST['email'];
}
mysql_select_db($database_test, $test);
$query_Recordset1 = sprintf("SELECT customerid, customeremail, customername, customerlastname FROM customers WHERE customeremail = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $test) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

if (("" == ""))     {
  $updateSQL = sprintf("UPDATE customers SET random_token=%s WHERE customerid=%s",
                       GetSQLValueString($_POST['token'], "text"),
                       GetSQLValueString($_POST['customerid'], "int"));

  mysql_select_db($database_test, $test);
  $Result1 = mysql_query($updateSQL, $test) or die(mysql_error());
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Can we get the exact error? What you have given is a little too vague.
Top Expert 2011

Commented:
To discard those messages you can put this on top in your php files:

error_reporting(E_ALL ^ E_NOTICE);

Open in new window

Author

Commented:
PHP Notice: Undefined index: customerid in C:\inetpub\wwwroot\mysite\request_sent.php on line 83

Line 83 = GetSQLValueString($_POST['customerid'], "int"));
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Greg AlexanderLead Developer

Commented:
What exactly is it saying
Greg AlexanderLead Developer

Commented:
$_POST['customerid'] does not exists basically, you can suppress it

<?
  $colname_Recordset1 = "-1";  
if (isset($_POST['email'])) {  
  $colname_Recordset1 = $_POST['email'];  
}  
mysql_select_db($database_test, $test);  
$query_Recordset1 = sprintf("SELECT customerid, customeremail, customername, customerlastname FROM customers WHERE customeremail = %s", GetSQLValueString($colname_Recordset1, "text"));  
$Recordset1 = mysql_query($query_Recordset1, $test) or die(mysql_error());  
$row_Recordset1 = mysql_fetch_assoc($Recordset1);  
$totalRows_Recordset1 = mysql_num_rows($Recordset1);  
  
if (("" == ""))     {  
  $updateSQL = sprintf("UPDATE customers SET random_token=%s WHERE customerid=%s",  
                       GetSQLValueString($_POST['token'], "text"),  
                       GetSQLValueString(@$_POST['customerid'], "int"));  
  
  mysql_select_db($database_test, $test);  
  $Result1 = mysql_query($updateSQL, $test) or die(mysql_error());  
}
?>

Open in new window

Top Expert 2011

Commented:
The undefined index just means that there is no $_POST['customerid'].
Are you sure that you are actually posting a field named exactly the same thing, that is it is named customerid instead of customer id.
or something named similarly but not actually what you are asking for on the request_sent.php page.

Author

Commented:
Oh wait, I think I know what I have done now that you mention it. I have this on the page

<input name="customerid" type="hidden" id="customerid" value="<?php echo $row_Recordset1['customerid']; ?>" />

but the form isn't posting, I have set that update to occur before the page loads:

if (("" == ""))     {

It is meant to post the customerid but there isn't meant to be a submit button, in other words, it isn't up to the user, the form must submit itself if that is possible?

Author

Commented:
So, I suppose I need something like this but not sure how to automate it

if ((isset($_POST["MM_Update"])) && ($_POST["MM_Update"] == "form1")) {
it would go something like this.
if ((isset($_POST["MM_Update"])) && ($_POST["MM_Update"] == "form1")) {
then the javascript
echo '<script language="javascript"> document.myform.submit();</script>';

Open in new window

Author

Commented:
I just used and it worked perfectly.

<script>
document.form1.submit();
</script>

Author

Commented:
Who deserves points? Once someone started crying because they gave a suggestion which wasn't even the answer and I didn't give them points for taking the time to give me a reply. I am not being nasty, I just wonder if I am supposed to give points for the right answer only or give to everybody who said something? Please advise.
you give points to whomever you felt helped you get the answer you were looking for, not usually to everyone who gave you a comment.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial