2011-12-19 26 views
0

此功能從用戶獲取日期:發送到DB函數不執行

function getCCGraduationDate() { 
     ?> 
     <form method="post" action="processor.php"> 
     Graduation Date: <input type="text" name="CCgraduationdate"><br> 
     <input type="submit"> 
     <?php 
    } 

該函數將值發送到一個數據庫,被稱爲processor.php頁:

function sendCCGraduationDate() { 
    $con = mysql_connect("localhost","root","XXXXXX"); 
    if (!$con) 
     { 
    die('Could not connect: ' . mysql_error()); 
     } 
     mysql_select_db("user", $con); 
     $grad = mysql_real_escape_string($_POST['CCGraduationDate'], $con); 
     $sql = "UPDATE profile SET CommunityCollegeGraduationDate='$grad' WHERE userid=$this->user_id"; 
     mysql_query($sql , $con); 

     mysql_close($con); 

    } 

由於某些原因該值未填充到數據庫中。我昨天晚上測試了類似的功能,他們工作,不知道我在這裏錯過了什麼。

+0

檢查,如果有任何的錯誤:'回聲mysql_error($ CON)的mysql_query後''權($的SQL,$ CON) ;'。如果有,則應該看到一些錯誤文本 – Kokers 2011-12-19 20:43:31

+0

未送回錯誤。 – buttonitup 2011-12-19 20:49:41

回答

1

請檢查:

FORM CODE:

<input type="text" name="CCgraduationdate"><br> 

PHP代碼:

$grad = mysql_real_escape_string($_POST['CCGraduationDate'], $con); 

CCgraduationdate在你的形式不等於CCGraduationDate在PHP代碼

如果你沒有得到這樣的錯誤:

Notice: Undefined index: CCGraduationDate /* blah blah blah */ 

然後你可以嘗試在你的PHP代碼的頂部添加:

error_reporting(E_ALL); 

然後看看是否有錯誤出來。

當然,這是改變你的$sql變量的數據後:

$sql = "UPDATE profile SET CommunityCollegeGraduationDate='$grad' WHERE userid=" . $this->user_id; 
1

假設有用於$this->user_id實際值:

$sql = "UPDATE profile SET CommunityCollegeGraduationDate='$grad' WHERE userid=$this->user_id"; 

// Should be: 

$sql = "UPDATE profile SET CommunityCollegeGraduationDate='$grad' WHERE userid={$this->user_id}"; 

// Or 

$sql = "UPDATE profile SET CommunityCollegeGraduationDate='$grad' WHERE userid= " . $this->user_id; 

- 編輯 -

$sql = "UPDATE profile SET CommunityCollegeGraduationDate='$grad' WHERE userid= " . $this->user_id; 

if (!mysql_query($sql , $con)) 
    die(mysql_error()); 
} 

- 編輯 -

// To avoid case and extra space issues, sanitize your var first 
$grad = trim(strtolower($grad)); 

// You did well to escape 
$grad = mysql_real_escape_string($grad, $con); 
+0

什麼都沒有...... – buttonitup 2011-12-19 20:41:07

+1

你可以'var_dump($ this-> user_id)'?有價值嗎? – 2011-12-19 20:41:50

+0

它在數據庫中,我也可以在視圖頁面上調用它,而不是使用$ this->。所以我試着把它切換到對象名稱$ profile->,但它仍然無法工作。 – buttonitup 2011-12-19 20:47:47