Forum Moderators: coopster

Message Too Old, No Replies

My query is not displaying.

Notice: Undefined variable error message

         

BadGoat

6:39 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



Hello!

I am getting an error message, saying that the variables from the acctmgr table are undefined. I am not sure what I am missing. Any help would be great!

This is the error message:

SELECT * from diw
Notice: Undefined variable: acctmgr_phone in c:\program files\easyphp1-7\www\diw4.php on line 40

Notice: Undefined variable: acctmgr_cellphone in c:\program files\easyphp1-7\www\diw4.php on line 40

Notice: Undefined variable: acctmgr_email in c:\program files\easyphp1-7\www\diw4.php on line 40

This is my code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php

$connect= mysql_connect("localhost","root","****")
or die("Could not connect to database in localhost!");
$result=mysql_select_db("testdiw")
or die("Could not select that database!");


echo "SELECT * from testdiw";

$joined = date("Y-m-d h:i:s");
$sqlquery = "INSERT INTO diw VALUES('','". $diwtitle ."','". $dropdownacctmgr ."','". $joined ."')";

$sqlquery = "SELECT * from diw";
$queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query!");

$get_acctmgr_info = mysql_query("SELECT acctmgr_phone, acctmgr_cellphone, acctmgr_email FROM acctmgr WHERE acctmgr_name = '$dropdownacctmgr'");
$row=mysql_fetch_array($get_acctmgr_info);

echo '<table border=1 align=center width=500>
<TR>
<TD colspan=2><b>General Deposition
Information></b></TD>
</TR>
<TR>
<TD><b>DIW Title:</b></TD>
<TD>' .$diwtitle. '</TD>
</TR>
<TR>';

echo ' <TD>Account Manager Information:</TD> <TD>' .$dropdownacctmgr. '<BR>' .$acctmgr_phone. '<BR>' .$acctmgr_cellphone. '<BR>' .$acctmgr_email. '</TD>
</TR>
</TABLE>';

?>

</body>
</html>

dreamcatcher

7:56 pm on Mar 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Undefined variable means that you are trying to access a variable that has not been set. Try using the isset() function.

if (isset($variable))
{
do something
}

dc

BadGoat

8:13 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



Thank you dreamcatcher :)

I follow that.. But, the undefined variables which I get the error for are associated with a variable that is defined..

$get_acctmgr_info = mysql_query("SELECT acctmgr_phone, acctmgr_cellphone, acctmgr_email FROM acctmgr WHERE acctmgr_name = '$dropdownacctmgr'");
$row=mysql_fetch_array($get_acctmgr_info);

The variable $dropdownacctmgr is defined on the page which leads to this. The variable $dropdownacctmgr displays even. So I am wondering if there is an error with the query which looks for a commonality between $dropdownacctmgr and acctmgr_name?

dreamcatcher

8:21 pm on Mar 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe this is a register globals issue?

If your data has come from a form, instead of $dropdownacctmgr use $_POST['dropdownacctmgr']

$get_acctmgr_info = mysql_query("SELECT acctmgr_phone, acctmgr_cellphone, acctmgr_email FROM acctmgr WHERE acctmgr_name = '".$_POST['dropdownacctmgr']."'");

dc

BadGoat

8:30 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



I tried the query as you suggested, I still get the same undefined variable error.

I checked to see if the variable $dropdownacctmgr was set my inserting the code

if (isset($dropdownacctmgr)) {
echo "This var is set set so I will print.";
}

into the script and it echoed back as being set. Does this point to a problem with the query syntax?

dreamcatcher

8:47 pm on Mar 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can you post some more of your code. Like where the variable is in the first place and how you are passing the data to your database when your form is executed.

dc

BadGoat

10:27 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



Certainly! This is the code from the page prior to the problem page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php

$connect= mysql_connect("localhost","root","cpyter")
or die("Could not connect to database in localhost!");
$result=mysql_select_db("testdiw")
or die("Could not select that database!");

?>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form action="diw5.php" method="post">
<TABLE>
<tr>
<td align="center" HEIGHT="65" width="100" colspan="2" BGCOLOR="#cc0000"><b>General Deposition Information</b></td>
</tr>
<tr><!-- ROW 2, TABLE 2 -->
<td width="40%"><small><b><font face="Arial">DIW Title:</font></b></small></td>
<td><input type="text" name="diwtitle" size="32"></td>
</tr>
<tr>
<td valign="top"><small><b><font face="Arial">Account Manager</font></b></small></td>
<td><select name="dropdownacctmgr" tabindex="4"><option value="notset">- Select an account manager -</option>
<?
//--- CREATE Account Manager SELECT ---
$sql = "SELECT DISTINCT acctmgr_name FROM acctmgr ORDER BY acctmgr_name";
$acctmgr_name = mysql_query($sql) or die($sql . '<br />' . mysql_error());
while ($row = mysql_fetch_array($acctmgr_name)) {
echo '<option value="' . $row['acctmgr_name'] . '">' . $row['acctmgr_name'] . '</option>';
}
?>

