Jump to content

Undefined variable


yandoo

Recommended Posts

Hi there,

 

I was hoping for a little help please :)

 

 

Basically i have created some pagnation for my records so they are limited to 10 at a time. I keep getting an eror saying: Notice: Undefined variable: query_test in C:\wamp\www\Woodside\view_animal.php on line 259

 

that points to this line of code

$query_limit_test = sprintf("%s LIMIT %d, %d", $query_test, $startRow_test, $maxRows_test);

 

Im failry sure i just have a small error here perhaps someting named wrong??

 

If anybody could help me that would be great!! :)

 

Thank You

 

Tom

 

Heres my full code incase:

<?php require_once('Connections/woodside.php'); ?><?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);

  $logoutGoTo = "login.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
$colname_user_conditional = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_user_conditional = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_woodside, $woodside);
$query_user_conditional = sprintf("SELECT * FROM `user` WHERE Username = '%s'", $colname_user_conditional);
$user_conditional = mysql_query($query_user_conditional, $woodside) or die(mysql_error());
$row_user_conditional = mysql_fetch_assoc($user_conditional);
$totalRows_user_conditional = mysql_num_rows($user_conditional);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/index.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- InstanceEndEditable -->
<SCRIPT language=JavaScript src="time.js"></SCRIPT>
<script language="JavaScript">

<!--
function gotoLink(form) {
var OptionIndex=form.ListBoxURL.selectedIndex;
parent.location = form.ListBoxURL.options[OptionIndex].value;}
//-->
</script>




<link href="newbord.css" rel="stylesheet" type="text/css" />
<link href="border_top.css" rel="stylesheet" type="text/css" />
<link href="border_bottom.css" rel="stylesheet" type="text/css" />
<link href="fullborder.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 18px;
}
.style2 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 16px; }
.style7 {
font-size: 12px;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
.style8 {font-size: 16px; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; }
.style9 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 12px;
}
-->
</style>
<!-- InstanceBeginEditable name="head" -->
<link href="border.css" rel="stylesheet" type="text/css" />
<link href="text.css" rel="stylesheet" type="text/css" />
<!-- InstanceEndEditable -->
</head>

<body>
<table width="100%" height="120" border="0" align="center">
  <tr>
    <td><div align="center"><img src="Images/woodside animal welfafe trust1.jpeg" width="1000" height="150" /></div></td>
  </tr>
</table>

<table width="1000" border="0">
  <tr>
    <td width="230"><span class="style7">Welcome: <?php echo $row_user_conditional['FirstName']; ?></span></td>
    <td width="526"> <div align="center" class="style7">
      <script language="JavaScript" type="text/javascript">
					document.writeln(date+"-"+monthname[month]+"-"+year);
				</script>
     </div></td>
    <td width="230"><div align="right" class="style7"><a href="<?php echo $logoutAction ?>">LOG OUT</a> </div></td>
  </tr>
</table>
<table width="100%" border="0">
  
  <tr>
    <td width="23%" rowspan="2"><table width="100%" border="0" align="center">
      
      <tr>
        <td height="23" valign="top"><p class="style7">Location:<!-- InstanceBeginEditable name="EditRegion1" -->EditRegion1<!-- InstanceEndEditable --></p>
          <p><span class="style8">Navigation Menu</span></p>
          <table width="100%" border="0" align="left">
            <tr>
              <td><table width="105%" border="0" align="center" class="newbord">
                <tr>
                  <td width="20%" height="23" valign="top"><div align="right">Get:</div></td>
                  <td width="80%" valign="top"><div align="left"><a href="help.php">Help</a></div></td>
                </tr>
                <tr>
                  <td height="23" valign="top"><div align="right"><a href="animal.php"></a>Go to:</div></td>
			  
			   <form name="AutoListBox" id="AutoListBox">
                      <td>
                        <div align="left">
                          <select name="ListBoxURL" size="1" language="javascript" onchange="gotoLink(this.form);">
                            <option value="animal.php"> Animals</option>
						<option value="appointment.php">Appointments</option>
                            <option value="customer.php">Customers</option>                  
                            <option value="user.php">Users</option>
                            <option selected="selected"> ----- Select ----- </option>
                          </select>
                        </div></td></form>
                </tr>
                <tr>
                  <td height="23" valign="top"></td>
                  <td height="23" valign="top"> </td>
                </tr>
                <tr>
                  <td height="23" valign="top"><div align="right">				  					

								 <?php 
