我正在尝试从HTML select标签向MySQL插入一个值:
<select name="venuesend">
<option value="37">LATINO SPORTS CLUB</option>
<option value="38">RED HOOK VISION CENTER</option>
<option value="39">ANTHOLOGY FILM ARCHIVES</option>
<option value="40">HUMMINGBIRD STUDIOS</option>
<option value="41">THE PRODUCERS CLUB</option>
</select>
因此,如果选择LATINO SPORTS CLUB
,则应将37
的值发送给MySQL。但是,目前发布到MySQL的值始终为3
。所以,我猜这是因为某种原因被截断了。
这是我的PHP和HTML表单:
<?php
//if "submit" is clicked
if(isset($_POST['upload2'])) {
//check if image files were uploaded
foreach($_FILES['images']['error'] as $err){
switch ($err){
case UPLOAD_ERR_NO_FILE:
echo 'No file sent.';
exit;
}
}
//iterate through each image file uploaded
for($x=0; $x<count($_FILES['images']['tmp_name']); $x++){
//THIS IS WHERE VENUESEND IS POSTED
$screeningID2 = $_POST['venuesend'][$x];
$file_name = $_FILES['images']['name'][$x];
$file_tmp = $_FILES['images']['tmp_name'][$x];
....
//SQL statement and Posting
$sql2 = "INSERT INTO screeningImages (screeningId, imageURL) VALUES ('$screeningID2', '$file_name')";
mysqli_query($db, $sql2);
} else{
echo "Only images can be stored.";
}
}
}
?>
//HTML Form
<form method="post" action="screenings-admin.php" enctype="multipart/form-data">
//SELECT
<select name="venuesend">
<option value="37">LATINO SPORTS CLUB</option>
<option value="38">RED HOOK VISION CENTER</option>
<option value="39">ANTHOLOGY FILM ARCHIVES</option>
<option value="40">HUMMINGBIRD STUDIOS</option>
<option value="41">THE PRODUCERS CLUB</option>
</select>
//Images Upload
<input type="file" id="imageUpload" name="images[]" multiple="" onchange="javascript:updateList()"/>
//submit button
<input type="submit" name="upload2" value="Upload" id="upload2">
</form>
答案 0 :(得分:1)
问题是您正在尝试访问字符串数组($screeningID2 = $_POST['venuesend'][$x];
),因为您正在调用<select>
。
$_POST[id]
POST通过$x
传递选定的值;实际上你根本不需要引用$screeningID2 = $_POST['venuesend'];
,只需要:
3
您收到$_POST['venuesend']
因为37
已经是字符串{
user_id : "user id",
list_devices_token : [....];
}
,您实际上是在接受字符串的第一个字符。< / p>
希望这有帮助! :)
答案 1 :(得分:0)
代码的某些部分不清楚,但这应该从它的外观来解决问题。
$screeningID2 = $_POST['venuesend'][$x]
到
$screeningID2 = $_POST['venuesend];
最后使用[$x]
,您试图存储/读取存储在变量中的整个字符串中的字符。尝试使用此代码并更新我们,以便我们查看是否可以修复它。