2014-03-27 53 views
1

看来我的代码不显示使用我的系统的编辑功能后,并按下保存/提交按钮后,查询我试图使用通过该网址的变量,并使用$ _GET只显示用户自己的帐户,我知道我的代码在Mysql的更新语句周围有冲突,请大家帮忙。更新语句使用变量

我的问题是:如何在按下表格中的保存按钮后显示查询?

这里是我的代码:?

<?PHP 
    include ("dbcon1.php"); 

// GET变量username通过URL

$username=$_GET['username']; 

    ?> 

    <html> 
    <head> 
    </head> 
    <body> 
    <form method="post"> 
    <table> 
    <?PHP 

//只获取查询根据URL(edit2.php USERNAME = $ USERNAME)

$customerquery=mysql_query("select * from customerinfo where username='$username'"); 
    $customerrows=mysql_fetch_array($customerquery); 
    ?> 

//形成具有用户信息

<tr><td>First name:</td><td><input type="text" name="fname" value="<?PHP echo $customerrows['fname'];?>"></td></tr> 
    <tr><td>Last name:</td><td><input type="text" name="lname" value="<?PHP echo $customerrows['lname'];?>"></td></tr> 
    <tr><td>Address:</td><td><input type="text" name="address" value="<?PHP echo $customerrows['address'];?>"></td></tr> 
    <tr><td>Contact Number:</td><td><input type="text" name="contactno" value="<?PHP echo $customerrows['contactno'];?>"></td></tr> 
    <tr><td>Username:</td><td><input type="text" name="username" value="<?PHP echo $customerrows['username'];?>"></td></tr> 
    <tr><td>Password:</td><td><input type="password" name="password" value="<?PHP echo $customerrows['password'];?>"></td></tr> 

//保存按钮

<tr><td><input type="submit" name="submit" value="Save"></td></tr> 

    </table> 
    </form> 
    </body> 
    </html> 
    <?PHP 
    include('dbcon1.php'); 
    include('dbcon.php'); 

//保存按钮按下时,更新表

if(isset($_POST['submit'])){ 
    $username=$_GET['username']; 
    $fname=$_POST['fname']; 
    $lname=$_POST['lname']; 
    $address=$_POST['address']; 
    $contactno=$_POST['contactno']; 
    $username=$_POST['username']; 
    $password=$_POST['password']; 

//更新表

mysql_query("update customerinfo set fname='$fname',lname='$lname',address='$address',contactno='$contactno',username='$username',password='$password' where username='$username'"); 
    header("location:index5.php?username=$username"); 
    } 
    ?> 
    <table border='1'> 
    <?PHP 
    include('dbcon.php'); 
    include('dbcon1.php'); 

//获取通过URL可变用户名

$username = $_GET['username']; 

//显示当前登录 //表信息,关于用户的用户

$customerquery = mysqli_query($con,"SELECT * FROM customerinfo WHERE username = '$username'"); 
    while($customerrows=mysqli_fetch_array($customerquery)){ 
    ?> 
    <tr> 
    <td>Id</td><td>First Name</td><td>Last Name</td><td>Address</td><td>Contact No</td <td>Username</td><td>Password</td><td>Edit</td> 
    </tr> 
    <tr> 
    <td><?PHP echo $customerrows['id'];?></td> 
    <td><?PHP echo $customerrows['fname'];?></td> 
    <td><?PHP echo $customerrows['lname'];?></td> 
    <td><?PHP echo $customerrows['address'];?></td> 
    <td><?PHP echo $customerrows['contactno'];?></td> 
    <td><?PHP echo $customerrows['username'];?></td> 
    <td><?PHP echo $customerrows['password'];?></td> 

//编辑按钮

<td><input type="button" value="edit" onClick="window.location='edit2.php?username=<?php echo $username ?>'"></td> 
    </tr> 
    <?PHP } ?> 
    </table> 
    <a href="login1.php">Log-out</a> 
+0

尽我所知,你已经混合了'mysqli_ *'和'mysql_ *'函数。最有可能的问题。这两个不混合。 –

+0

@ Fred-ii-那么先生,最好只使用mysqli或mysql? – eatmycode

+0

只要你正确地消毒,这取决于你。但你不能混用它们。你的DB文件是什么样子的,他们都使用'mysql_ *'作为SQL函数,还是'mysqli_ *'? –

回答

0

首先你的查询有一个错误

$customerquery=mysql_query("select * from customerinfo where username='".$username."' "); 

AND

mysql_query("UPDATE customerinfo SET fname='".$fname."',lname='".$lname."',address='".$address."',contactno='".$contactno."',username='".$username."',password='".$password."' WHERE username='".$username."' "); 
+3

@zardari先生是什么让它错了?请回答 – eatmycode

+0

不,我敢肯定这样会有效,但你可以指出更多更明显的错误。 –

+1

哦,我的不好,我会尝试这个代码出来tnx先生 – eatmycode