// Show IF Conditional region1 
//echo @$row_user['Username'];
if (@$row_user_conditional['Access'] == "2") {

              echo "Admin: </div></td>";
                 echo '<td height="23" valign="top">';
			  echo'<form name="AutoListBox" id="AutoListBox">';
			  
			     echo '<div align="left">';
			        echo'<select name="ListBoxURL" size="1" onchange="gotoLink(this.form);">';
			         echo'<option value="fear.php">Fears</option>';
			         echo'<option value="food.php">Foods</option>';
			         echo'<option selected="selected"> ----- Select ----- </option>';
			         echo"</select>";
			     echo"</div>";
			  echo"</form>";

} 
// endif Conditional region1
?>				 </td>
                </tr>


              </table>
              <table width="99%" border="0" align="center">
                  <tr>
                    <td><strong>Quick Links:  </strong><a href="search.php" class="style7"> Search</a></td>
                  </tr>
                </table>                
                <table width="105%" border="0" align="center" class="newbord">
                  <tr>
                    <td height="20" colspan="2"><a href="search.php"></a>                      <div align="center"><a href="search.php"></a><a href="search.php"></a></div></td>
                    </tr>
                  <tr>
                    <td width="21%"><div align="right">Add a:</div></td>
                    <form name="AutoListBox" id="AutoListBox">
                      <td width="79%">
                        
                          <div align="left">
					  
                            <select name="ListBoxURL" size="1" language="javascript" onchange="gotoLink(this.form);">
                              <option value="add_animal.php"> Animals</option>
                              <option value="add_customer.php">Customers</option>                              
                              <option value="add_appointment.php">Appointments</option>
						  <option selected="selected"> ----- Select ----- </option>
                            </select>
                          </div></td>
                    </form>
                  </tr>
                  <tr>
                    <td> </td>
                    <td> </td>
                  </tr>
                  <tr>
                    <td width="21%"><div align="right">View:</div></td>
				<form name="AutoListBox" id="AutoListBox">
                    <td><label>
                      
                        <div align="left">
                          <select name="ListBoxURL" size="1" language="javascript" onchange="gotoLink(this.form);">
                            <option value="fast_animal.php">Animals</option>
						<option value="fast_appointment.php">Appointments</option>
                            <option value="fast_customer.php">Customers</option>
                            <option value="fast_user.php">User</option>                            
                            <option selected="selected"> ----- Select ----- </option>
                          </select>
                        </div>
                      </label></td>
			      </form>
                  </tr>
                  <tr>
                    <td colspan="2"> </td>
                  </tr>
                </table>                </td>
            </tr>
          </table>          </td>
        </tr>
      </table>
    <p> </p></td>
    <td width="6%" height="61" valign="top"><p class="style1"> </p>
    <p align="left" class="style2"> </p>    </td>
    <td width="69%" valign="bottom"> </td>
  </tr>
  <tr>
    <td height="297" valign="top"> </td>
    <td width="69%" align="left" valign="top"><!-- InstanceBeginEditable name="EditRegion2" -->
<?php



ini_set('error_reporting',E_ALL);


$currentPage = $_SERVER["PHP_SELF"];

if (isset($_GET['orderby'])) { 
$orderby= $_GET['orderby']; 
}else{ $orderby="AnimalID"; }
//CHECKING TO SEE IF THE PERSON HAS CHOSEN TO ORDER BY A CERTAIN FIELD
?>
<?php

$maxRows_test = 10;
$pageNum_test = 0;
if (isset($_GET['pageNum_test'])) {
  $pageNum_test = $_GET['pageNum_test'];
}
$startRow_test = $pageNum_test * $maxRows_test;



mysql_select_db($database_woodside, $woodside);

$test= ("SELECT * FROM animal ORDER BY $orderby DESC");
$query_limit_test = sprintf("%s LIMIT %d, %d", $query_test, $startRow_test, $maxRows_test);
$test = mysql_query($query_limit_test, $woodside) or die(mysql_error());
$result = mysql_query($test) or die(mysql_error());
$row_test = mysql_fetch_assoc($result);
$totalRows_test = mysql_num_rows($result);

if (isset($_GET['totalRows_test'])) {
  $totalRows_test = $_GET['totalRows_test'];
} else {
  $all_test = mysql_query($query_test);
  $totalRows_test = mysql_num_rows($all_test);
}
$totalPages_test = ceil($totalRows_test/$maxRows_test)-1;

$queryString_test = "";

if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_test") == false && 
        stristr($param, "totalRows_test") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_test = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_test = sprintf("&totalRows_test=%d%s", $totalRows_test, $queryString_test);
?>




  <?php echo'<table width="500" border="1" >';
