提交时刷新表现得很奇怪

时间:2015-05-14 15:40:24

标签: php mysql forms submit

我希望下面的代码会在我按下任何一个CALLED或EMAILED按钮时刷新页面,但它似乎没有这样做。我单击按钮,页面不刷新,但是当我按F5时,更改显示到相关字段。

任何人都可以提供一些关于为什么它不令人耳目一新的想法?每次单击提交按钮时,我都需要强制刷新整个页面。我也对JS解决方案持开放态度,但古怪的行为使得很难弄清楚发生了什么。谢谢你的帮助!

    <html>
<head>
<title>Call Log System</title>

<style type="text/css">

@-webkit-keyframes invalid {
  from { background-color: red; }
  to { background-color: inherit; }
}
@-moz-keyframes invalid {
  from { background-color: red; }
  to { background-color: inherit; }
}
@-o-keyframes invalid {
  from { background-color: red; }
  to { background-color: inherit; }
}
@keyframes invalid {
  from { background-color: red; }
  to { background-color: inherit; }
}
.invalid {
  -webkit-animation: invalid 3s infinite; /* Safari 4+ */
  -moz-animation:    invalid 3s infinite; /* Fx 5+ */
  -o-animation:      invalid 3s infinite; /* Opera 12+ */
  animation:         invalid 3s infinite; /* IE 10+ */
}
</style>




<script language="JavaScript" type="text/javascript">
function checkDelete(){
    return confirm('Are you sure you want to delete this record?');
}
</script>

<script language="JavaScript" type="text/javascript">
function checkArchive(){
    return confirm('Are you sure you want to archive this record?');
}
</script>


</head>

<body>


<?php
$db_host = 'localhost';
$db_user = '********';
$db_pwd = '******';
$database = '********';
$table = 'Project_Submissions';


if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");
if (!mysql_select_db($database))
    die("Can't select database");

//Display all fields
$result = mysql_query("SELECT * FROM {$table} WHERE Archived is null or Archived='' ORDER BY ID DESC");

if (!$result) 
{
    die("Query to show fields from table failed");
}

echo "<a href=\"archives.php\">Go to Archives</a>";
//Main Table 
echo "<table border='1px' width='100%'>
<tr>
<th style='font-size:18px;width:20px;'>ID</th>
<th style='font-size:18px;'>Customer Name</th>
<th style='font-size:18px;'>Phone #</th>
<th style='font-size:18px;'>Address</th>
<th style='font-size:18px;'>Time Zone</th>
<th style='font-size:18px;'>E-mail</th>
<th style='font-size:18px;'>Alt Phone</th>
<th style='font-size:18px;'>Vehicle</th>
<th style='font-size:18px;'>Project Start</th>
<th style='font-size:18px;'>Project Description</th>
<th style='font-size:18px;'>RDM</th>
<th style='font-size:18px;'>Phone Call #1</th>
<th style='font-size:18px;'>Phone Call #2</th>
<th style='font-size:18px;'>Phone Call #3</th>
<th style='font-size:18px;'>Email Sent</th>
<th style='font-size:18px;'>Notes</th>
<th style='font-size:18px;'>Received Date</th>
<th style='font-size:18px;'>Functions</th>
</tr>";


