2015-05-14 5 views
0

Я бы ожидал, что приведенный ниже код заставит страницу обновляться, когда я нажимаю любую из кнопок CALLED или EMAILED, но, похоже, это не так. Я нажимаю кнопку, и страница не обновляется, но когда я нажимаю F5, изменение отображается в соответствующем поле.Обновить на submit behancy weirdly

Может кто-нибудь предложить некоторые мысли о том, почему это не освежает? Мне нужно заставить всю страницу обновляться всякий раз, когда нажимается кнопка отправки. Я также открыт для решений 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

+0

Просто FYI, LENGTH (EmailAttempt) = 0 вызовет полное сканирование таблицы, вместо того, чтобы использовать EmailAttempt = '' –

+0

Есть ли у вас какие-либо Javascript с 'onsubmit' обработчик, который переопределяет нормальное поведение? – Barmar

+0

Если у вас нет Javascript, сообщение формы должно всегда обновляться. – Barmar

ответ

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> 
"; 

?> 
+0

Хмм ?? Я не уверен, что имеет смысл, вы можете уточнить? – new2programming

+0

вам просто нужно изменить переменные с помощью вашего –

+0

Это форма, которую вы можете использовать, и isset там, чтобы проверить, есть ли у вас то, что вы хотите в переменной. –

Смежные вопросы