Hi all, i have a form which is suppose to upload images, i have the images uploading into a mysql database, but when i query the database mysql i get the image path, maybe im doing something wrong, im new to php so any help would be great:
Here is the upload form:
<html>
<head>
<title>Car Rentals & Returns</title>
<meta http-equiv="Content-Type" content="text/html" />
<link href="style2.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{alert(alerttxt);return false;}
else {return true}
}
}function validate_form(thisform)
{
with (thisform)
{
if (validate_required(mymake,"Car Make must be selected!")==false)
{mymake.focus();return false;}
if (validate_required(mymodel,"Car Model must be filled out!")==false)
{mymodel.focus();return false;}
if (validate_required(myregistration,"Registration must be filled out!")==false)
{myregistration.focus();return false;}
}
}
</script>
</head>
<body>
<form action="case.php"
onsubmit="return validate_form(this);"
method="post">
<div id="wrapper3">
<img src="images/cars.jpg" width="996" height="100"></a>
<TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=100%>
<tr>
<td align="center">
<H1>Create new case</H1>
</td></tr>
<tr><td>
<h2>Please upload a new picture</h2>
<input type=hidden name=MAX_FILE_SIZE value=150000>
<input type=hidden name=completed value=1>
<br>Please choose an image to upload: <input type=file name=myimage><br>
<br>
Please enter the car make: <input name=mymake><br><br>
Please enter the car model: <input name=mymodel><br><br>
Please enter the car registration: <input name=myreg><br>
<br>
</TABLE>
<TABLE BGCOLOR="#F0F8FF" WIDTH=100%>
<TR><TD ALIGN="CENTER">
<input type="submit" value="Add Case"/><input type="reset" name="reset" value="Clear Form"/>
</form><form action="login_success.php" method="post">
<input type=submit value="Home"></form></TD></tr>
<TR><TD><BR></TD></TR>
</table>
</td></tr>
</body>
</html>
Here is my code for querying the database:
<html>
<head>
<title>Car Rentals & Returns</title>
<meta http-equiv="Content-Type" content="text/html" />
<link href="style2.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper3">
<img src="images/cars.jpg" width="996" height="100"></a>
<TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=100%>
<tr>
<td align="center">
<H1>View Cases:</H1>
<form method="post" action="view_2.php">
</td>
</table>
<TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=100%>
<tr>
<TD ALIGN=CENTER>
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="test"; // Database name
$tbl_name="reff"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "root", "root")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$result = mysql_query("SELECT * FROM reff ORDER BY make;");
$_SESSION['reff'] = array();
while ($row = mysql_fetch_assoc($result)) {
$_SESSION['reff'][] = $row;
}
foreach ($_SESSION['reff'] as $row) {
echo "<table border=\"1\" align=\"center\">";
echo "<tr><th>ID</th>";
echo "<td>";
echo $row['pid'];
echo "</td>";
echo "<tr><th>Make</th>";
echo "<td>";
echo $row['make'];
echo "</td>";
echo "<tr><th>Model</th>";
echo "<td>";
echo $row['model'];
echo "</td>";
echo "<tr><th>Registration</th>";
echo "<td>";
echo $row['registration'];
echo "</td>";
echo "<tr><th>Image</th>";
echo "<td>";
echo $row['imgdata'];
echo "</td>";
echo "<tr><th></th>";
echo "<td>";
echo "<button onclick=\"window.location.href='view_3.php?pid=".$row['pid']."'\">Details</button>";
echo "</td>";
echo "<tr>";
echo "<br>";
echo "<br>";
echo "</tr>";
}
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
if (mysql_num_rows($result) == 0) {
echo "No records found";
exit;
}
?>
<TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=30%>
</form>
<tr><form method="post" action="login_success.php">
<td align="center"><input type="submit" value="Home"/></td>
</tr>
</table>
</table>
</td>
</tr>
</table>
</BODY>
</HTML>
Any help would be great thanks.