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.

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.

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.