尝试更新表的SQL语法 [英] Sql syntax trying to update table

查看:47
本文介绍了尝试更新表的SQL语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家下午好,在尝试更新表时遇到问题:

Good afternoon to all, having an issue trying to update a table:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'name='Joshh'   WHERE email='yoyo@gmail.com'' at line 1





有什么想法吗?在此先感谢。



我尝试过:





Any idea? Thanks in advance.

What I have tried:

<div class="modal fade" id="defaultModal" tabindex="-1" role="dialog" aria-labelledby="defaultModalLabel" aria-hidden="true">
										<div class="modal-dialog">
											<div class="modal-content">
												<div class="modal-header">
													<h4 class="modal-title" id="defaultModalLabel">Edit Information</h4>
													<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
												</div>
												<div class="modal-body">
													<form action="" method="post">
    <div class="form-group">
      <label for="usr">Username:</label>
      <input type="text" class="form-control" disabled="disabled"  value="<?php echo $name;?>" id="usr" placeholder="Username" name="u_name" required="required">
    </div>
 <div class="form-group">
      <label  for="email">Email:</label>
      <input type="Email" class="form-control" id="email" value="<?php echo $eml;?>" disabled="disabled" placeholder="Enter Email" name="email" required="required">
      <input type="hidden" class="form-control" id="email" value="<?php echo $eml;?>" placeholder="Enter Email" name="email" required="required">
    </div> 
    <div class="form-group">
      <label for="pwd">New Password:</label>
      <input type="password" class="form-control" id="pswd"  placeholder="Enter password" name="pswd" required="required" onkeyup='check();'>
       <label for="cpwd">Confirm_Password:</label>
      <input type="password" class="form-control" id="cpswd" placeholder="Confirm password" name="cpswd" required="required" onkeyup='check();'>
      <span id='message'></span>
      <div class="form-group">
      <label for="pwd">Phone:</label>
      <input type="text" class="form-control" id="address" value="<?php echo $phn;?>" placeholder="Enter Phone" name="phone" required="required">
    </div>

    </div>
    <div class="form-group">
      <label for="pwd">Address:</label>
      <input type="text" class="form-control" id="address" value="<?php echo $addr;?>" placeholder="Enter Address" name="address" required="required">
    </div>
    <center>
    <button type="submit" name="submit" class="btn btn-primary">Save Change</button>
  </center>
  </form>







---------- --------






------------------

// Create connection
$conn = mysqli_connect($servername, $username, $password,$db);

// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}?>
<?php
$name = $credit = $eml = $phone = $addr ="";
if (!isset($_SESSION["username"])) {
# code...
header("location:index.php");
}else {
$un = $_SESSION["username"];

$sql = "SELECT * FROM registration_form where username='$un'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_array($result)) {
$name = $row["username"];
$eml = $row["email"];
$credit = $row["credit"];
$phone = $row["phone"];
$addr = $row["Address"];
$fname = $row["fname"];
$lname = $row["lname"];
$binp = $row["binp"];
$amm = $row["amm"];
$bname = $row["bname"];
$acc = $row["acc"];
$rnumber = $row["rnumber"];
}
}
}
if(isset($_POST['submit'])){
$un = $_POST['u_name'];
$em = $_POST['email'];
$ps = $_POST['pswd'];
$cps = $_POST['cpswd'];
$p = $_POST['phone'];
$bd = $_POST['address'];

$sql = "UPDATE registration_form SET password ='$ps', phone='$p',Address='$bd', first name='$fname' WHERE email='$em'";

if($ps==$cps){
if (mysqli_query($conn, $sql)) {
?>
alert("Saved");
<?php
} else {

$error = "Error: " . mysqli_error($conn);
?>

alert("<?php echo $error; ?>");
<?php
}
} else {
?>
alert("Please Enter Correct Password and Try Again!");
<?php
} 
}

推荐答案

name;?>id = usr占位符=用户名name =u_namerequired =required>
< / div>
< div class =form-group>
< ; label for =email>电子邮件:< / label>
< input type =Emailclass =form-controlid =emailvalue =<?php echo
name;?>" id="usr" placeholder="Username" name="u_name" required="required"> </div> <div class="form-group"> <label for="email">Email:</label> <input type="Email" class="form-control" id="email" value="<?php echo


eml;?>disabled =disabledplaceholder =输入电子邮件name =emailrequired =required>
< input type =hidden class =form-controlid =emailvalue =<?php echo
eml;?>" disabled="disabled" placeholder="Enter Email" name="email" required="required"> <input type="hidden" class="form-control" id="email" value="<?php echo


eml;?>placeholder =Enter emailname =emailrequired = required>
< / div>
< div class =form-group>
< label for =pwd>新密码:< / label>
< input type =passwordclass =form-controlid =pswdplaceholder =Enter passwordname =pswdrequired =requiredonkeyup ='check();' >
< label for =cpwd > Confirm_Password:其中/标签>
< input type =passwordclass =form-controlid =cpswdplaceholder =Confirm passwordname =cpswdrequired =requiredonkeyup ='check();'>
< span id ='message'>< / span>
< div class =form-group>
< label for =pwd>电话:< / label>
< input type =textclass =form-controlid =addressvalue =<?php echo
eml;?>" placeholder="Enter Email" name="email" required="required"> </div> <div class="form-group"> <label for="pwd">New Password:</label> <input type="password" class="form-control" id="pswd" placeholder="Enter password" name="pswd" required="required" onkeyup='check();'> <label for="cpwd">Confirm_Password:</label> <input type="password" class="form-control" id="cpswd" placeholder="Confirm password" name="cpswd" required="required" onkeyup='check();'> <span id='message'></span> <div class="form-group"> <label for="pwd">Phone:</label> <input type="text" class="form-control" id="address" value="<?php echo


这篇关于尝试更新表的SQL语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