Last Name:"> Mail ID:"> -6ren">
gpt4 book ai didi

php - 更新查询不起作用并将字段更改为 0

转载 作者:行者123 更新时间:2023-11-29 07:37:33 25 4
gpt4 key购买 nike

我有这个表单代码。

<form action="save_profile.php" method="post">
<table>
<tr><td>First Name:</td><td><input type="text" name="fname" value="<?php echo $fname;?>"></td></tr>
<tr><td>Last Name:</td><td><input type="text" name="lname" value="<?php echo $lname;?>"></td></tr>
<tr><td>Mail ID:</td><td><input type="text" name="mail" value="<?php echo $mail;?>"></td></tr>
<tr><td>Contact NO:</td><td><input type="text" name="contact" value="<?php echo $contact;?>"></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Save Profile"></td></tr>
</table>
</form>

我的 save_profile.php 文件包含此代码。

<?php
session_start();
require('config.php');
function is_valid_fname($fname,$lname,$contact)
{
if (empty($fname)) {
?>
<center><strong><font color="red">First Name is required.</font></strong></center>
<?php
return false;
}
if ( !preg_match ("/^[a-zA-Z\s]+$/",$fname)) {
?>
<center><strong><font color="red">First Name Only Contain Letters.</font></strong></center>
<?php
return false;
}
if (strlen($fname)>20) {
?>
<center><strong><font color="red">First Name must be less than 20 Letters.</font></strong></center>
<?php
return false;
}
if (empty($lname)) {
?>
<center><strong><font color="red">Last Name is required.</font></strong></center>
<?php
return false;
}
if ( !preg_match ("/^[a-zA-Z\s]+$/",$lname)) {
?>
<center><strong><font color="red">Last Name Only Contain Letters.</font></strong></center>
<?php
return false;
}
if (strlen($lname)>20) {
?>
<center><strong><font color="red">Last Name must be less than 20 Letters.</font></strong></center>
<?php
return false;
}
if (empty($contact)) {
?>
<center><strong><font color="red">Contact is required.</font></strong></center>
<?php
return false;
}
if ( !preg_match ("/^[0-9\s]+$/",$contact)) {
?>
<center><strong><font color="red">Contact Only Contain Numbers.</font></strong></center>
<?php
return false;
}
if (strlen($contact)>15) {
?>
<center><strong><font color="red">Contact must be less than 20 Digits.</font></strong></center>
<?php
return false;
}
else{
return true;
}
}
function is_valid_email($mail)
{
if (empty($mail)) {
?>
<center><strong><font color="red">Email is required.</font></strong></center>
<?php
return false;
} else {
$email = test_input($mail);
// check if e-mail address is well-formed
if (!filter_var($mail, FILTER_VALIDATE_EMAIL)) {
?>
<center><strong><font color="red">Invalid Email Format.</font></strong></center>
<?php
return false;
}
// now check if the mail is already registered
$slquery = "SELECT 1 FROM user_tbl WHERE user_mail = '".$mail."'";
$selectresult = mysql_query($slquery);
if(mysql_num_rows($selectresult)>1) {
?>
<center><strong><font color="red">This Email Is Already Exits.</font></strong></center>
<?php
return false;
}
// now returns the true- means you can proceed with this mail
return true;
}
}
if (isset($_POST['submit'])){
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mail = $_POST['mail'];
$contact = $_POST['contact'];
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if (is_valid_email($mail) && is_valid_fname($fname,$lname,$contact))
{
$query="UPDATE user_tbl SET user_fname='".$fname."' AND user_lname='".$lname."' AND user_mail='".$mail."' AND user_contact='".$contact."' WHERE user_id='".$_SESSION['uid']."'";
$result = mysql_query($query);
if ($result) {
header('location:profile.php');
}
}
else{
?>
<center><strong><font color="red">Error Updating User.</font></strong></center>
<?php
}
}
?>

我的问题是,当我更改表单数据时,在表单中显示数据后,当我提交表单时,它总是会更新我的 user_fname=0...当我更改其他字段时,我的其他字段保持不变并设置 user_fname=0。请帮帮我...

最佳答案

请使用逗号(,)代替

$query="UPDATE user_tbl SET user_fname='".$fname."', user_lname='".$lname."', user_mail='".$mail."', user_contact='".$contact."' WHERE user_id='".$_SESSION['uid']."'";

关于php - 更新查询不起作用并将字段更改为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30233150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com