Passing variables from php script to another
Posted: Thu Aug 03, 2006 8:07 am
Hi, I have a php script which searches for school name results in a database and displays them back as links to another php script which displays detailed information about the a particular school from the same table and database. Now the second php script is supposed to use a variable from the first php script. How can I send that variable. Please help.
Below are the two scripts in question.
search script.
view details script
Thanx in advance.
NB: Im new on the forum, and I'd preffer the neccesarry directions to than criticisims.
Below are the two scripts in question.
search script.
Code: Select all
<html>
<head>
<title>School Search Results</title>
</head>
<body>
<h3>School Search Results</h3>
<?php
//create short variable names
$search1=$HTTP_POST_VARS['name'];
$search2=$HTTP_POST_VARS['type'];
$search3=$HTTP_POST_VARS['year'];
$search3=trim($search3);
if(!$search1)
{
echo 'You have not entered search details please go back and try again';
exit;
}
$search1=addslashes($search1);
$search2=addslashes($search2);
$search3=addslashes($search3);
$conn = mysql_connect('localhost','','pass');
if (!$conn)
{
echo 'Error: could not connect to database. Please try again later.';
exit;
}
mysql_select_db('school');
$query = "select * from SCHOOL where sch_name like '%".$search1."%' or type like '%".$search2."%' or year like '%".$search3."%'";
$result = mysql_query($query) or die (mysql_error()."<br>Couldn't execute query: $query");
$num_results = mysql_num_rows($result);
echo '<p>Search results found: '.$num_results.'</p>';
for ($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
echo '<p> '.($i+1).'<a href=schselect.php> ';
echo htmlspecialchars(stripslashes($row['sch_name']));
echo '</a><br> ';
echo stripslashes($row['type']);
echo '<br> ';
echo stripslashes($row['year']);
echo '</p>';
}
?>
</body>
</html>Code: Select all
<?
$sch_name=$_GET[sch_name];
mysql_connect("localhost", "","pass") or
die ("Could not connect to database");
mysql_select_db("school") or
die ("Could not select database");
// define the SQL command
$query = "select * from school where sch_name = '$sch_name'";
// submit the query to the database
$res=mysql_query($query);
// make sure it worked!
if (!$res) {
echo mysql_error();
exit;
}
echo "<div align=\"center\">";
echo "<center>";
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"8\" width=\"98%\">";
echo "<tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $res )) {
// Print out the contents of each row into a table
echo "<tr>";
echo "<td width=\"100%\" height=\"58\" colspan=\"2\"><strong><font size=\"7\">";
echo $row['sch_name'];
echo "</font></strong>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo " <td width=\"20%\"><font size=\"2\">YEAR OF ESTABLISHMENT</font>";
echo "<font size=\"3\"><br>";
echo $row['year'];
echo "</font>";
echo "<font size=\"2\">";
echo "<br>";
echo "<p><font size=\"2\">LOCATION</font><font size=\"4\"><br>";
echo "</font><font size=\"2\">";
echo $row['location'];
echo "<br>";
echo "<p><font size=\"2\">KIND</font><br>";
echo "<font size=\"2\">";
echo $row['kind'];
echo "<br><br>";
echo "<p><font size=\"3\">TYPE</font></p>";
echo "<p>";
echo $row['type'];
echo "</p>";
echo "<p>TEL:</p><p><font size=\"3\">";
echo $row['phone'];
echo "</font><br>";
echo "<p>POSTAL ADDRESS:</p><p><font size=\"3\">";
echo $row['address'];
echo "</font><br>";
echo "</td>";
echo "<td width=\"80%\"><p><strong><font size=\"4\">Headteacher's Message</font></strong></p><p>";
echo $row['ht_msg'];
echo "</p></font></td></tr>";
}
echo "</table>";
echo "</center></div>";
echo "</table>"
?>NB: Im new on the forum, and I'd preffer the neccesarry directions to than criticisims.