/    Sign up×
Community /Pin to ProfileBookmark

PHP image upload

Hi everyone, I am new here and new to php. I am working on a form with a image upload. I have to upload the image to the image folder and then write the image name to a mysql database. I am able to upload the image but I am unable to write the image name to the database.

PHP:
<?php include(“db_connect.php”);?>
<?php // select the database in which to add a table
mysql_select_db(“final_exam_db”,$con);

$sql =”INSERT INTO drivers_0115061 (ln,fn,month,day,year,img,email)
VALUES (‘”.$_POST[“ln”].”‘,
‘”.$_
POST[“fn”].”‘,
‘”.$_POST[“month”].”‘,
‘”.$_
POST[“day”].”‘,
‘”.$_POST[“year”].”‘,
‘”.$_
POST[‘img’][‘img’].”‘,
‘”.$_POST[“email”].”‘
)”;

//$sql=”INSERT INTO people (fn,ln,dob,city,prov,pc,gender,hc,nod) VALUES (‘steve’,’douglas’,1234567,’winnipeg’,’manitoba’,’r3p 6g5′,’m’,’grey’,2)”;

//echo $sql;

mysql_query($sql, $con);
echo mysql_error();
?>

<?php
$target_folder=”images/”;
$target_file=$target_folder.basename($_FILES[“img”][“img”]);
// if(move_uploaded_file($_
FILES[“img”][“tmp_name”],$target_file))
// {
// echo “It Worked!”;
// echo “<a href='”.$target_file.”‘target=’_blank’/>”.$target_file.”</a>”;
// }
// else
// {
// echo “Crap No Go!”;
// }
?>

<?php include(“db_close.php”);?>

html form (snippet):
<td>
Picture
</td>
<td>
<input type=”hidden” name=”MAX_FILE_SIZE” value=”10000000″/>
<input type=”file” id=”img” name=”img”/>
</td>

If anyone can help me out I would be forever grateful.

Thanks in advance,
Vince

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@PbpixelsMar 17.2013 — Hello Vince.

You could try inserting values without the "post" since it might affect something without being sure

you could try something like this:
[CODE]
$ln = $_POST['ln'];
$sql = "INSERT INTO drivers_0115061 VALUES ($ln, '$fn', '$month', '$day', '$year', '$img' '$email')";
[/CODE]

Hope it helps
Copy linkTweet thisAlerts:
@Vince_MauthorMar 17.2013 — I tried it and nothing worked. I also noticed that the image no longer uploads to the images folder. One other question. When I look at the database table it seems to be skipping record rows. It only uploads to every 2nd line. Any ideas?
×

Success!

Help @Vince_M spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...