I m new to php..I have page in which the user as to enter a number and when clicked on submit the page as to redirect to the entered number in the first form. all the details of that number as to be displayed for updating it. How can I do this?
Here is the code. The first page which takes only the number
<form method="post" action="modify.php">
<label type="text" name="name" maxlength="50" size="30" class="label">Enter the Membership Number</label><br />
<input type="text" name='id' placeholder="enter Number which u want to edit" class="input" size="40"/><br />
<span class="field">(* Required field)</span><br /><br />
<input type="submit" name="submit" value="SUBMIT" class="button"><br /><br /><br /><br />
</form>
</body>
</html>
<?php
mysql_connect("localhost","root","");
mysql_select_db("adminstud");
if(isset($_POST['submit']))
$id=$_POST['id'];
if( ! ctype_alnum($id) )
die('invalid id');
$query = "SELECT FROM `stud` WHERE `id` =$id";
$run = mysql_query($query);
if(mysql_num_rows($run)>0){
echo "<script>window.open('modify.php?id=".$id."','_self')</script>";
}
else {
echo "<script>alert('Membership No is Invalid!')</script>";
}
}
?>
second page is to modify the record
I m getting error in this page as undefined index id in modify.php. Where should i define id. And how should i define id
modify.php
<?php
mysql_connect("localhost","root","");
mysql_select_db("adminstud");
if(isset($_POST['update'])){
$UpdateQuery = "UPDATE stud SET Student_name='".$_POST['Student_name']."', Father_name='".$_POST['Father_name']."', Mother_name='".$_POST['Mother_name']."', Nationality='".$_POST['Nationality']."', Address1='".$_POST['Address1']."', Address2='".$_POST['Address2']."',email='".$_POST[email]."', DOB='".$_POST['DOB']."', Gender='".$_POST['Gender']."', Percentage='".$_POST['Percentage']."' WHERE Student_name='".$_POST['hidden']."'";
$run=mysql_query($UpdateQuery);
};
$sql = "SELECT * FROM stud where id='".$_GET['id']."'" ;
$myData = mysql_query($sql);
echo "<table border=1>
<tr>
<th>id</th>
<th>Student_name</th>
<th>Father's_Name</th>
<th>Mother's_name</th>
<th>Nationality</th>
<th>Address Line 1</th>
<th>Address Line 2</th>
<th>Email</th>
<th>DOB</th>
<th>Gender</th>
<th>Percentage</th>
</tr>";
while($record = mysql_fetch_array($myData)){
echo "<form action=modify.php method=post>";
echo "<tr>";
echo "<td>" . "<input type=text name=Student_name value=" . $record['Student_name'] . " </td>";
echo "<td>" . "<input type=text name=Father_name value=" . $record['Father_name'] . " </td>";
echo "<td>" . "<input type=text name=Mother_name value=" . $record['Mother_name'] . " </td>";
echo "<td>" . "<input type=text name=Nationality value=" . $record['Nationality'] . " </td>";
echo "<td>" . "<input type=text name=Address1 value=" . $record['Address1'] . " </td>";
echo "<td>" . "<input type=text name=Address2 value=" . $record['Address2'] . " </td>";
echo "<td>" . "<input type=Email name=email value=" . $record['email']. " </td>";
echo "<td>" . "<input type=text name=DOB value=" . $record['DOB'] . " </td>";
echo "<td>" . "<input type=text name=Gender value=" . $record['Gender'] . " </td>";
echo "<td>" . "<input type=text name=Percentage value=" . $record['Percentage'] . " </td>";
echo "<td>" . "<input type=hidden name=hidden value=" . $record['Student_name'] . " </td>";
echo "<td>" . "<input type=submit name=update value=update" . " </td>";
echo "</tr>";
echo "</form>";
}
echo "<form action=modify.php method=post>";
echo "<tr>";
echo "<td><input type=text name=id></td>";
echo "<td><input type=text name=Student_name></td>";
echo "<td><input type=text name=Father_name</td>";
echo "<td><input type=text name=Mother_name></td>";
echo "<td><input type=text name=Nationality></td>";
echo "<td><input type=text name=Address1</td>";
echo "<td><input type=text name=Address2></td>";
echo "<td><input type=email name=email> </td>";
echo "<td><input type=text name=DOB</td>";
echo "<td><input type=text name=Gender></td>";
echo "<td><input type=text name=Percentage></td>";
echo "</form>";
echo "</table>";
?>
</body>
</html>