echo '<tr>';
    echo '<td width="100"><strong>Animal ID</strong></td>';
    echo'<td width="100"><strong>Animal Type</strong></td>';
    echo'<td width="100"><strong>Name</strong></td>';
    echo '<td width="100"><strong>Breed</strong></td>';
    echo '<td width="100"><strong>Date</strong></td>';
  echo '</tr>';
   echo'<tr>';
   echo '</table>';?>

<?php do { ?>
    <span class="text">
    <?php
echo '<table width="500" border="1" >';
    echo'<td width="100">'; 
echo $row_test['AnimalID']; 
echo'</td>';
    echo'<td width="100">';
echo $row_test['AnimalTypeID'];
echo'</td>';
    echo'<td width="100">';
echo $row_test['Name'];
echo'</td>';
    echo'<td width="100">';
echo $row_test['BreedID'];
echo'</td>';
    echo'<td width="100">';
echo $row_test['Date'];
echo'</td>';
  echo'</tr>';
echo'</table>';
?>
    </span>
  <?php } while ($row_test = mysql_fetch_assoc($result)); ?>


<table border="0" width="50%" align="center">
                        <tr>
                          <td width="23%" align="center"><?php if ($pageNum_test > 0) { // Show if not first page ?>
                                <a href="<?php printf("%s?pageNum_test=%d%s", $currentPage, 0, $queryString_test); ?>">First</a>
                                <?php } // Show if not first page ?>                          </td>
                          <td width="31%" align="center"><?php if ($pageNum_test > 0) { // Show if not first page ?>
                                <a href="<?php printf("%s?pageNum_test=%d%s", $currentPage, max(0, $pageNum_test - 1), $queryString_test); ?>">Previous</a>
                                <?php } // Show if not first page ?>                          </td>
                          <td width="23%" align="center"><?php if ($pageNum_test < $totalPages_test) { // Show if not last page ?>
                                <a href="<?php printf("%s?pageNum_test=%d%s", $currentPage, min($totalPages_test, $pageNum_test + 1), $queryString_test); ?>">Next</a>
                                <?php } // Show if not last page ?>                          </td>
                          <td width="23%" align="center"><?php if ($pageNum_test < $totalPages_test) { // Show if not last page ?>
                                <a href="<?php printf("%s?pageNum_test=%d%s", $currentPage, $totalPages_test, $queryString_test); ?>">Last</a>
                                <?php } // Show if not last page ?>                          </td>
                        </tr>
                                            </table>
                      <strong>Records <?php echo ($startRow_test + 1) ?> to <?php echo min($startRow_test + $maxRows_test, $totalRows_test) ?> of <?php echo $totalRows_test ?></strong>


<!-- InstanceEndEditable --></td>
  </tr>
</table>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($user_conditional);
mysql_free_result($result);
mysql_free_result($test);
?>

Link to comment
https://forums.phpfreaks.com/topic/93189-undefined-variable/
Share on other sites

Hi there,

 

thanks for reply, i think what that particular problem was that is should be $test and NOT $query_test.... for that line as it is define the line above.

 

That has resolved that error but i now find i hav another: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #5' at line 1

 

 

Hmm what should i do???

 

Thank You :)

Link to comment
https://forums.phpfreaks.com/topic/93189-undefined-variable/#findComment-477430
Share on other sites

Hi,

 

I also changed the following line:

  $all_test = mysql_query($query_test);

 

  $all_test = mysql_query($test);

 

...i still get the same error message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #5' at line 1

 

Any help please??

 

Thanks

 

p.s. the original query causing the problem is the $test query...

Link to comment
https://forums.phpfreaks.com/topic/93189-undefined-variable/#findComment-477436
Share on other sites

Hi,

 

I didnt change it back, all i did is direct the Action of the form to go to a different page and tried to add pagnation and limit the records to 10 per page... I have a working pagnation page and just revered engineereed it for this particular query....

 

Oh man have i balls'd it up :(?

 

Thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/93189-undefined-variable/#findComment-477507
Share on other sites

Hi all,

 

Ive done it!! Woohoo! Feel quite pleased with my self :)

 

For anybody whos interested heres what i did.....

 

Firslty i named 2 different queries the same name. They corresponded to the query that was used to display record results $test and the other query that produces the pagnation function now $test1...

 

Thought it was looking bit sketchy at one point, but pleased its all tured out well in the end...and hey, ive learnt something too :)

 

Thank You All :)

 

Link to comment
https://forums.phpfreaks.com/topic/93189-undefined-variable/#findComment-477590
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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