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?
mysql_*functions! They're in the process of being deprecated.mysql_*functions in new code. They were removed from PHP 7.0.0 in 2015. Instead, use prepared statements via PDO or MySQLi. See Why shouldn't I use mysql_* functions in PHP? for more information.