2012-02-08 7 views
-1

Я смотрю на эту страницу больше часа. Моя функция обновления просто не обновляется. Когда я пробовал его через sql, все выглядит нормально. У меня есть форма внизу этой страницы, которая обновляет поле в таблице. Кто-нибудь может заметить ошибки?Что я здесь делаю неправильно?

<?php 

// First of all initialise the user and check for permissions 
require_once "/var/www/users/user.php"; 
$user = new CHUser(2); 


// Initialise the template 
require_once "/var/www/template/template.php"; 
$template = new CHTemplate(); 

// And create a cid object 
    require_once "/var/www/Testing/DisplayWIPOnLocation.php"; 
$BundleProgress= new CHWIPProgress(); 


if(isset($_GET['Reference'])){ 

$todays_date = date("Y-m-d H:i:s"); 
$content .= " <h3> Details for Bundle : $reference </h3> "; 
$bundle = $BundleProgress->GetBundle($_GET['Reference']); 
$reference = $_GET['Reference']; 

// Now show the details 

    foreach($bundle as $x){ 
     $content .= " 
     <table> 
            <tr> 
        <th> Location </th> 
        <td>" . $x['Description'] . "</td> 
        </tr> 



        <tr> 
        <th> Works Order Number </th> 
        <td>" . $x['WorksOrder'] . "</td> 
        </tr> 


        <tr> 
        <th> Bundle Number </th> 
          <td>" . $x['Number'] . "</td> 
        </tr> 


        <tr> 
        <th>Qty Issued</th> 
        <td>" . $x['Qty'] . "</td> 

        </tr> 


        <tr> 
        <th>Bundle Reference </th> 
        <td>" . $x['Reference'] . "</td> 

        </tr> 

        <tr> 
        <th>Style description</th> 
              <td>" . $x['Stock'] . "</td> 

        </tr> 

        <tr> 
          <th>Due Date</th> 
        <td>" . $x['DueDate'] . "</td> 

        </tr> 


        <tr> 
        <th>Date In </th> 
        <td>" . $x['DateIN'] . "</td> 

        </tr> 

        <tr> 
        <th>Date Out</th> 
        <td>" . $x['DateOUT'] . "</td> 

        </tr> 

        <tr> 
        <th>Last Code</th> 
        <td>" . $x['Last'] . "</td> 

        </tr> 

       </table> 

       <br> "; 

    } 

       $content .= " </table> 
       <form action='viewBundle.php?step=2' method='post'> 
       <p>Reason: <input type='text' name='reason' /><br  
            /><p> 
       <p><input type='hidden' name='bundlereference' 
            id='Username' value='" . $x['Reference'] . "' /> 
       <input type='submit' name ='add'/></form> 

       </table> "; 

       if($_GET['step'] == 2) { 



     $BundleProgress->UpdateReason($_POST['reason'],$_POST['bundlereference']); 

       $content .= " <a href='index.php?location=" . 
       $x['Description'] . "'> updated</a> "; 
       } 

     } 


    else { 
    $content .= "<h3>Something has gone wrong</h3> 

    <br> 

    <a href='index.php?location=" . $x['Description'] . "'> Return to Previous    
    Page </a> 

    "; 
} 

    $template->SetTag("content", $content); 
    echo $template->Display(); 

    ?> 

Функция

public function UpdateReason($reason, $bundlereference) { 
        $sql = "UPDATE `ArchiveBundle` 
            SET `Issue` = " . $reason . " 
            WHERE `BundleReference` = " . $bundlereference .  
       ";"; 
        mysql_select_db(DB_DATABASE_NAME, $this->conn); 
        return mysql_query($sql, $this->conn); 
      } 
+0

«Что я здесь делаю неправильно?» «Не дезинфицировать пользователей и доверяющих клиентов» –

+0

И не проверить обратные вызовы функций вашей базы данных, поэтому даже вы не можете знать, что происходит не так ... – Mat

+0

Помещение '

...
' между ' ... '!! – Toto

ответ

4

изменение:

if($_GET['step'] == 2) 

к:

if((int)$_GET['step'] === 2) 

и:

public function UpdateReason($reason, $bundlereference) { 
    $sql = "UPDATE `ArchiveBundle` 
     SET `Issue` = " . $reason . " 
     WHERE `BundleReference` = " . $bundlereference .  
     ";"; 
    mysql_select_db(DB_DATABASE_NAME, $this->conn); 
    return mysql_query($sql, $this->conn); 
} 

к:

