Button's Code:
<?php
if(isset($_POST['btnSave']))
{
$UN = $_POST['txtName'];
$PH = $_POST['txtPhone'];
$EM = $_POST['txtEmail'];
$FN = $_FILES['UFile']['name'];
$FT = $_FILES['UFile']['type'];
$TN = $_FILES['UFile']['tmp_name'];
echo "Temp Name: $TN<br>";
if($FT =="image/jpeg" || $FT == "image/gif" || $FT=="image/png")
{
move_uploaded_file($TN,"Data/$FN");
$A = mysql_connect("LocalHost","root","") or die("Error in MYSQL Connection!");
mysql_select_db("BahriaDB",$A) or die("Error in DataBase!");
mysql_query("Insert into tblRegister values ('','$UN','$PH','$EM','$FN')",$A) or die("Error in Insert Query.");
mysql_close($A);
}
else
{ echo "Error: Select jpg | gif | png image."; }
}
?>
Form's Code:
<html>
<body>
<form action="Attach.php" method="POST" Enctype="multipart/form-data">
<table border=1 CellPadding=5 CellSpacing=5>
<tr>
<td>Name</td>
<td><input type=Text name=txtName required=required></td>
</tr>
<tr>
<td>Phone</td>
<td><input type=Text name=txtPhone required=required></td>
</tr>
<tr>
<td>Email</td>
<td><input type=Text name=txtEmail required=required></td>
</tr>
<tr>
<td>Select Image</td>
<td><input type=File name=UFile></td>
</tr>
<tr>
<td>.</td>
<td><input type=Submit name=btnSave value=Save></td>
</tr>
</table>
</form>
Table's View:
<table border=1 CellPadding=5 CellSpacing=5>
<tr BGColor=Aqua> <th>RID</th> <th>Name</th> <th>Phone</th> <th>E-Mail</th> <th>Image</th> </tr>
<?php
$A = mysql_connect("LocalHost","root","") or die("Error in MYSQL Connection!");
mysql_select_db("BahriaDB",$A) or die("Error in DataBase!");
$B = mysql_query("Select * from tblRegister",$A) or die("Error in Insert Query.");
$T = mysql_num_rows($B);
echo "Total Records: $T<br>";
for($a=0; $a<$T; $a++)
{
$R = mysql_fetch_array($B);
echo "<tr>";
echo "<td>$R[0]</td>";//RID
echo "<td><a href='Detail.php?A=$R[0]'>$R[1]</a></td>";//Name
echo "<td>$R[2]</td>";//PHone
echo "<td>$R[3]</td>";//Email
echo "<td><img src='Data/$R[4]' width=100 height=100 border=5 Title='$R[1]'></td>";
echo "</tr>";
}
mysql_close($A);
?>
</table>
</html>
No comments:
Post a Comment