Jump to content
Sign in to follow this  
appleorange

Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 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 ') FROM `users` WHERE `user

Recommended Posts

<?php
session_start();
$servername = "localhost";
$username = "t9w7awqo_ftp_acc";
$password = "";
$dbname = "t9w7awqo_vuyanii";
$conn = null;
//$dbname = "temp_StoreDB";
$conn = null;
global $bcrypt; 
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);
    //echo "Connected to DB successfully <br>";
    }
catch(PDOException $e)
    {
    echo $e->getMessage();
    }

if(isset($_POST['login'])){
            $username   = $_POST['username'];
            $password   = $_POST['password'];
            $message    = '';
     
         $query = "SELECT count() FROM `users` WHERE `username`= ? AND `password` = ?";

       
        
         $stmt = $conn->prepare($query); 
         $stmt->execute(array($username,$password)); //line 34

         //$stmt->execute([$username,$password]);
        
         $stmtl = $stmt->fetchColumn();

         if($stmtl == 1){
            $_SESSION['username'] = $username;

            $dated = date('y/m/d');
            $ip    = $_SERVER['REMOTE_ADDR']; 
           try{
                   $query = "INSERT INTO visitors(user_id,username,dated,ip) 
                VALUES(:fn, :ln, :em, :con)";
            $stmt = $conn->prepare($query);
           $stmt->bindparam(":fn",$user_id);
            $stmt->bindparam(":ln",$username);
            $stmt->bindparam(":em",$dated);
            $stmt->bindparam(":con",$ip);
           
            
            $stmt->execute();

            header('location:welcome.php');
           }
                       catch(PDOException $e){
                echo $e->getMessage();
            }
             echo $dated;

             $message ='<p style="color:red;">Logged In successfully</p>';      
         }else{
             
            $message ='<p style="color:red;">Incorrect Details Entered</p>';  
            //echo "$message";           
         }
}
?>

Share this post


Link to post
Share on other sites

You need to get better at asking questions.  This is not a service where you enter your code and error message and a solution pops out.  Also, please understand how to post code using the Code button in the text entry field.

The error message is telling you exactly what the problem is, do you understand what it's saying?

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...