Click to See Complete Forum and Search --> : Insert ID value from dynamic dropdown into SQL table


invision
12-01-2005, 05:39 AM
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 :

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 :

$query = "SELECT user_id FROM users WHERE first_name = '$_SESSION[first_name]'";
$result = mysql_query($query) or trigger_error("Query: $query\n<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: $query\n<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!

rincewind456
12-01-2005, 09:26 AM
Check you values statement some have single quotes some don't also $row[user_id] should be $row['user_id']