Sunteți pe pagina 1din 4

Data Input and Output (Example)

Database Structure:

Database View:

Data Input:

<?php
$name=$_POST["st_name"];
$tel=$_POST["st_tel"];
$id=$_POST["st_id"];
$course=$_POST["st_course"];
$sex=$_POST["st_sex"];
$linkz=mysql_connect("localhost","root","") or die ("sorry didnot"); //connecting
mysql_select_db("test") or die("No_ DB_Found");//selecting Database
$sql="INSERT INTO student(ida,st_name,st_tel,st_id,st_course,st_sex) VALUES
(' ','$name','$tel','$id','$course','$sex')";
//echo $sql.mysql_error();
mysql_query($sql,$linkz); //passing sql
echo "student ".$name." was entered.";
echo "<hr>";
mysql_close($linkz);
?>
<html>
<body>
<h1 align="center">Student Details Entry</h1>

ii

<form action="" method="post">


<table border="1" align="center">
<tr><td>Name</td>
<td><input type=" text" name="st_name"></td></tr>
<tr><td>Telephone</td><td><input type="text" name="st_tel"></td></tr>
<tr><td>Student ID</td><td><input type="text" name="st_id"></td></tr>
<tr><td>Course</td>
<td><select name="st_course">
<option selected>Java</option>
<option selected>Visual Basic</option>
<option selected>Database</option>
<option selected>Software Engineering</option>
</select></td>
<tr><td>Sex</td><td><input name="st_sex" type="radio" value="Male">Male
<input name="st_sex" type="radio" value="Female">Female</td></tr>
<tr>
<td colspan="2" align="center">
<input type="submit">
</td></tr>
</table>
</form>
<?php
echo "<hr><font size=5>";
echo "</font></br>Add other function here.";
?>
</body></html>

Data Output:

iii

<?php
$linkz=mysql_connect ("localhost","root","") or die("sorry didnot");
//connecting
mysql_select_db("test",$linkz) or die("No_db_found"); //selecting Database
$sql="select * from student"; //sql to count columns / rows
$result=mysql_query($sql,$linkz); //passing sql
echo "<table border=1>";
$numofrows=mysql_num_rows($result);
for($fld=0; $fld<mysql_num_fields($result);$fld++) {
echo "<th>";
echo "&nbsp;&nbsp;&nbsp;".mysql_field_name($result,$fld);
echo "</th>";
}
while ($row=mysql_fetch_assoc($result)) {
echo"<tr>";
echo"<td>".$row["ida"]."</td><td>".$row["st_name"]."</td> <td>".
$row["st_tel"]."</td><td>".$row["st_id"]."</td> <td>".$row["st_course"]."</td><td>".
$row["st_sex"]."</td>";
echo"</tr>";
}
echo"</table>";
?>

iv

S-ar putea să vă placă și