后端php程序在xammp中工作但是上传的值没有输入数据库

时间:2016-08-16 08:38:13

标签: php xampp

验证邮件发送但数据库中没有值,我创建了一个用户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

3 个答案:

答案 0 :(得分:0)

尝试调试您的查询。

例如:

if (mysqli_query($link, "your query") === TRUE) {

    printf("Table myCity successfully created.\n");

}

答案 1 :(得分:0)

除了明显缺乏安全性之外,你应该考虑一下。[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语法的好资源。

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

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分钟前

     

请检查此页面以查看MYSQL dev.mysql.com/doc/refman/5.7/en/keywords.html中的研究用语。不要在你的sql中使用保留字 - kikuyu1 6分钟前

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

答案 2 :(得分:0)

我建议你使用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;
?>