Avatar of jonofat
jonofat

asked on 

php undefined index

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

PHP

Avatar of undefined
Last Comment
haloexpertsexchange
Avatar of haloexpertsexchange
haloexpertsexchange
Flag of United States of America image

Can we get the exact error? What you have given is a little too vague.
Avatar of Rik-Legger
Rik-Legger
Flag of undefined image

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

error_reporting(E_ALL ^ E_NOTICE);

Open in new window

Avatar of jonofat
jonofat

ASKER

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

Line 83 = GetSQLValueString($_POST['customerid'], "int"));
What exactly is it saying
$_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

Avatar of Rik-Legger
Rik-Legger
Flag of undefined image

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.
Avatar of jonofat
jonofat

ASKER

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?
Avatar of jonofat
jonofat

ASKER

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

if ((isset($_POST["MM_Update"])) && ($_POST["MM_Update"] == "form1")) {
ASKER CERTIFIED SOLUTION
Avatar of haloexpertsexchange
haloexpertsexchange
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of jonofat
jonofat

ASKER

I just used and it worked perfectly.

<script>
document.form1.submit();
</script>
Avatar of jonofat
jonofat

ASKER

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.
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo