First off, im a newbie to PHP so please go easy on me.
I wanted to create a simple login system that can upload a photo of a user that when he login he'll be redirected to his account and their individual id picture will appear. I already have a login system but i dont know how to integrate the tutorial i've read from the net.
here's the scenario:
index.php --> ask for a username and password, if success redirected to account.php
account.php --> show the id pic of the user.
user_registration.php --> username, password and upload id picture.
currently, i already have a working login system but i don't know how to view the id picture.
Pls see code below:
how do i view the id of the user here uniquely for each user? I always get an error on this and i have to manually set the id to eg. "1" or "2" before i can view it.
PHP Code:
<?php
//account.php
$username = "";
$password = "";
$host = "localhost";
$database = "";
@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'];
if(!isset($id) || empty($id)){
die("Please select your image!");
}else{
$query = mysql_query("SELECT * FROM tbl_images WHERE id='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['image'];
header('Content-type: image/jpg');
echo $content;
}
?>
and how do i add a username and password + confirm password on this code
PHP Code:
//registration.php
<?php
// Create MySQL login values and
// set them to your login information.
$username = "";
$password = "";
$host = "localhost";
$database = "";
// 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);
?>
btw, i already have a database for this.
I really need help with as i already spent weeks just to figure out and i can't find a tutorials on google as same as this.
Any help would greatly appreciated. Thanks.
+++++++++++++++++++++++++++++++++++++++++++++++++
Pisotens is back. :)
Since, i dont know how to make a user profile creation if i'll add an upload image and instead manually upload the image to the db. How do i display the image and i identify the correct id picture of the user?