Search MySQL after accepting data from text field
Posted: Wed May 09, 2007 2:52 am
HI,
I'm doing a website for one of the college and they want to display there result on the website. The result should be displayed when a user searchs for a roll number.
I made a page result.php in which the user enters the roll number and searches
This leads to a page result1.php where the code is:
The table structure is:
Whenever I am trying to search the database it is giving "'Roll Number Not Found. Please check the roll number and try again"
Please help with the code!!
I'm doing a website for one of the college and they want to display there result on the website. The result should be displayed when a user searchs for a roll number.
I made a page result.php in which the user enters the roll number and searches
Code: Select all
<form id="form1" name="form1" method="post" action="result1.php">
<input name="roll" type="text" id="roll" />
<input name="Go" type="submit" id="Go" value="Go" />
<input type="reset" name="Reset" value="Reset" />Code: Select all
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("database",$db);
$roll = $_POST['roll'];
if (!empty($_GET['roll']) && is_numeric($_GET['roll']))
{
$sql = "SELECT roll, student, father, category, theory, prac1, prac2, total, percent, divison FROM tablename WHERE roll=".$_GET['roll'];
$result = mysql_query($sql, $db) or die(mysql_error().'<p>'.$sql.'</p>');
if (mysql_num_rows($result) == 1)
{
while ($row = mysql_fetch_array($result))
{
$roll = $row['roll'];
$student = $row['student'];
$father = $row['father'];
$category = $row['category'];
$theory = $row['theory'];
$prac1 = $row['prac1'];
$prac2 = $row['prac2'];
$total = $row['total'];
$percent = $row['percent'];
$divison = $row['divison'];
}
}
else
{
echo 'Roll Number Not Found. Please check the roll number and try again';
}
}
else {
echo 'Roll Number Not Found. Please check the roll number and try again';
}
<table width="50%" border="0" align="center" cellpadding="0" cellspacing="4">
<tr>
<td>Roll Number of Candidate </td>
<td>:</td>
<td><?php echo $roll ?></td>
</tr>
<tr>
<td>Name of Candidate </td>
<td>:</td>
<td><?php echo $name ?></td>
</tr>
<tr>
<td>Father's Name </td>
<td>:</td>
<td><?php echo $father ?></td>
</tr>
<tr>
<td>Category</td>
<td> </td>
<td><?php echo $category ?></td>
</tr>
<tr>
<td>Rank</td>
<td>:</td>
<td> </td>
</tr>
<tr>
<td>Theory</td>
<td>:</td>
<td><?php echo $theory ?>/600</td>
</tr>
<tr>
<td>Practical - I </td>
<td>:</td>
<td><?php echo $prac1 ?>/300</td>
</tr>
<tr>
<td>Practical - II </td>
<td>:</td>
<td><?php echo $prac2 ?>/300</td>
</tr>
<tr>
<td class="textbold">Total Marks</td>
<td class="textbold">:</td>
<td class="textbold"><?php echo $total ?>/1200</td>
</tr>
<tr>
<td>Percentage</td>
<td>:</td>
<td><?php echo $percent ?></td>
</tr>
<tr>
<td>Divison</td>
<td>:</td>
<td><?php echo $divison ?></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>Code: Select all
`roll` tinyint(4) NOT NULL default '0',
`student` varchar(50) NOT NULL default '',
`father` varchar(50) NOT NULL default '',
`category` varchar(10) NOT NULL default '',
`theory` varchar(5) NOT NULL default '',
`prac1` varchar(5) NOT NULL default '',
`prac2` varchar(5) NOT NULL default '',
`total` varchar(5) NOT NULL default '',
`percent` varchar(5) NOT NULL default '',
`divison` char(2) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1;Please help with the code!!