2014-02-14 81 views
-3

我創建了一個社交網站,到目前爲止一切都很好用於登錄和註銷等......但是當涉及到編輯配置文件頁面時,我無法弄清楚我的錯誤,有人可以提出什麼建議錯誤還是有更好的方法來處理此更新配置文件頁面。用PHP更新用戶配置文件頁面MySQL

我得到的錯誤是:

Parse error: syntax error, unexpected '$firstname' (T_VARIABLE) in C:\wamp\www\change.php on line 28

我的PHP代碼:

<?php 
session_start(); 
if (isset($_SESSION['username'])) { 
$username = $_SESSION['username']; 
} 
else { 
echo "You have not signed in"; 
} 
?> 
<?php 
include_once ("php_includes/db_conx.php");  
$sql = "SELECT * FROM users WHERE username='$u' AND activated='1' LIMIT 1"; 
$user_query = mysqli_query($db_conx, $sql); 
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) { 
$username = $row["surname"]; 
$firstname = $row["firstname"]; 
$surname = $row["surname"]; 
$weight = $row["weight"]; 
$height = $row["height"]; 
} 

function filter($date) 
{ 
    return trim(htmlspecialchars($date)); 
} 

$username = filter($_POST['username']) 
$firstname = filter($_POST['firstname']) 
$surname = filter($_POST['surname']) 
$weight = filter($_POST['weight']) 
$height = filter($_POST['height']) 

if (username) 
{ 

$sql = mysql_query ("UPDATE users SET username='$username', firstname='$firstname', surname='$surname', weight='$weight', height='$height' WHERE username='$username'") 
or die (mysql_error()); 
} 
?> 


<form action="change.php" method="post"> 
    Username: <input type="text" name="username"><br /> 
    Firstname: <input type="text" name="firstname"><br /> 
    Surname: <input type="text" name="surname"><br /> 
    weight: <input type="text" name="weight"><br /> 
    height: <input type="text" name="height"><br /> 
    <input type="submit" value="Submit"> 
</form> 
+1

你的錯誤是什麼? – Jori

+0

不應該'username ='$ u''是'username ='$ username''? – Prix

+0

錯誤是解析錯誤:語法錯誤,意外的'$ firstname'(T_VARIABLE)在C:\ wamp \ www \ change.php在第28行 – user3311898

回答

2
$username = filter($_POST['username']); 
$firstname = filter($_POST['firstname']); 
$surname = filter($_POST['surname']); 
$weight = filter($_POST['weight']); 
$height = filter($_POST['height']); 

您需要終止每個語句/符合;

-1

您需要終止每行代碼用分號分隔。第27行(和接下來的四行)缺少分號。

0
$sql = mysql_query ("UPDATE users SET weight='$weight', height='$height' WHERE username='$username'") 

i think you have to create like this 


$sql = mysql_query ('UPDATE users SET username ="'.$username.'" WHERE username="'.$username.'"'); 

$sql = mysql_query ('UPDATE users SET firstname="'.$firstname.'" WHERE username = "'.$username.'"'); 

$sql = mysql_query ('UPDATE users SET surname="'.$surname.'" WHERE username = "'.$username.'"'); 

$sql = mysql_query ('UPDATE users SET weight='".$weight."' WHERE username = "'.$username.'"'); 





$sql = mysql_query ('UPDATE users SET height="'.$height.'" WHERE username="'.$username'"'); 

粘貼此代碼。

相關問題