while ($row = mysql_fetch_array($result)) 
{
    $mydate = $row['Received_Date'];
    $receiveddate = strtotime($mydate);
    $onemonthago = strtotime('-1 month');
    $twomonthago = strtotime('-2 month');
    $threemonthago = strtotime('-3 month');

    if($receiveddate > $onemonthago)//Less than 30 days old
    {
        echo "<tr bgcolor=\"#74ED45\">";//Green
    }

    else if(($receiveddate > $twomonthago) && ($receiveddate < $onemonthago))//30-60 days old
    {
        echo "<tr bgcolor=\"#EDED45\">";//Yellow
    }
    else if(($receiveddate > $threemonthago) && ($receiveddate < $twomonthago))//60-90 days old
    {
        echo "<tr bgcolor=\"#D65151\">";//Red
    }
    else if($receiveddate < $threemonthago)//More than 90 days old
    {
        //echo "<tr bgcolor=\"#2C32DB\">";//Blue
        echo "<tr class=\"invalid\">";//Flashing Red
    }

    else 
    {
        echo "<tr>";
    }

    echo "
    <td style='font-size:12px;'><center>{$row['ID']}</center></td>
    <td style='font-size:12px;'>{$row['First_Name']} {$row['Last_Name']}</td>
    <td style='font-size:12px;'><center><a href=\"tel:{$row['Phone']}\">{$row['Phone']}</a></center></td>
    <td style='font-size:12px;'><center>{$row['Street']} {$row['City']} {$row['State_Country']}</center></td>
    <td style='font-size:12px;'><center><div style=\"width:150px\">{$row['Time_Zone']}</div></center></td>
    <td style='font-size:12px;'><center><a href=\"mailto:{$row['Email']}?Subject=************\" target=\"_top\">{$row['Email']}</a></center></td>
    <td style='font-size:12px;'><center>{$row['Alt_Phone']}</center></td>
    <td style='font-size:12px;'><center>{$row['Year']} {$row['Make']} {$row['Model']}</center></td>
    <td style='font-size:12px;'><center>{$row['Project_Start']}</center></td>
    <td style='font-size:12px;width:300px;'><div style=\"overflow-x:auto; max-height:100px\">{$row['Project_Description']}</div></td>
    <td style='font-size:12px;'><center>{$row['Restoration_Decision_Matrix']}</center></td>
    <td style='font-size:12px;'><center>";

    //------------------------------------
    if(empty($row['CallAttemptOne']))
    {
    echo" 
        <form action='".$_SERVER['PHP_SELF']."' method='post'>
        <input type='hidden' id='ID' name='ID' value='{$row['ID']}' />
        <input type='submit' name='formCalledOne' id='formCalledOne' value='Called' />
        </form>
        {$row['CallAttemptOne']}";
    }
    else
    {
    echo "{$row['CallAttemptOne']}";
    }


    echo "</center></td><td style='font-size:12px;'><center>";

    //------------------------------------
    if(empty($row['CallAttemptTwo']))
    {
    echo" 
        <form action='".$_SERVER['PHP_SELF']."' method='post'>
        <input type='hidden' id='ID' name='ID' value='{$row['ID']}' />
        <input type='submit' name='formCalledTwo' id='formCalledTwo' value='Called' />
        </form>
        {$row['CallAttemptTwo']}";
    }
    else
    {
    echo "{$row['CallAttemptTwo']}";
    }


    echo "</center></td><td style='font-size:12px;'><center>";

    //------------------------------------
    if(empty($row['CallAttemptThree']))
    {
    echo" 
        <form action='".$_SERVER['PHP_SELF']."' method='post'>
        <input type='hidden' id='ID' name='ID' value='{$row['ID']}' />
        <input type='submit' name='formCalledThree' id='formCalledThree' value='Called' />
        </form>
        {$row['CallAttemptThree']}";
    }
    else
    {
    echo "{$row['CallAttemptThree']}";
    }


    echo "</center></td><td style='font-size:12px;'><center>";

    //------------------------------------
    if(empty($row['EmailAttempt']))
    {
    echo" 
        <form action='".$_SERVER['PHP_SELF']."' method='post'>
        <input type='hidden' id='ID' name='ID' value='{$row['ID']}' />
        <input type='submit' name='formEmailAttempt' id='formEmailAttempt' value='Emailed' />
        </form>
        {$row['EmailAttempt']}";
    }
    else
    {
    echo "{$row['EmailAttempt']}";
    }


    echo "</center></td>
    <td style='font-size:12px;width:300px;'><center>Text Area</center></td>
    <td style='font-size:12px;'><center>{$row['Received_Date']}</center></td>
    <td style='font-size:12px;'><center>

        <form action='".$_SERVER['PHP_SELF']."' method='post' onclick=\"return checkDelete()\">
        <input type='hidden' id='ID' name='ID' value='{$row['ID']}' />
        <input type='submit' name='formDelete' id='formDelete' value='Delete' />
        </form>

        <form action='".$_SERVER['PHP_SELF']."' method='post' onclick=\"return checkArchive()\">
        <input type='hidden' id='ID' name='ID' value='{$row['ID']}' />
        <input type='submit' name='formArchive' id='formArchive' value='Archive' />
        </form>


    </center></td>
    </tr>";



    //Check to see if delete button is pressed
    if(isset($_POST['formDelete']))
    {
        if(isset($_POST['ID']) && !empty($_POST['ID']))
        {
            $deleteID = $_POST['ID'];
            $result = mysql_query("DELETE FROM Project_Submissions WHERE ID ='".$deleteID."'");
        }
    }   

    //Check to see if archive button is pressed
    if(isset($_POST['formArchive']))
    {
        if(isset($_POST['ID']) && !empty($_POST['ID']))
        {
            $archiveID = $_POST['ID'];
            $result = mysql_query("UPDATE Project_Submissions SET Archived ='1' WHERE ID ='".$archiveID."'");
        }
    }   

    if(isset($_POST['formCalledOne']))//Check to see if Call Attempt One button is pressed
    {
        //if(isset($_POST['ID']) && !empty($_POST['ID']))
        //{
            $callattemptoneID = $_POST['ID'];
            $callattemptonequery = mysql_query("UPDATE Project_Submissions SET CallAttemptOne=CURDATE() WHERE ID ='".$callattemptoneID."' AND (CallAttemptOne IS NULL OR LENGTH(CallAttemptOne)=0)");
        //}
    }   

    if(isset($_POST['formCalledTwo']))//Check to see if Call Attempt Two button is pressed
    {
        //if(isset($_POST['ID']) && !empty($_POST['ID']))
        //{
            $callattempttwoID = $_POST['ID'];
            $callattempttwoquery = mysql_query("UPDATE Project_Submissions SET CallAttemptTwo=CURDATE() WHERE ID ='".$callattempttwoID."' AND (CallAttemptTwo IS NULL OR LENGTH(CallAttemptTwo)=0)");
        //}
    }   

    if(isset($_POST['formCalledThree']))//Check to see if Call Attempt Three button is pressed
    {
        if(isset($_POST['ID']) && !empty($_POST['ID']))
        {
            $callattemptthreeID = $_POST['ID'];
            $callattemptthreequery = mysql_query("UPDATE Project_Submissions SET CallAttemptThree=CURDATE() WHERE ID ='".$callattemptthreeID."' AND (CallAttemptThree IS NULL OR LENGTH(CallAttemptThree)=0)");
        }
    }   

    if(isset($_POST['formEmailAttempt']))//Check to see if Email Attempt button is pressed
    {
        if(isset($_POST['ID']) && !empty($_POST['ID']))
        {
            $emailattemptID = $_POST['ID'];
            $emailattemptquery = mysql_query("UPDATE Project_Submissions SET EmailAttempt=CURDATE() WHERE ID ='".$emailattemptID."' AND (EmailAttempt IS NULL OR LENGTH(EmailAttempt)=0)");

        }
    }   
}
?>
</body>
</html>

This is what the screen looks like

1 个答案:

答案 0 :(得分:0)

如果我理解你的问题,我认为这应该有所帮助。

<?php

$value = "string";


if (isset($_POST['ID']))
{
    echo $emailattemptID = $_POST['ID'];
}



echo" 
<form action='".$_SERVER['PHP_SELF']."' method='post'>
<input type='hidden' id='ID' name='ID' value='$value' />
<input type='submit' name='formEmailAttempt' id='formEmailAttempt' value='Emailed' />
</form>
";

?>