>> Line 1 - There is no attribute for the form tag called 'value'
>> Line 4, 5 - Do not use spaces between attributes and their values (so value = "sid" needs to be value="sid" )
>> Line 12 - Add a attribute "name" with the value "submitted" to the submit element, else the if statement on line 17 does not work correctly
>> Line 25, 26 - This is not an error but if the code goes online, it can be exploited by adding SQL code into the value of the form elements, clean it up before adding them to the query:
$searchword = htmlentities(addslashes($_POST['searchword']));
>> Line 48 - You need to place this line within the if statement brackets, as there only is a connection when it has been openend on line 19
~G
hi dear i just made some correction as you suggested but still some error. im bit stupid on php so could u pls check this code again for me?
<body>
<form method="post" action="new.php" name="submitted" />
<label>TYPE:
<select name="field">
<option value ="sid">StudentID</option>
<option value ="sname">StudentName</option>
</select>
</label>
<label>WORD:
<input type="text" name="searchword" />
</label>
<input type="submit" name ="submitted" />
</form>
<?php
if (isset($_POST['submitted'])){
$searchword = htmlentities(addslashes($_POST['searchword']));
$con = mysql_connect("localhost","root","");
mysql_select_db("uni", $con) or trigger_error('MySQL error: ' . mysql_error());
$field= $_POST['field'];
$searchword = $_POST['searchword'];
$result = mysql_query("SELECT* FROM student WHERE $field ='$searchword'") or trigger_error('MySQL error: ' . mysql_error());
//$result = mysql_query($query);
//$num_rows = mysql_num_rows($result);
//echo"num_rows results found.";
echo"<table>";
echo "<tr><th>StudentID</th><th>StudentName</th></tr>";
while($row = mysql_fetch_array($result)){
echo "<tr><td>";
echo "$row ['field']";
echo "</td><td>";
echo "$row ['searchword']";
echo "</td></tr>";
}
echo"</table>";
}
mysql_close($con);
?>
</body>
</html>
NB: this is my error.....
Notice: MySQL error: Unknown column 'sid' in 'where clause' in C:\wamp\www\new.php on line 37
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\new.php on line 45