PHP更新用户帐户的详细信息没有显示错误,但帐户详细信息未更新
概述: 我创建一个虚拟网站用于学习的目的,因此它的功能主义者是基本和安全的不在议程atm。PHP更新用户帐户的详细信息没有显示错误,但帐户详细信息未更新
实际的问题:在谁拥有如果需要编辑他/她的帐户的选项的用户
行,所以我的应用程序包厢。所以我已经提前创建了PHP脚本来处理这个问题,但它不是。当我点击编辑帐户按钮时,没有错误弹出,但同时当我检查MySQL数据库没有发生变化。
EditAccountForm.php文件:
<?php
include('connect_mysql.php');
if(isset($_POST['editAccount'])){
$Newusername = $_GET['username'];
$Newpassword = $_POST['password'];
$Newfirstname = $_POST['first_name'];
$Newlastname = $_POST['last_name'];
$Newemail = $_POST['email'];
if($Newusername != $username)
{
$q1 = ("UPDATE users SET username=$Newusername WHERE username=$username");
}
else if(!mysql_query($q1)){
echo "MySQL ERROR: " . mysql_error() . "" . $sql;
}
///////////////////////////////////////////////////////////////
if($Newpassword != $password)
{
$q2 = ("UPDATE users SET password=$Newpassword WHERE password=$password");
}
else if(!mysql_query($q2)){
echo "MySQL ERROR: " . mysql_error() . "" . $sq2;
}
///////////////////////////////////////////////////////////
if($Newfirstname != $firstname)
{
$q3 = ("UPDATE users SET first_name=$Newfirstname WHERE first_name=$firstname");
}
else if(!mysql_query($q3)){
echo "MySQL ERROR: " . mysql_error() . "" . $sq3;
}
///////////////////////////////////////////////////////////////
if($Newlastname != $lastname)
{
$q4 = ("UPDATE users SET last_name=$Newlastname WHERE last_name=$lastname");
}
else if(!mysql_query($q4)){
echo "MySQL ERROR: " . mysql_error() . "" . $sq4;
}
///////////////////////////////////////////////////////////////
if($Newemail != $email)
{
$q5 = ("UPDATE users SET username=$Newemail WHERE email=$email");
}
else if(!mysql_query($q5)){
echo "MySQL ERROR: " . mysql_error() . "" . $sq5;
}
}
?>
userEditAccount.php:
<html>
<head>
<title>Edit Account</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<header><h1>E-Shop</h1></header>
<article>
<h1>Welcome</h1>
<h1>Edit Account</h1>
<div id="login">
<ul id="login">
<form method="post" name="editAccount" action="userEditAccount.php" >
<fieldset>
<legend>Fill in the form</legend>
<label>Select Username : <input type="text" name="username" /></label>
<label>Password : <input type="password" name="password" /></label>
<label>Enter First Name : <input type="text" name="first_name" /></label>
<label>Enter Last Name : <input type="text" name="last_name" /></label>
<label>Enter E-mail Address: <input type="text" name="email" /></label>
</fieldset>
<br />
<input name="Editsubmited" type="submit" submit="submit" value="Edit Account" class="button">
</form>
<?
echo $newrecord;
?>
</div>
<form action="userhome.php" method="post">
<div id="login">
<ul id="login">
<li>
<input type="submit" value="back" onclick="index.php" class="button">
</li>
</ul>
</div>
</article>
<aside>
</aside>
<div id="footer">This is my site i Made coppyrights 2013 Tomazi</div>
</div>
</body>
</html>
此外:
我试图与代码拨弄看着网页,但没有运气的代码我已经为我的眼中的剧本写下了最好的解决方案,也是让我感觉到的解决方案。
所以我没有其他选择,只能转到本网站寻找答案,任何人都可能看到哪里会出现错误的整个事情......?
图片编辑帐户页面:
至于问Conect_mysql.php:
<?php
$db_hoast = "127.0.0.1";
$db_username = "root";
$db_password = "";
$db_name = "eshop";
$con = mysql_connect("$db_hoast","$db_username","$db_password");
if(!$con)
{
die("Could not connect to DATABASE");
}
$db = mysql_select_db("$db_name");
if(!$db)
{
die("No database");
}
?>
的问题与您UPDATE
陈述的价值观是未用单引号。它们是字符串文字,应该被包装。
$q1 = "UPDATE users SET username='$Newusername' WHERE username='$username'";
,以显示错误,
if($Newfirstname != $firstname)
{
$q1 = "UPDATE users SET username='$Newusername' WHERE username='$username'";
$result = mysql_query($q1);
if (!$result)
{
die('Invalid query: ' . mysql_error());
}
}
而且你的逻辑UPDATES
是错误的。这会导致您更新与条件匹配的记录。
作为旁注,如果变量的值(s)来自外部,则该查询容易受到SQL Injection
的影响。请看下面的文章,了解如何防止它。通过使用PreparedStatements
你可以摆脱使用单引号围绕值。
让我们听听downvoter的评论':)'我没有生气。我只想知道为什么。嘿嘿 – 2013-03-01 02:35:29
Thx您的回复我尝试了您的建议,现在仍然是错误,现在更新 – Tomazi 2013-03-01 02:40:07
如果你正在开始一个新的项目,不要使用分机/ MySQL的。它已被弃用。而是使用PDO或mysqli。您的脚本容易受到SQL注入的影响。 – Mike 2013-03-01 02:24:51
'WHERE username = $ password'是错误的 - 它应该与'$ username'比较,而不是'$ password'。 – Barmar 2013-03-01 02:25:42
请添加您的'connect_mysql.php'类来调查。 – 2013-03-01 02:28:40