I am sooooo glad i found this forum, i just hope i can be helped before my deadline (which is tomorrow afternoon!) Now before I begin, you need to know that i have VERY LIMITED php experience. I know the basic functions, what they do and in a way how they operate, but thats about it. So giving a one sentence answer like "you need to use the php_function_yourscrewed wont help me what so ever. I will however give all of the code i am using, and really its a simple thing i am struggling with.
I have a customer who wants to add their products to a website. ITs a very simple database application, containing:
* Product Name
* Product image
* Description.
I am using php5 and mysql. The database is already created, with the following fields:
* ID
* name
* img (its a blob type field)
* description
I found a tutorial script which basically does what i need. I can add stuff to the database, edit and delete it. I can obviously also recall it. But my problem comes in with the image. All images will be jpg, 200 width and 150height, and will never be more than 150kb.
I found out today that I have one of 2 ways to do this:
* BLOB
* image directory must be saved in database.
Honestly, i want to learn how to do this, but with my limited php skills, and the fact that i berely understand the script i am using, i have gone thru 100's of "quick tutorials" and EACH ONE IS DIFFERENT, and with that its something new every time! I am not limited to web space, nor database size, so honestly i do not care where the image is stored.
Knowing php, there probably isnt a easy way to do it. I am pasting my code with the hopes that someone can help me to
1) store the files in the database.
2) Give me a LOGICALLY method to retrieve it.
PLEASE PLEASE PLEASE, I am in need of help URGENTLY!
Code: Select all
<html>
<body>
<?php
$image = $row['img'];
$db = mysql_connect("localhost", "root", "password");
mysql_select_db("products",$db);
if ($submit) {
if ($id) {
$sql = "UPDATE bushshirts SET img='$img',name='$name',description='$description' WHERE id=$id";
} else {
$sql = "INSERT INTO bushshirts (img,name,description) VALUES ('$img','$name','$description')";
}
$result = mysql_query($sql);
echo "Record updated/edited!<p>";
} elseif ($delete) {
$sql = "DELETE FROM bushshirts WHERE id=$id";
$result = mysql_query($sql);
echo "$sql Record deleted!<p>";
} else {
if (!$id) {
$result = mysql_query("SELECT * FROM bushshirts",$db);
while ($myrow = mysql_fetch_array($result)) {
printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF, $myrow["id"], $img["$image"],$myrow["name"], $myrow["description"]);
printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["id"]);
}
}
?>
<P>
<a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>
<P>
<form action="<?php echo $PHP_SELF?>" method="post" enctype="multipart/form-data">
<?php
if ($id) {
$sql = "SELECT * FROM bushshirts WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
$first = $myrow["name"];
$last = $myrow["img"];
$address = $myrow["description"];
?>
<input type=hidden name="id" value="<?php echo $id ?>">
<?php
}
?>
Name:
<input type="name" name="name" value="<?php echo $first ?>"><br>
Image:
<label>
<input type="file" name="img" id="img">
</label>
<br>
Description
<label>
<textarea name="description" value="<?php echo $description ?>" id="description" cols="45" rows="5"></textarea>
</label>
<br>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
}
?>
</body>
</html>scottayy| Please put your code in BBCode [ code ] tags. I've edited your post to show how we would like it posted.