0

I was working in PHP 5.x for the past 2 years. I just got my PHP version updated to PHP 7.x which uses PDO to add data into the database. Now I have altered my code but the data is not getting added to the database from the User's form whereas it is getting added if I hard code it by changing the VALUES(' '); to the value that I want in the SQL QUERY.

Please look into the code and help me with it. Thanks!

    <?php
        try{
            $db=new PDO("mysql:host=$host;dbname=$dbname",$dbusername,$dbpassword);
            $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            //echo "Database selected";
        }
        catch(PDOException $e)
            {
                echo $e->getMessage();
            }

        if(isset($_REQUEST['sub'])){
            //echo "going inn";
            $email=$_REQUEST['email'];
            $password=$_REQUEST['password'];
            $mobile=$_REQUEST['mobile'];
            $insert="INSERT INTO users (mailid,password,mobile) VALUES ($email,$password,$mobile)";


            $db->exec($insert);
                echo "New record created successfully";
        }
?>
SimpleBeat
  • 747
  • 1
  • 10
  • 20

0 Answers0