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>
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>’;
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!