duangan1945 2015-12-11 10:01
浏览 38
已采纳

PHP表单提交信息两次

I have a perfectly working PHP form and until the other day it only submitted the results once to the database. I have not changed the code and suddenly it is submitting all results twice for an unknown reason. I've google it and can't find the issue. Here is my code:

<?php
$jinput = JFactory::getApplication()->input;
if(isset($_POST['submit'])) {
    $db = JFactory::getDbo();
    $query = $db->getQuery(true);
    $user = JFactory::getUser();
    $userID = $user->get( 'id' );
    $date = date("Y/m/d");
    $description = $jinput->get('description', null , null);
    $subsection = $jinput->get('subsection', null , null);
    $urgency = $jinput->get('urgency', null , null);
    $status = "Waiting Attention";
    $columns = array('userid', 'rdate', 'description', 'area', 'subsection', 'urgency', 'status');
    $values = array($userID, $db->quote($date), $db->quote($description), $db->quote($selected), $db->quote($subsection), $db->quote($urgency), $db->quote($status));
    $query
        ->insert($db->quoteName('#__website_issues'))
        ->columns($db->quoteName($columns))
        ->values(implode(',', $values));
    $db->setQuery($query);
    $db->execute();
    echo "<h4>Thank You! Issue Successfully Reported!";
}
echo "<table style='text-align:center;text-align:center;margin-left:41%;'>";
echo "<tr><td><h4>Report Website Issue</h4></td></tr>";
echo "<tr><td><form method='post'><select name='area'  onchange='this.form.submit()'>
<option value=''>Select Website Area</option>
<option value='General'>General</option>
<option value='Emails'>Emails</option>
<option value='Education'>Education</option>
<option value='Reviews'>Reviews</option>
<option value='Store'>Store</option>
<option value='Toolkit'>Toolkit</option>
<option value='Membership'>Membership</option>
<option value='Other'>Other</option>
</select></form>
</td></tr>";
echo "<form method='post'>";
$selected = $jinput->get('area', null, null);
echo "<tr><td><h5><center>Current Area Selected: $selected</center></tr></td></h5>";
if($selected == 'General') {
    echo "<tr><td><input type='text' name='subsection' placeholder='Subsection'></td></tr> ";
}
else if($selected == 'Emails') {
    echo "<tr><td><select name='subsection'>
    <option value=''>Select Email System</option>
    <option value='Contact Error'>Contact Emails</option>
    <option value='Notification'>Notifications</option>
    <option value='Newsletter'>Newsletter</option>
    <option value='Store'>Store Emails</option>
    </select></td></tr>";
}
else if($selected == 'Education') {
    echo "<tr><td><select name='subsection'>
    <option value=''>Select Subsection</option>
    <option value='Lighting'>Lighting</option>
    <option value='Sound'>Sound</option>
    <option value='Rigging'>Rigging</option>
    <option value='Stage Management'>Stage Management</option>
    <option value='Console Training'>Console Training</option>
    <option value='Video'>Video</option>
    <option value='Media & Projection'>Media & Projection</option>
    <option value='Church'>Church</option>
    </select></td></tr>";
}
else if($selected == 'Reviews') {
    echo "<tr><td><input type='text' name='subsection' placeholder='Specific Review'></td></tr> ";
}
else if($selected == 'Store') {
    echo "<tr><td><input type='text' name='subsection' placeholder='Store Area'></td></tr> ";
}
else if($selected == 'Toolkit') {
    echo "<tr><td><input type='text' name='subsection' placeholder='Specific Tool'></td></tr> ";
}
else if($selected == 'Membership') {
    echo "<tr><td><select name='subsection'>
    <option value=''>Select Membership Plan</option>
    <option value='Member'>Member</option>
    <option value='Student'>Student</option>
    <option value='Educator'>Educator</option>
    </select></td></tr>";
}
else if($selected == 'Other') {
    echo "<tr><td><input type='text' name='subsection' placeholder='Subsection'></td></tr> ";
}
echo "<tr><td><select name='urgency'>
<option value=''>Select Urgency</option>
<option value='Minor'>Minor</option>
<option value='Serious'>Serious</option>
<option value='Urgent'>Urgent</option>
</select></td></tr>";
echo "<tr><td><textarea rows='6' cols='50' name='description' placeholder='Please Describe The Issue'></textarea></td></tr>";
// Submit
echo "<tr><td><input type='submit' class='btnsubmit' name='submit' value='Submit Issue'>";
echo "</form></table><hr>";
?>
</body>

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • donglun1918 2015-12-11 10:10
    关注

    Maybe you should redirect the user after inserting data, this way a page refresh would avoid inserting data again :

    <?php
    ...
    $db->setQuery($query);
    $db->execute();
    header('Location: '.$_SERVER['PHP_SELF']);
    exit();
    

    An other point is that you could disable form submission after first submission in js.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化