I have a form that allows uploads of images. The user can select which gallery to upload the image to based on a radio button.
In the upload php script, the images are uploaded to a directory then then directory location is added to a MYSQL database. The upload and directory addition works fine.
I’m trying to add the name of the radio button that was pressed to another column in the image database so that I can see which image was uploaded to which gallery as my images are in a separate table.
My form looks like
<form enctype="multipart/form-data" action="upload-image.php" method="POST">
<h3>Select Gallery To Upload To</h3>
<?php
$results = mysql_query("SELECT * FROM users");
while ($row = mysql_fetch_assoc($results))
{
echo'<br>';
echo '<input type="radio" name="'. $row["username"].'"value="'.$row["username"].'">' . $row["username"];
}
?>
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
The section of the upload script that handles the adding to the MYSQL database is as follows:
mysql_query("INSERT INTO images (image, gallery_name) VALUES('".$target_path, $_POST["$row["name"]"]."')")
This is giving me a few errors:
Notice: Undefined index: name
Warning: mysql_query() expects parameter 2 to be resource, string given
How might I fix this?
Your query’s double quotes are a bit awry. You also need to feed
mysql_querya resource created bymysql_connect(in the following example, it’s represented by$mysql).