Jump to content

PHP PDO Insert Query Inserting Data Two Times Error

<?php

   $server = "localhost";
    $user ="root";
    $password="";
    $db="pdophp";

    $dbcon = new PDO("mysql:host=$server; dbname=$db", $user, $password );

try{

$dbcon->exec("insert into studentstable(name,age,class,gender) values('vinodth',26,11,'male')");

echo 'inserted successful';
}catch(PDOException $e)
    {
    echo $sql . "<br>" . $e->getMessage();
    }
?>

Code is working. Values are inserting but Twice into the Table. I tried but where I am doing wrong. Could you help plz.

Screenshot (1438).png

Link to comment
Share on other sites

Link to post
Share on other sites

Is that your whole code? Because nothing in that code will cause to insert twice.

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

45 minutes ago, C2dan88 said:

Is that your whole code? Because nothing in that code will cause to insert twice.

 

 

yes,  I don't know why it is happening. When I try the same code on Microsoft edge it's work.

Link to comment
Share on other sites

Link to post
Share on other sites

I could be miss understanding but your asking why is there more then one row in the database or that when you refresh the page it inserts two records at once?

 

Everytime you run the browser / load this up it will insert a new row into the database. Maybe you want a constraint in the database to not have a row with the same name and age?

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×