0% found this document useful (0 votes)
63 views4 pages

Data Input and Output10122009

This document provides an example of data input and output in PHP. It includes code to connect to a MySQL database called "test", insert user-submitted form data into a student table, and output the data from the student table in an HTML table. User form data on student name, telephone, ID, course, and sex is inserted into the student table. Then a SELECT query retrieves all data from the student table and outputs it in an HTML table on the webpage.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views4 pages

Data Input and Output10122009

This document provides an example of data input and output in PHP. It includes code to connect to a MySQL database called "test", insert user-submitted form data into a student table, and output the data from the student table in an HTML table. User form data on student name, telephone, ID, course, and sex is inserted into the student table. Then a SELECT query retrieves all data from the student table and outputs it in an HTML table on the webpage.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like