Forum Moderators: coopster
I am stuck on a problem that I am hoping that someone has run across. I have a series of multiple (3) pages that I am trying to pass variables to in order to display the info that I want. Going from the 1st page to the 2nd page I have sucessfully queried information into a viewable table where you can do one of two things: (1)select a certain record and edit the information; or (2)click on a field in one column (Computer Name) which is a hyperlink to another query and another table.
However, when I click on a hyperlink I get the table that I want to call, but no data. I tested the function by plugging in a hard-coded query (i.e. "comp_name = X") and the the data comes back just fine. But I want to use a variable (i.e. "comp_name = $somevariable) passed into the query so the returned data will be for the computer name that I click on.
Below is the code as I have it now--
form1: simply an HTML page that calls and populates a table on form2
form2:
<?php $hostname = "localhost"; // The database server
$username = "root"; // username for this database
$password = "pass"; // password for this database
$dbName = "database"; // This is the database
$usertable = "table"; // name of the table
MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
@mysql_select_db( "$dbName") or die( "Unable to select database");
?>
<?
//error message (not found message)begins
$XX = "No Record Found. To search again please close this window";
//query details table begins
$query = mysql_query("SELECT * FROM table ORDER BY ip_addr ASC");
while ($row = @mysql_fetch_array($query))
{
$variable1=$row["emp_id"];
$variable2=$row["comp_name"];
$variable3=$row["function"];
$variable4=$row["network"];
$variable5=$row["ip_addr"];
//table layout for results
print ("<tr>");
print ("<td>$variable1</td>");
print ("<td><a href='http://localhost.network.lan/form3.php'>$variable2</a></td>"); //this is the hyperlink
print ("<td>$variable3</td>");
print ("<td>$variable4</td>");
print ("<td>$variable5</td>");
print ("</tr>");
}
//below this is the function for no record!
if (!$variable1)
{
print ("$XX");
}
//end
?>
</table><br><br>
<form method="POST" action="http://localhost.network.lan/form3.php" target="_blank">
<input type="hidden" name="compip" value="<? echo "$variable2"?>">
</form>
<form method="POST" action="http://localhost.network.lan/formX.php">
<p align="left">
Enter ID of record to EDIT:
<input type="text" name="empid" size="5" maxlength="11"> <br><br>
Click here to select the record: <input type="submit" value="SELECT"><br>(Or close window if finished)</p><br><br>
</form>
form3:
<?php $hostname = "localhost"; // The database server
$username = "root"; // username for this database
$password = "pass"; // password for this database
$dbName = "database2"; // This is the database
$usertable = "table2"; // name of the table
$compip = $_POST["compip"];
MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
@mysql_select_db( "$dbName") or die( "Unable to select database");
?>
<?
//error message (not found message)begins
$XX = "No Record Found. To search again please close this window";
//query details table begins
$query = mysql_query("SELECT * FROM $usertable WHERE comp_name = $compip ");
while ($row = @mysql_fetch_array($query))
{
$variable1=$row["comp_name"];
$variable2=$row["comp_type"];
$variable3=$row["op_sys"];
$variable4=$row["mainboard"];
$variable5=$row["cpu"];
$variable6=$row["ram_amt"];
$variable7=$row["hdd"];
$variable8=$row["video"];
$variable9=$row["nic_spd"];
$variable10=$row["ip_addr"];
//table layout for results
print ("<tr>");
print ("<td>$variable1</td>");
print ("<td>$variable2</td>");
print ("<td>$variable3</td>");
print ("<td>$variable4</td>");
print ("<td>$variable5</td>");
print ("<td>$variable6</td>");
print ("<td>$variable7</td>");
print ("<td>$variable8</td>");
print ("<td>$variable9</td>");
print ("<td>$variable10</td>");
print ("</tr>");
}
//below this is the function for no record!
if (!$variable1)
{
print ("$XX");
}
//end
?>
</table><br>
The problem (as far as I can tell) is that the variable "$variable2" is not passed from form2 to form3 (defined on form3 as "$compip". I believe that I am correct in using a hidden field as there is no user input on form2 to pass on to form3. The info that I want passed is simply data ("comp_name") that is populated in the table upon calling form2.
Thanks in advance for any help that is offered.
Eric
I think your problem in getting $variable2 passed from form two to form three is that you appear to have two form twos, and you have $variable2 as the only field in a form with no submit button:
form2:
...
<form method="POST" action="http://localhost.network.lan/form3.php" target="_blank">
<input type="hidden" name="compip" value="<? echo "$variable2"?>">
</form>
<form method="POST" action="http://localhost.network.lan/formX.php"> -->[/b]
<p align="left">
Enter ID of record to EDIT:
<input type="text" name="empid" size="5" maxlength="11"> <br><br>
Click here to select the record: <input type="submit" value="SELECT"><br>
(Or close window if finished)</p><br><br>
</form>
...
form3:
I hope this helps
Getto: I know that the variables being named the same may look a little confusing, but they are on different forms and are each defined on their respective forms. When (or should I say, if) $variable2 is passed from form2 to form3, that value is then defined by another variable (in this case, $compip. As I stated before, when I give the function a fixed value (comp_name = x) it works. So I know that the variable names are OK.
Salsa, you have hit upon the crux of my problem. There is only one "form2", and yes, there are two <form>s and only one "submit" button. When form1 calls form2, a table is displayed with various computers listed with approx 4 columns of data for each record. At the bottom of the form is a text field and a submit button. This allows the user to enter a particular id# and upon clicking select is directed to a form (formX) that allows that record to be modified, as the code snipit below shows:
<form method="POST" action="http://localhost.network.lan/formX.php">
<p align="left">
Enter ID of record to EDIT:
<input type="text" name="empid" size="5" maxlength="11"> <br><br>
Click here to select the record: <input type="submit" value="SELECT"><br>(Or close window if finished)</p><br><br>
This works fine, but my problem is this:
Also on form2, one column lists the Computer Name of each machine. Each entry in the table under Computer Name is a hyperlink to form3. So you see, THERE IS NO SUBMIT BUTTON (I am not shouting, just caps for clarification :) for this function call. The user clicks on the hyperlink and is taken to form3, and the Computer Name (i.e. $variable2) is what I am trying to pass over to form3. The links work, but the value of $variable2 (the computer name) is not being passed and I am only able to view a blank table with the error message ("no records found") that is coded to be displayed when no records are found. Everything works correctly except the passing of the variable.
I hope this clarifies what it is that I am trying to do. Thanks for your response.
Eric
Just to further clarify:
I am of the understanding that you need a <form> to define a hidden or a text field. The reason that I have two is that the hidden field needs to be passed to one form (form3) and the text field (w/ the "submit" button) needs to be passed to another form (formX). Is this correct? Or can I pass the fields to different destinations using the same <form>. I did try that at first but it did not work. Maybe my structure is not entirely correct? Thanks again.
Eric