I need a little help I have followed Tutorial: Storing Images in MySQL with PHP / Part II / Display your images and I want to change the table and insert.php script a little bit. I’ve changed the table (images) that holds the images by adding a column called subscriber I have another table called subscriber_info that all the subscriber_info is on but what I want to do is when I add the image I want to also record the subscriber_id into the subscriber column on the images table at the same time so that I know who added the picture and also so that I can create a page where all the subscribers can view all of the images that they have uploaded.
I have this script on my add.html page
<form action="insert.php" method="post" enctype="multipart/form-data" name="browse" id="brows_form"> <div align="left"> <input type="hidden" name="MAX_FILE_SIZE" value="102400" > <input name="image" type="file" class="style1" accept="image/jpeg" /> <input type="hidden" name="subscriber " value="<?php echo $row_subscriber_username['subscriber_id']; ?>" /> <input type="submit" value="Upload" > <span class="style10">Choose Your Profile Picture</span></div> </form>And this script on my insert.php page
<?php
$username = "root";
$password = "159753";
$host = "localhost";
$database = "the_secrets_out";
$table = "images";
$column = "image";
$link = mysql_connect($host, $username, $password); if (!$link) {
die("Can not connect to database: ".mysql_error());
}
mysql_select_db ($database);
if (isset($_FILES[$column]) && $_FILES[$column]['size'] > 0) {
$tmpName = $_FILES[$column]['tmp_name'];
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
$query = "INSERT INTO $table ";
$query .= "($column) VALUES ('$data')";
$results = mysql_query($query, $link);
print "Thank you, Your Image has been uploaded. DONT FORGET to add the image into your profile! ";
}
else {
print "No image selected/uploaded. Make sure that you have not exceeded the max file size!";
}
mysql_close($link);
?>
What do I need to change on the insert.php script to fetch the subscriber_id and insert it into the subscriber column?
Edited by whitestar, 15 February 2011 - 12:56 AM.


Sign In
Create Account


Back to top









