-2

i am learning php and phpmyadmin I want to upload Images to database then echo the same image to another page any one help me

index.html

<html>
<body>
    <form name="form" method="post" action="insert_ac.php">
      <h1>Insert Data Into mySQL Database</h1>

            name......    <input name="name" type="text" id="name"> <br><br>
            username....  <input name="username" type="text" id="username"> <br><br>
            password..    <input name="password" type="text" id="lastname"><br><br>
            Email.....    <input name="email" type="text" id="email"><br><br>
            Upload Image....... :<input type="file" name="image" id="uploadimg"><br>
      <input type="submit" name="Submit" value="Submit">
    </form>
</body>
</html>

insert_ac.php

<?php

$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="loginfour"; // Database name
$tbl_name="test_four"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form
$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];
$name=$_POST['name'];

// Insert data into mysql
$sql="INSERT INTO $tbl_name(username, password, email, name)VALUES('$username', '$password', '$email', '$name')";
$result=mysql_query($sql);

// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='insert.php'>Back to main page</a>";
}

else {
echo "ERROR";
}
?>

<?php
// close connection
mysql_close();
?>

i want to upload image and show it to insert_ac.php any one assist me..........................

3
  • Have a look at vikasmahajan.wordpress.com/2010/07/07/…
    – Laurent W.
    Sep 27, 2013 at 8:00
  • a lot of tutorials exit in internet , try googling , inset your image name img.jpg to Database and upload file to your folder, and then concat path with name
    – Charaf JRA
    Sep 27, 2013 at 8:00
  • There are two patterns for storing images in a database. The first is to store only the path to the image file, and store the file itself in the filesystem. The seconds is to store the actual image in the database as a blob. PS: do not use the 'mysql' library, use 'mysqli' instead when working with php-mysql. Sep 27, 2013 at 8:03

1 Answer 1

0

the php page is simple

echo($_FILES["image"]["name"]);

reference

2
  • I was just pointing out a minor typo in your answer - thank you for correcting it!
    – andrewsi
    Sep 27, 2013 at 13:45
  • @andrewsi the way of explanation is great , thnx
    – user1899563
    Sep 27, 2013 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.