Forum Moderators: coopster
I call this code, search.php, while the one after this is called view.php
The table is personnel with columns (id-auti_increment, firstname,lastname,nick,email,salary)
<HTML>
<?php
if ($searchstring)
{
$sql="SELECT * FROM personnel WHERE $searchtype LIKE '%$searchstring%' ORDER BY firstname ASC";
$db = mysql_connect("localhost", "root", "");
mysql_select_db("learndb",$db);
$result = mysql_query($sql,$db);
echo "<TABLE BORDER=2>";
echo"<TR><TD><B>Full Name</B><TD><B>Nick Name</B><TD><B>Options</B></TR>";
while ($myrow = mysql_fetch_array($result))
{
echo "<TR><TD>".$myrow["firstname"]."
".$myrow["nick"];
echo "<TD><a href=\"view.php?id=".$myrow[id]."\">View</a>";
}
echo "</TABLE>";
}
else
{
?>
<form method="POST" action="<?php $PHP_SELF?>">
<table border="2" cellspacing="2">
<tr><td>Insert you search string here</td>
<td>Search type</td></tr>
<tr>
<td><input type="text" name="searchstring" size="28"></td>
<td><select size="1" name="searchtype">
<option selected value="firstname">First Name</option>
<option value="lastname">Last Name</option>
<option value="nick">Nick Name</option>
<option value="email">Email</option>
</select></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset"
></p>
</form>
<?php
}
?>
</HTML>
This is view.php
<HTML>
<?php
$db = mysql_connect("localhost", "root", "");
mysql_select_db("learndb",$db);
$result = mysql_query("SELECT * FROM personnel WHERE id=$id",$db);
$myrow = mysql_fetch_array($result);
echo "First Name: ".$myrow["firstname"];
echo "<br>Last Name: ".$myrow["lastname"];
echo "<br>Nick Name: ".$myrow["nick"];
echo "<br>Email address: ".$myrow["email"];
echo "<br>Salary: ".$myrow["salary"];
?>
</HTML>
Please why is this code no more working and what is the solution.
Thanks.
okonjiaustin
I guess nobody is going to fix it for you while you are not making any effort. Let's start doing it!
first step, display your query by echoING your $sql variable and see if you are getting the query structure correct. If you do not get the variables values in the query it means your old PHP version had REGISTER GLOBAL ON and this has set it to OFF so use ini_set() or htaccess to switch on this for your script life time, alternatively use global arrays, suggested method, i.e $_GET,$_POST or $_REQUEST to cover both previous arrays to get the variable values.
I hope you will solve it by this, if not, please return with the updated status of the problem and post your sql query structure here to get further help.
thank you
You are a great guy, this problem has given me gray hairs for sometime now, but within a few seconds you have just given the solution.
I am very happy to be associated with this forum. I still have one more problem I will submit by tomorrow on retrieving images from mysql databases.
Thanks, good guy till tomorrow.
Okonjiaustin