gpt4 book ai didi

php - 无法让 PHP 将信息发布到数据库

转载 作者:行者123 更新时间:2023-11-29 13:57:41 25 4
gpt4 key购买 nike

我编写了一个脚本来将信息发布到我的数据库中,因为我无法将其发布,并且需要帮助指出我缺少的内容。

我的 php 帖子看起来像这样:

$query = "SELECT * from departments";
$res = mysql_query($query);
echo '<div id="department" >';
echo '<form action="depedit.php" method="post">';
echo '<input type="text" placeholder="Search departments">';
echo '<br>';
echo '</form>';
echo '</div>';
echo '<div id="depadd">';
echo '<form>';
echo '<table width="0" border="0">';
echo '<tr>';
echo '<td>Name:</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo "<select name='depid'>";
while ($row = mysql_fetch_array($res)) {
echo "<option value='".$row['id']."'>".$row['depname']."</option>";
}
echo "</select>";
echo '</td>';
echo ' </tr>';
echo '<tr>';
echo '<td>&nbsp;</td>';
echo '</tr>';
echo ' <tr>';
echo '<td><label class="limit">Select Limit for active courses in Learning Locker:</label></td>';
echo ' </tr>';
echo ' <tr>';
echo '<td>';
echo "<select name='courselimit'>";
echo "<option value='1'>1</option>";
echo "<option value='2'>2</option>";
echo "<option value='3'>3</option>";
echo "<option value='4'>4</option>";
echo "<option value='5'>5</option>";
echo "<option value='0'>Unlimited</option>";
echo "</select>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>&nbsp;</td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="radio" id="1" name="senabled" value="1"/><label for="c1" class="required">Required<br>(Study Shredder Feature Enabled)</br></label></td>';
echo '<td><input type="radio" id="0" name="senabled" value="0"/><label for="c1" class="optional">Optional</label></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="hidden" name="orgid" value="'.$adminorgid.'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="hidden" name="createdby" value="'.$userid.'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="hidden" name="timecreated" value="'.time(now).'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td>&nbsp;</td>';
echo '</tr>';
echo ' <tr>';
echo ' <td><button type="submit" class="btn">Submit</button></td>';
echo ' </tr>';
echo '</table>';
echo "</form>";
echo '</div>';

depedit.php 看起来像这样:

 $adddep = "INSERT INTO organization_dep (orgid,depid,courselimit,senabled,createdby,timecreated) VALUES ('".$_POST["orgid"].",".$_POST["depid"].",".$_POST["courselimit"].",".$_POST["senabled"].",".$_POST["createdby"].",".$_POST["timecreated"]."')";
$res = mysql_query($adddep);

if ($res === TRUE) {
echo "Department added successfully";
} else{
printf("Could not create department");
}

正确的信息似乎已被传递,因为网址中显示以下信息:

/index.php?depid=6&courselimit=3&senabled=1&orgid=9&createdby=1129&timecreated=1364005206

对此的任何帮助将不胜感激,因为我确信这很简单,我只是忽略了。

最佳答案

您想要从 $_POST 获取值

('".$_POST["orgid"].",".$_POST["depid"].",".$_POST["courselimit"].",".$_POST["senabled"].",".$_POST["createdby"].",".$_POST["timecreated"]."')";

但是你说它是通过 URL 传递的,这看起来你需要使用 $_GET 来获取值

--- 还有一个小提示,您可以使用 echo 打印多行,它可以工作。只要你关闭它,最后

例如

echo " <html>
<body>
</body>
</html>
";

关于php - 无法让 PHP 将信息发布到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15582718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com