well written thanks
HI, I tried this script in my webpage the upload works fine but i couldnt display the image it says "please select the image" when i check my mysql it shows 1 row affected..
could u please help me resolve this problem
Did you edit that script?
If yes please post it here.. then I can help you![]()
HI , thanks for your reply..
if you could sorld out this issue today , it ll be very helpful to me..
insert.php
show.phpCode:<?php
// Create MySQL login values and
// set them to your login information.
$username = "user1";
$password = "password1";
$host = "mysql2.ten4onehost.com";
$database = "michaels";
// Make the connect to MySQL or die
// and display an error.
$link = mysql_connect($host, $username, $password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// Select your database
mysql_select_db ($database);
// Make sure the user actually
// selected and uploaded a file
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {
// Temporary file name stored on the server
$tmpName = $_FILES['image']['tmp_name'];
// Read the file
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
// Create the query and insert
// into our database.
$query = "INSERT INTO tbl_images ";
$query .= "(image) VALUES ('$data')";
$results = mysql_query($query, $link);
// Print results
print "Thank you, your file has been uploaded.";
}else{
print "No image selected/uploaded";
}
// Close our MySQL Link
mysql_close($link);
?>
thank youCode:<?php
$username = "user1";
$password = "password1";
$host = "mysql2.ten4onehost.com";
$database = "michaels";
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
@mysql_select_db($database) or die("Can not select the database: ".mysql_error());
$id = $_GET['id'];
$query = mysql_query("SELECT * FROM tbl_images WHERE id=1);
$row = mysql_fetch_array($query);
$content = $row['image'];
header('Content-type: image/jpg');
echo $content;
?>
Last edited by Jaan; 12-15-2009 at 09:52 AM. Reason: Please use code tags when you are posting your codes!
Change this:
to this:Code:$query = mysql_query("SELECT * FROM tbl_images WHERE id=1);
Code:$query = mysql_query("SELECT * FROM tbl_images WHERE id='1'");
I think this line in show.php needs to be changed :
intoCode:$row = mysql_fetch_array($query);
Code:$row = mysql_fetch_assoc($query);
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
Works perfect, thank you!
I'd say that your line shall be:
and the line above, is even better if it is:Code:$query = mysql_query("SELECT * FROM tbl_images WHERE id='$id'");
Code:$id = mysql_real_escape_string($_GET['id']);
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
There are currently 2 users browsing this thread. (0 members and 2 guests)
Bookmarks