Professional Documents
Culture Documents
Database Connectivity With PHP and MYSQL
Database Connectivity With PHP and MYSQL
<tr>
<td>PASSWORD</td>
<td> <input name="pwd" type="password" id="pwd" /> </td>
</tr>
<tr>
<td>TECHNOLOGY</td>
<td> <select name="tech" id="tech">
<option value="0"> Technology </option>
<?php
$technology = array("PHP", "JOOMLA", "MAGENTO", "CAKE",
"ZEND", "YII", "DRUPAL", "WORDPRESS");
foreach($technology as $v)
{
echo "<option value='".$v."'>".$v."</option>";
}
</td>
</tr>
?>
</select>
<tr>
<td>AGE</td>
<td>
<select name="age" id="age">
<option value="0"> Age </option>
<?php
$age = range(18,60);
foreach($age as $v)
{
echo "<option value='".$v."'>".$v."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>CONTACTAT NO </td>
<td> <input name="contact" type="text" id="contact" /> </td>
</tr>
<tr>
<td colspan="2">
<input name="insert" type="submit" value=" INSERT " />
<input name="display" type="submit" value=" DISPLAY " />
<input name="edit" type="submit" value=" EDIT " />
<input name="delete" type="submit" value=" DELETE " />
</td>
</tr>
<tr> <td colspan="2"><?php echo $msg; ?></td> </tr>
</table>
</form>
</body>
</html>
$technology =
array("PHP","JOOMLA","MAGENTO","CAKE","ZEND","YII","DRUP
AL","WORDPRESS");
$id
= $_REQUEST['id'];
$pwd = $_REQUEST['pwd'];
$tech = $_REQUEST['tech'];
$uage = $_REQUEST['age'];
$contact = $_REQUEST['contact'];
if(isset($_REQUEST['insert']))
{
$sql = "insert into students values('$id', '$pwd', '$tech', '$uage', '$contact')";
mysql_query($sql) or die(mysql_error());
$msg = "Data saved sucessfully!";
}
if(isset($_REQUEST['display']))
{
$sql = "select * from students";
$data = mysql_query($sql);
echo "<table width='700px' border='1' align='center'>";
echo "<th> SL </th>
<th> STUDENT ID </th>
<th> PASSWORD </th>
<th> CONTACT NO </th>
<th> ACTION </th>";
$i = 0;
while($res = mysql_fetch_assoc($data))
{
$i++;
$tsid = $res['studentid'];
$tpwd = $res['password'];
$cont = $res['contactno'];
echo "<tr> <td>".$i."</td> <td>".$tsid."</td>
<td>".$tpwd."</td> <td>".$cont."</td>
<td>
<a href='#'> EDIT </a>
<a href='#'> VIEW </a>
<a href='#'> DELETE </a>
</td>
</tr> ";
}
echo "</table>";
}
if(isset($_REQUEST['delete']))
{
echo $sql = "delete from students where studentid='$id'";
$data = mysql_query($sql);
echo "data deleted sucessfully";
}
?>