后端php程序在xammp工作,但当上传的值没有进入数据库


Backend php program working in xammp but when uploaded values not getting entered in database

验证邮件正在发送,但值不在数据库中,我创建了一个用户lavvish,它具有所有特权。这是我的代码-

$dbc=mysqli_connect('localhost','lavvish','lavvish','lavvish_users');
$q="INSERT INTO temp_users(first,last,email,otp,countrycode,mobile,password)VALUES ('$first','$last','$email','$otp','$cc','$mobile','$EncPwd')";
mysqli_query($dbc,$q);
$_SESSION['email']=$_POST['email'];
header('Location:index.php?login=newuser');
//send verification mail
$to = $email; // Send email to our user
$subject = 'Verification link'; // Give the email a subject 
$message='Your account has been created, activate your account by entering the following otp:'.$otp.'';
$headers = 'From:goLavvish@golavvish.com' . "'r'n"; // Set from headers
mail($to, $subject, $message, $headers); // Send our email
//Email sent

我建议您使用PDO。只有INSERT命令成功时才会发送电子邮件,否则它将返回一个带有错误消息的错误。要了解PDO,请访问此页面http://www.w3schools.com/php/php_mysql_insert_multiple.asp。

希望对大家有帮助。

<?php
$servername = "localhost";
$username = "lavvish";
$password = "lavvish";
$dbname = "lavvish_users";
try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "INSERT INTO temp_users (first, last, email, otp, countrycode, mobile, password)
    VALUES ($first, $last, $email, $otp, $cc, $mobile, $EncPwd)";
    // use exec() because no results are returned
    $conn->exec($sql);
    // Save sessions when INSERT is successful
    $_SESSION['email']=$_POST['email'];
    header('Location:index.php?login=newuser');
    $to = $email; // Send email to our user
    $subject = 'Verification link'; 
    // Give the email a subject 
    $message='Your account has been created, activate your account by entering the following otp:'.$otp.'';
    $headers = 'From:goLavvish@golavvish.com' . "'r'n"; 
// Set from headers
  mail($to, $subject, $message, $headers); 
// Send our email
//Email sent
    }
catch(PDOException $e)
    {
    echo $sql . "<br>" . $e->getMessage();
    }
$conn = null;
?>

尝试调试您的查询。

例如:

if (mysqli_query($link, "your query") === TRUE) {
    printf("Table myCity successfully created.'n");
}

除了明显缺乏安全性之外,您应该考虑到这一点。[1]我认为你的问题在于你的SQL语句。

我要把下面这行改成:

$q="INSERT INTO temp_users(first,last,email,otp,countrycode,mobile,password)VALUES ('$first','$last','$email','$otp','$cc','$mobile','$EncPwd')";

使它现在读为:

$q="INSERT INTO temp_users (first, last, email, otp, countrycode, mobile, password) VALUES ('$first', '$last', '$email', '$otp', '$cc', '$mobile', '$EncPwd')";

可以看到,我在元素之间添加了空格。这对我很有效。如果没有帮助,试试MySQL Checker,这是一个很好的资源来检查你的MySQL语法。

EDIT:如果这不起作用,我会检查您的用户权限。确保该用户对该数据库具有特定于数据库的权限(或者如果要锁定数据库,则具有特定于表的权限)

EDIT2:参见kikuyu1在上一个答案中的评论:

@ShubhamKhetan,你可以试着重命名这个$sql = "INSERT INTO temp_users (first_n, last_n, email_n, otp_n, countrycode_n, mobile_n, password_n) VALUES ($first, $last, $email, $otp, $cc, $mobile, $EncPwd)";- kikuyu1 11 mins ago

请查看本页的MYSQL研究词dev.mysql.com/doc/refman/5.7/en/keywords.html。不要在你的sql中使用保留词- kikuyu16 mins ago

[1]:至少对输入进行一些处理,否则一些不法黑客会尝试SQL注入。