您好我有一个上传文件的简单表单,我想使用$ POST获取id值并放入数据库但我的代码不正确。这是我的代码。我只是想问一下我是否正确地传递和获取$ POST?感谢
echo "<form action='process.php' method='post' enctype='multipart/form-data' id='uploadfile'>";
echo "<input type='hidden' name='MAX_FILE_SIZE' value='100000' />";
echo "<select name='selectedValue'>";
echo '<option selected="selected">' .'Choose a User'. '</option>';
foreach ($registeredUsers as $key => $value) {
$registered = JFactory::getUser($value);
echo '<option name="id" value="'.$registered->id.'">'.$registered->name.'</option>';
}
echo "</select>";
echo "Choose a file to Upload:";
echo "<input name='uploadedfile' type='file' /> <br/>";
echo '<input type="submit" name="submit" value="Upload">';
echo "</form>";
这是process.php文件。
if(isset($_POST['selectedValue']))
{
$selectedValue = $_POST['id'];
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query = "INSERT INTO sample_table ('user_id') VALUES ('$_POST[id]')"
$db->setQuery($query);
$result = $db->execute();
}
答案 0 :(得分:-1)
echo "<form action='process.php' method='post' enctype='multipart/form-data' id='uploadfile'>";
echo "<input type='hidden' name='MAX_FILE_SIZE' value='100000' />";
echo "<select name='id'>";
echo '<option selected="selected">' .'Choose a User'. '</option>';
foreach ($registeredUsers as $key => $value) {
$registered = JFactory::getUser($value);
echo '<option value="'.$registered->id.'">'.$registered->name.'</option>';
}
echo "</select>";
echo "Choose a file to Upload:";
echo "<input name='uploadedfile' type='file' /> <br/>";
echo '<input type="submit" name="submit" value="Upload">';
echo "</form>";
process.php
if(isset($_POST['id']))
{
$selectedValue = $_POST['id'];
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query = "INSERT INTO sample_table ('user_id') VALUES ('$selectedValue')";
$db->setQuery($query);
$result = $db->execute();
}
好。因此,您遇到了一些问题,您已经设置了&#34; name&#34;关于选项,这是错误的,你必须在。上设置 其次,你在$ query的最后错过了一个分号 最后,我已经检查了是否已从下拉列表中选择了一个值,并将selectedValue设置为该值,并在查询中使用该值。