-1

I want to query one new to sql table, the code run but it doesn't insert anything into the database.

I try to read back the pdo manual but doesn't understand which part I am wrong.

$query = "INSERT INTO 'easycomputing'('STID', 'NAME', 'TONG') VALUES (:STID, :NAME, :TONG)";
$dns = " mysql:host=localhost;dbname=phan1";
$username="root";  
$password= "";
// $password="";
try{
    //access the database
    $db = new PDO($dns, $username, $password);
    //execute the query
    $statement = $db->prepare($query);

    $statement->bindValue(':STID', 137, PDO::PARAM_INT);
    $statement->bindValue(':NAME', 'tenten', PDO::PARAM_STR);
    $statement->bindValue(':TONG', 5, PDO::PARAM_INT);

    //execute the query
    if( $statement->execute() ){
        echo "record tranfer successfully";
    }else{
        echo "fail to execute the record";
    }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
anh phan
  • 21
  • 6
  • 1
    This is not valid MySQL code. You need to remove the single quotes around the table name and the column names: `INSERT INTO easycomputing(STID, NAME, TONG) VALUES (:STID, :NAME, :TONG)`. You should also learn to check for errors after calling `prepare()`. Voting to close this as a typo. – GMB May 27 '20 at 02:57
  • that is true, wrong syntax on table name. first i thought it is problem with the binding statement. thank you for your time @GMB. – anh phan May 27 '20 at 03:13

1 Answers1

-1

Sorry, but I think that you shouldn't isert the name of columns between codes : (STID, NAME, TONG)