开发者

Insert Comma Separated Values into MYSQL + Additional Form Data

开发者 https://www.devze.com 2023-04-05 22:01 出处:网络
I have a form that allows users to tag an image, choose a location from a drop-down, & upload the image. The tagging takes place by allowing multiple values, separated by commas, to be entered int

I have a form that allows users to tag an image, choose a location from a drop-down, & upload the image. The tagging takes place by allowing multiple values, separated by commas, to be entered into a field.

This code is successfully inputting the comma delimited list to individual rows:

    $categories = $_POST['bib'];
    $categories = explo开发者_JAVA技巧de(",", $categories);
    foreach($categories as $category) {
    $category = trim($category); // Remove possible whitespace
    $sql = "INSERT INTO athletes (bib) VALUES ('%s')";
    $sql = sprintf($sql, mysql_real_escape_string($category));
    mysql_query($sql);
    }

However, it is not adding the additional content (location from drop-down list & image filename). For query purposes I need to be able to use both the 'bib' tag and the 'location' to be attached to images to allow users to search.

Before implementing the comma-separated option, this code was working to insert all of the data:

 mysql_query("INSERT INTO `athletes` VALUES ('$id', '$bib', '$race','$new_file_name')") ;

So, basically I'm trying to merge the functionality of the two.


You need to use MySQL's UPDATE statement to update data in an existing row.

0

精彩评论

暂无评论...
验证码 换一张
取 消