0

Hi,

I'm trying to post through a value of a button from a form on a previous page, and depending on the button that was pressed, an SQL statement will be executed and then a table will be created based on the result. However, when i try to do this i get an error message:

PHP Notice: Undefined index: both in D:\Web\Tivicheck\getinfo.php on line 11

The relevent code for the first form is..

<form action="getinfo.php" method="POST">
<select name=t1>



<?php
while (odbc_fetch_row($rs))
{
$location=odbc_result($rs,"Location");

echo "<option>";
echo $location;
}
?>



</select>

<select name=t2>



<?php
$sql2="SELECT DISTINCT Responsible FROM BackupLog";
$rs2=odbc_exec($conn,$sql2);

while (odbc_fetch_row($rs2))
{
$responsible=odbc_result($rs2,"Responsible");

echo "<option>";
echo $responsible;
}
odbc_close($conn);
?>

</select>

<input type=Submit name="one" value="Location">
<input type=Submit name="both" value="Location and Responsible">
</div>
</div>
</body>
</html>

and the second page code is as follows:

<?php
$conn=odbc_connect('backuplogs','','');

if (!$conn)

{exit("Connection Failed: " . $conn);}

$postlocation = $_POST['t1'];
$postresponsible = $_POST['t2'];

if($_POST['both'] == 'Location and Responsible') {

$results="SELECT * FROM BackupLog WHERE 
Location = '$postlocation' 
AND Responsible = '$postresponsible'";


$rs=odbc_exec($conn, $results);

while (odbc_fetch_array($rs)){


$servername=odbc_result($rs, "Servername");

$results2 = odbc_result_all($rs, "border=1");

echo $results2;

}

echo "</table>";	

}

else

{

$singleresults="SELECT * FROM BackupLog WHERE 
Location = '$postlocation'";


$rs2=odbc_exec($conn, $singleresults);

while (odbc_fetch_array($rs2)){


$servername=odbc_result($rs2, "Servername");

$results3 = odbc_result_all($rs2, "border=1");

echo $results3;

}

echo "</table>";	

}

Any help is appreciated, thanks.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by stonest123
1

Just so you know, you aren't closing your form tag in the first page.

I don't believe you can POST the value of a button. It would probably be better to have a check box saying "include responsible?" before the "Submit" button.

0

Thanks, I've changed the code now but i've hit another problem.

When i search for something in the database that i know has more than 1 result found. odbc_result_all doesn't return the last result in the database? any idea why?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.