Heloo, i want to upload image file to a directory and want to make a reference in mysql, i have the following code. i am unable to figure out whats the problem in my code,...... please help me out
<?php
include("../include/dbconnection.php");
session_start();
$ses_id = session_id();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Color Information</title>
<style type="text/css">
<!--
.center {
text-align: center;
font-weight: bold;
}
.c {
color: #F00;
}
-->
</style>
<script type="text/javascript">
function validate(form)
{
var code = form.code.value;
var color = form.color.value;
if (code.length ==0)
{
window.alert('Please Enter Color Code');
return false;
}
if (code.length >2)
{
window.alert('Color Code Length Could Not be Greater than 2 Digits');
return false;
}
if (code.length <2)
{
window.alert('Color Code Length Could Not be Shorter than 2 Digits');
return false;
}
if (color.length ==0)
{
window.alert('Please Enter Color Information');
return false;
}
return true;
}
</script>
</head>
<body >
<?php
$query = "select FirstName, LastName , Status from users where Status = 1 " ;
$result = mysql_query($query , $con);
while($data = mysql_fetch_array($result))
{
$F_Name = $data['FirstName'];
$L_Name = $data['LastName'];
$sts = $data['Status'];
}
if ($sts == 1)
{
//----------------------------------------------------------------------------------------
?>
<div align="center"><a href="home.php"> <i>Home</i> </a></div>
<?php
if (!isset ($_POST['submit']))
{
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" onsubmit="return validate(this);">
<table border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="pink" >
<tr>
<td colspan="2" class="center">Enter New Color</td>
</tr>
<tr>
<td> Color Code: </td>
<td><input type="text" name="code" size="35"/> </td>
</tr>
<tr>
<td> Color Name: </td>
<td><input type="text" name="color" size="35"/> </td>
</tr>
<tr>
<td> Color Pic: </td>
<td><input type="hidden" name="size" value="350000" />
<input type="file" name="photo" size="35" /> </td>
</tr>
<tr>
<td> </td>
<td align="center"> <input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
<?php
$query1 = "select * from color";
$result1 = mysql_query($query1 , $con);
?>
<table border="1" bordercolor="#000033" align="center">
<tr bgcolor="pink">
<td>Color ID </td>
<td>Color Code </td>
<td>Color Name </td>
<td> Picture </td>
</tr>
<?php
while($ds = mysql_fetch_array($result1))
{
?>
<tr>
<td><?php echo $ds['ColorID']; ?> </td>
<td align="center"> <?php echo $ds['ColorCode']; ?> </td>
<td><a href="color_edit.php?id=<?php echo $ds['ColorID']; ?>"> <?php echo $ds['ColorName']; ?> </a></td>
</tr>
<?php
}
?>
</table>
<?php
}
else
{
$Color = $_REQUEST['color'];
$Code = $_REQUEST['code'];
$target_path = "colorimg/";
$target_path = $target_path . basename( $_FILES['photo']['name']);
$Target = $target_path;
move_uploaded_file($_FILES['photo']['tmp_name'], $Target);
$sql = mysql_query ("insert into color (ColorName , ColorCode,ColorPic)
VALUES
('$Color' , '$Code','$Target')" , $con);
echo "data inserted successfully";
}
}
else { echo "error"; }
mysql_close($con);
?>
</body>
</html>