</td>
</tr>
<TR>
<TD COLSPAN=2><input type="submit" name="Submit" value="Submit" action="required"></TD></FORM>
</TR>
</TABLE>
</body>
</html>

And tjhis is the code for the page with the problems as I currently have it:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php

$connect= mysql_connect("localhost","root","cpyter")
or die("Could not connect to database in localhost!");
$result=mysql_select_db("testdiw")
or die("Could not select that database!");


echo "SELECT * from diw";

$joined = date("Y-m-d h:i:s");
$sqlquery = "INSERT INTO diw VALUES('','". $diwtitle ."','". $dropdownacctmgr ."','". $joined ."')";

$sqlquery = "SELECT * from diw";
$queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query!");

echo "<table border=1 align=center width=500>";
echo "<TR>";
echo "<TD colspan=2><b>General Deposition";
echo "Information></b></TD>";
echo "</TR>";
echo "<TR>";
echo "<TD><b>DIW Title:</b></TD>";
echo "<TD>" .$diwtitle. "</TD>";
echo "</TR>";
echo "<TR>";
echo "<TD>Account Manager Information:</TD> <TD>" .$dropdownacctmgr. "<BR>";

//$get_acctmgr_info = mysql_query("SELECT acctmgr_phone, acctmgr_cellphone, acctmgr_email FROM acctmgr WHERE acctmgr_name = '$dropdownacctmgr'");

$get_acctmgr_info = mysql_query("SELECT acctmgr_phone, acctmgr_cellphone, acctmgr_email FROM acctmgr WHERE acctmgr_name = '".$_POST['dropdownacctmgr']."'");

$row=mysql_fetch_array($get_acctmgr_info);

if (isset($acctmgr_name)) {
echo "This var is set set so I will print.";
}
echo "" .$acctmgr_phone. "<BR>" .$acctmgr_cellphone. "<BR>" .$acctmgr_email. "</TD>";
echo "</TR>";
echo "</TABLE>";

?>


</body>
</html>

dreamcatcher

10:45 pm on Mar 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On the page where your database query is, try putting the following code before you query your database:

if (isset($_POST['Submit']))
{
$diwtitle = $_POST['title'];
$dropdownacctmgr = $_POST['dropdownacctmgr'];
}

also change:

SELECT acctmgr_phone, acctmgr_cellphone, acctmgr_email FROM acctmgr...

to simply:

SELECT * FROM acctmgr..

See if that helps.

dc

BadGoat

2:59 pm on Mar 21, 2005 (gmt 0)

10+ Year Member



Hi dreamcatcher, I tried as you suggested, and I still get the same undefined variable error.
"Notice: Undefined variable: acctmgr_phone in c:\program files\easyphp1-7\www\diw5.php on line 52

Notice: Undefined variable: acctmgr_cellphone in c:\program files\easyphp1-7\www\diw5.php on line 52

Notice: Undefined variable: acctmgr_email in c:\program files\easyphp1-7\www\diw5.php on line 52"

Salsa

5:33 pm on Mar 21, 2005 (gmt 0)

10+ Year Member



Maybe, try adding these lines:

...
$get_acctmgr_info = mysql_query("SELECT acctmgr_phone, acctmgr_cellphone, acctmgr_email FROM acctmgr WHERE acctmgr_name = '".$_POST['dropdownacctmgr']."'");

$row=mysql_fetch_array($get_acctmgr_info);

$acctmgr_phone = $row['acctmgr_phone'];
$acctmgr_cellphone = $row['acctmgr_cellphone'];
$acctmgr_email = $row['acctmgr_email'];

if (isset($acctmgr_name)) {
echo "This var is set set so I will print.";
}
echo "" .$acctmgr_phone. "<BR>" .$acctmgr_cellphone. "<BR>" .$acctmgr_email. "</TD>";
...

BadGoat

7:06 pm on Mar 22, 2005 (gmt 0)

10+ Year Member



Salsa, that did it! OMG, I am about to faint. =P Only been scratching my head with this one for 3 or 4 days, plus dreaming about it once over the weekend.

dreamcatcher, thank you as well! I thank both of you from the bottom of my heart. :)

dreamcatcher

12:58 am on Mar 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Dreaming about code is not good. LOL!

Glad you got it working.