uploading image to php mysql?

ApurvA

New member
JAI MATADI all ..

i m uploading image into first my directory folder called as "upload" (folder) and then uploading it into my database called "alldatabase" (database name)

here is my uploading image to first directory and then database code ..

page1.php
--------------------------------------------------
<form method="post" name="f1" id="f1" enctype="multipart/form-data" >
Upload Image : <input type="file" id="file1" name="file1" />
Name : <input type="text" name="t1" id="t1" />
<br />

<input type="submit" id="submit" name="submit" onclick="ab()" />

</form>

<?php

$path = "upload/";
$path = $path . $_FILES["file1"]["name"];
move_uploaded_file($_FILES["file1"]["tmp_name"],$path);
echo "The File successfully Uploaded" . "<br>";
echo "Stored in : " . "upload/" . $_FILES["file1"]["name"] . "<br>";

$imgg = $_FILES["file1"]["name"];
mysql_connect("localhost","root","");
mysql_select_db("alldatabase");
$qry = "insert into signup (username,ppassportphoto) values('$uname','$path')";
if(mysql_query($qry))
{
echo "Successfully Inserted into Database" . "<br>";
}
----------------------------------------
m able to see in database as my image picture like this "upload/imagename.jpg" in my database ...

& dont look this code preety closely as i m able to upload it pretty well this is the base of my question m letting you know what problem m facing now

what i m trying to do now in the second new page is .. if the user write his/her name then he/she will be able to see the particular image he/she uploaded b4 ..
here is my code ..


page2.php
--------------------------------------------------------
<form enctype="multipart/form-data" id="f1" name="f1" method="post">
Enter the Name : <input type="text" name="t1" id="t1" />
<br />
<input type="submit" name="submit" id="submit" />
</form>
<?php
if(isset($_POST["submit"]))
{
$uname = $_POST["t1"];
mysql_connect("localhost","root","");
mysql_select_db("alldatabase");
$qry = "select * from signup where username='$uname' ";
if(!mysql_query($qry))
{
mysql_error();
}
$row = mysql_fetch_array($qry);
$path=$row['ppassportphoto'];
echo "<img src='$path' width=300 height=250 alt= >";
}
?>
----------------------------------------------------

but m not able to get the image .. instead m getting the warning saying

mysql_fetch_array() expects parameter 1 to be resource, string given in C:\wamp\www\login and etc database\try2.php on line 25

(
here on line 25 means m getting error in this line

$row = mysql_fetch_array($qry);
)

please tell me wht wrong m doing ..
 
Back
Top