/    Sign up×
Community /Pin to ProfileBookmark

Insert ID value from dynamic dropdown into SQL table

Insert ID value from dynamic dropdown into SQL table

Hello,

I have a dynamically generated drop down menu as part of a form on my php page :

[CODE]
Location in Scotland : <select name=”location”>
<?php
require_once (‘../mysql_connect.php’); // Connect to the database
$query = “SELECT aname, id FROM area ORDER BY aname”;
$result = mysql_query ($query); // Run the Query
while ($row = mysql_fetch_array($result)) {
echo ‘<option value=”‘ . $row[‘id’] . ‘”>’ . $row[‘aname’] . ‘</option>’;
}
?>
</select>
[/CODE]

This takes the area name and id from the area table, and uses it to display the drop down menu.
However, when I try to insert data into the user_images table, it doesn’t work.

My INSERT INTO is above this in the php and is as follows :

[CODE]
$query = “SELECT user_id FROM users WHERE first_name = ‘$_SESSION[first_name]'”;
$result = mysql_query($query) or trigger_error(“Query: $queryn<br />MySQL Error: ” . mysql_error());
$row = mysql_fetch_array($result);
// Add the Image
$MIMEtype = $_FILES[‘img’][‘type’]; // putting the file type into the table with the variable name MIMEtype
$query = “INSERT INTO user_images (image_name, area, img_src, dateUpload, cameraType, longitude, latitude, comments, aid, user_id, content_type) VALUES (‘$in’, ‘$an’, ‘$contents’, NOW(), ‘$ct’, $lo, $la, ‘$com’, ‘$location’, $row[user_id], ‘$MIMEtype’)”;
$result = mysql_query ($query) or trigger_error(“Query: $queryn<br />MySQL Error: ” . mysql_error());
if (mysql_affected_rows() == 1) {
echo ‘<P>Well done! Your image has been successfully uploaded !</p>’;
[/CODE]

I fear the problem is in the INSERT INTO where I’ve used ‘$location’, what should this be changed to?

Any ideas would be very much appreciated.

Thanks!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@rincewind456Dec 01.2005 — Check you values statement some have single quotes some don't also $row[user_id] should be $row['user_id']
×

Success!

Help @invision 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.29,
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,
)...