duanbiyi7319 2019-01-18 08:50 采纳率: 100%
浏览 64

INSERT INTO不会在数据库中写入任何内容

Basically, we are trying to add some values in a database. We are doing it using a GET command to get the value called "valeur" and writing this in the database. However it is not working, the values are not added to the database

<?php
try
{ // connection a la base de donnees
// connection to mySQL
$bdd = new

PDO('mysql:localhost;dbname=test1', 'root', '');

}

catch(Exception $e) //in case of error, display it and stop everything

{
die('Erreur : '.$e->getMessage()); 
}

if (isset($_GET['temp1'])) // test if the variable exists

{

$_GET['temp1'] = floatval($_GET['temp1']); 

echo ('donnee ' .$_GET["temp1"]. ' en cours d\'ecriture</br>');

$bdd->exec('INSERT INTO temp (valeur) VALUES('.$_GET["temp1"].')');

echo ('donnee ' .$_GET['temp1']. ' ecrite!');
}
?>

If we put a value in (in our case) http://localhost/test1/add.php?temp1=(thevalue) then it should be inserted into our table called temp in the column "valeur". Instead, it doesn't write anything.

Edit : We are using PHP version 5.6.19 and MySQL 5.7.11 and WAMPserver

EDIT2: I have finally resolved the problem, though I have no idea how. Php looks fun

  • 写回答

2条回答 默认 最新

  • douchuoxuan3177 2019-01-18 09:03
    关注

    You should assign a variable for the SQL query for debugging target.
    And echo to print how is your query string. After that, you paste your $query in SQL tab at Phpmyadmin to know what is your error.

    $query = "INSERT INTO temp (valeur) VALUES('.$_GET['temp1'].')";
    echo $query;

    评论

报告相同问题?