public function UpdateReason($reason, $bundlereference) { 
    mysql_select_db(DB_DATABASE_NAME, $this->conn); 

    $_reason = mysql_real_escape_string($reason,$this->conn); 
    $_bundlereference = mysql_real_escape_string($bundlereference,$this->conn); 

    $sql = "UPDATE `ArchiveBundle` 
      SET `Issue` = '" . $_reason . "' 
      WHERE `BundleReference` = '" . $_bundlereference . "'"; 

    return mysql_query($sql, $this->conn); 
} 

Попробуйте-й в. Код не был протестирован, но это хорошее место для начала.

Чтобы попробовать и отлаживать, что происходит здесь, сделайте следующее:

public function UpdateReason($reason, $bundlereference) { 
    error_reporting(E_ALL^E_NOTICE); 

    $db_selected = mysql_select_db(DB_DATABASE_NAME, $this->conn); 

    if (!$db_selected) { 
     die("Can't use db : " . mysql_error()); 
    } 

    $_reason = mysql_real_escape_string($reason,$this->conn); 
    $_bundlereference = mysql_real_escape_string($bundlereference,$this->conn); 

    $sql = "UPDATE `ArchiveBundle` 
      SET `Issue` = '" . $_reason . "' 
      WHERE `BundleReference` = '" . $_bundlereference . "'"; 

    mysql_query($sql, $this->conn); 

    die(mysql_error()); 
} 

Кроме того, это выглядит как на вашем представлении формы вы не передаете в справочном параметра так что если (Исеть ($ _ GET [ «Ссылка»])) не удастся при отправке формы. Я изменил приведенный ниже код таблицы и формы, чтобы сделать его более читабельным, передать в параметре Reference параметр отправки формы, а также обновить запись db ПЕРЕД НАЗНАЧЕНИЕМ набора данных, чтобы вы увидели обновленные записи в возвращенной таблице.

// First of all initialise the user and check for permissions 
require_once "/var/www/users/user.php"; 
$user = new CHUser(2); 


// Initialise the template 
require_once "/var/www/template/template.php"; 
$template = new CHTemplate(); 

// And create a cid object 
require_once "/var/www/Testing/DisplayWIPOnLocation.php"; 
$BundleProgress= new CHWIPProgress(); 


if(isset($_GET['Reference'])){ 
    if($_GET['step'] == 2) { 
     $BundleProgress->UpdateReason($_POST['reason'],$_POST['bundlereference']); 
    } 

    $todays_date = date("Y-m-d H:i:s"); 
    $content .= " <h3> Details for Bundle : $reference </h3> "; 
    $bundle = $BundleProgress->GetBundle($_GET['Reference']); 
    $reference = $_GET['Reference']; 

    // Now show the details 
    foreach($bundle as $x){ 
     $content .= " 
        <table> 
         <tr><th> Location </th><td>" . $x['Description'] . "</td></tr> 
         <tr><th> Works Order Number </th><td>" . $x['WorksOrder'] . "</td></tr> 
         <tr><th> Bundle Number </th><td>" . $x['Number'] . "</td></tr> 
         <tr><th>Qty Issued</th><td>" . $x['Qty'] . "</td></tr> 
         <tr><th>Bundle Reference </th><td>" . $x['Reference'] . "</td></tr> 
         <tr><th>Style description</th><td>" . $x['Stock'] . "</td></tr> 
         <tr><th>Due Date</th><td>" . $x['DueDate'] . "</td></tr> 
         <tr><th>Date In </th><td>" . $x['DateIN'] . "</td></tr> 
         <tr><th>Date Out</th><td>" . $x['DateOUT'] . "</td></tr> 
         <tr><th>Last Code</th><td>" . $x['Last'] . "</td></tr> 
        </table> 
        <br>"; 
    } 

    $content .= "<table> 
        <form action='viewBundle.php?Reference=" . $_GET['Reference'] . "&step=2' method='post'> 
         <p>Reason: <input type='text' name='reason' /></p><br/> 
         <p><input type='hidden' name='bundlereference' id='Username' value='" . $x['Reference'] . "' /></p> 
         <input type='submit' name ='add'/> 
        </form> 
       </table>"; 
} else { 
    $content .= "<h3>Something has gone wrong</h3> 
       <br> 
       <a href='index.php?location=" . $x['Description'] . "'> Return to Previous Page </a> 
       "; 
} 

$template->SetTag("content", $content); 
echo $template->Display(); 
+1

Первый не имеет значения, потому что PHP слабо типизирован. –

+0

Правда, но я считаю это хорошей практикой. –

+0

Ive попытался добавить ваши изменения, все еще не работает. Если я повторяю sql и вводим данные вручную, он работает. Так странно. Я довольно новичок в php. спасибо за вашу помощь – user1010756

0

Могу ли я посоветовать вам разбить это вниз по первой проверке, что mysql_query возвращает. Возможно, эта конкретная переменная определена неверно. Также не забудьте добавить кавычки к значениям в вашем запросе.

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