How to add images in your website using database?
<?php
//connect mysql//
$connect = mysql_connect("servername","username","password");
//select database//
mysql_select_db("databasename");
if($_POST['BtnSubmit'])
{
$Name=$_POST['TxtName'];
$Web=$_POST['Txtweb'];
$Is_Active="1";
$Is_Deleted="0";
$filename = $_FILES["Photo"]["name"];
$type = $_FILES["Photo"]["type"];
$size = $_FILES["Photo"]["size"];
$temp = $_FILES["Photo"]["tmp_name"];
$error = $_FILES["Photo"]["error"];
if($error >0)
{
}
else
{
$fileext=explode('.',$filename);
$fileext=$fileext[count($fileext)-1];
$filename=$Name.'.'.$fileext;
move_uploaded_file($temp,"Uploaded/".$filename);
$query="INSERT INTO portfolio(P_Name,Photo,Website,Is_Active,Is_Deleted,Created_Date) VALUES('$Name','$filename','$Web',$Is_Active,$Is_Deleted,now());";
$write=mysql_query($query);
if($write)
header('location:ListPo.php');
else
echo mysql_error();
}
}
?>
Html code:
<form action="AddPo.php" method="post" onsubmit="return validation();" enctype="multipart/form-data">
<table><tr><td><font color="#FFFFFF" size="+3" face="Lucida Handwriting"><strong>Add Portfolio</strong></font></td></tr></table><br />
<table class='ImageBox1' align="center" >
<tr>
<td><input type="text" name="TxtName" id="TxtName" size="35" placeholder="Portfolio Name..!!" class="inputtext"/></td>
<td style="padding-top:5px;"><font size="+3" color="#990000"> *</font></td>
</tr>
<tr><td height="10px"></td></tr>
<tr>
<td>( Photo )<br /><input type="file" name="Photo" id="Photo" class="inputtext" size="27" placeholder="Photo"/></td>
<td style="padding-top:5px;" valign="bottom"><font size="+3" color="#990000"> *</font></td>
</tr>
<tr><td height="10px"></td></tr>
<tr>
<td><input type="text" name="Txtweb" id="Txtweb" size="35" placeholder="Website Name..!!" class="inputtext"/></td>
<td style="padding-top:5px;"><font size="+3" color="#990000"> *</font></td>
</tr>
<tr>
<td height="15px"></td>
</tr>
<tr>
<td align="center">
<input type="submit" value="Submit" name="BtnSubmit" class="botton" />
<input type="reset" value="Reset" name="BtnReset" class="botton"/>
</td>
</tr>
</table>
</form>
No comments:
Post a Comment