Jump to content

Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax;


DaryllB
Go to solution Solved by ginerjm,

Recommended Posts

I did some improvements but still got this fatal error.

Fatal error: Uncaught mysqli_sql_exception: 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 ')' at line 1 in C:\xampp\htdocs\myproject\code.php:66 Stack trace: #0 C:\xampp\htdocs\myproject\code.php(66): mysqli_query(Object(mysqli), 'INSERT INTO use...') #1 {main} thrown in C:\xampp\htdocs\myproject\code.php on line 66.

 

What to do next?

<?php
session_start();
include "dbcon.php";
//Import PHPMailer classes into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require 'vendor/autoload.php';


function sendemail_verify($name,$email,$verify_token)
{
    $mail = new PHPMailer(true);

    $mail->isSMTP();                                             //Send using SMTP
    $mail->Host       = 'smtp.gmail.com';                        //Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                    //Enable SMTP authentication
    $mail->Username   = 'harivoteuser@gmail.com';                //SMTP username
    $mail->Password   = 'Sec_ret123';                            //SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;        //Enable implicit TLS encryption
    $mail->Port       = 587;                                     //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
    
    $mail->setFrom("harivoteuser@gmail.com", $name);
    $mail->addAddress($email);                                   //Add a recipient
    
    $mail->isHTML(true);                                         //Set email format to HTML
    $mail->Subject = 'Email Verification from HariVote';

    $email_template = "
    <h2>You have Registered with Harivote</h2>
    <h5>Verify your email address to Login with the below given link </h5>
    <br/><br/>
    <a href='http://localhost/myproject/verify-email.php?token=$verify_token'>Click Me </a>
    ";
    $mail->Body = $email_template;
    $mail->send();
    //echo 'Message has been sent';
    
}

if(isset($_POST['register_btn']))
{
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$verify_token = $_POST['password'];
$password = md5(rand());



//Email exists or not
    $check_email_query = "SELECT email FROM users WHERE email='$email'LIMIT 1";
    $check_email_query_run = mysqli_query($con, $check_email_query);

    if(mysqli_num_rows($check_email_query_run)>0)
    {
        $_SESSION['status'] = "Email Id already Exists";
        header("Location: register.php");
    }
    else
    {
    // Inswer User / Registered User Data
    $query = "INSERT INTO users (name, phone, email, password, verify_token) VALUES ('$name','$phone','$email','$password','$verify_token',)";
    $query_run = mysqli_query($con, $query);
        if($query_run)
        {   
            sendemail_verify("$name","$email","$verify_token");
            $_SESSION['status'] = "Registration Successful! Please verify your Email Address.";
        header("Location: register.php");
        }
        else
        {
            $_SESSION['status'] = "Registration Failed";
        header("Location: register.php");
        }
    }


}


?>

 

Link to comment
Share on other sites

  • Solution

You have an extra ,  right before the ) as the error message is telling you.

In the future when posting code that includes an error message with a line number it would be always helpful to point out that line when you show the code.

Edited by ginerjm
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.