从php添加一条mysql记录

时间:2015-09-02 11:04:36

标签: php mysql

为什么这段代码不起作用? 我需要在mysql上插入一个名为“utenti”的新记录,但是这段代码不起作用:

<?php
    $nome = $_REQUEST["nomeUtente"];
    $cognome = $_REQUEST["cognome"];
    $psw = $_REQUEST["psw"];
    $email = $_REQUEST["email"];
    $cell = $_REQUEST["num"];           

    echo $nome . " / " . $cognome . " / " . $psw . " / " . $email . " / " . $cell;
    echo "<br>";

    $conn = mysql_connect("hostName","User","password");

    if(!$conn){
        echo "connessione non satabilita";
    }else{
        if(!mysql_select_db("a4102239_utenti",$conn)){
            echo "database non trovato";
        }else{
            $sql = "INSERT INTO utenti (id,psw,nome,cognome,email,cellulare) VALUES (NULL,'$psw','$nome','$cognome','$email','$cell')"; //costruzione comando di ricerca      
        }
    }
?>

2 个答案:

答案 0 :(得分:1)

执行查询

.demoDark {
    background-size: cover;
    margin: 0 !important;
    padding-bottom: 1.7em !important; /*reduced padding value here */
}

答案 1 :(得分:0)

因为您没有执行查询,

$sql = "INSERT INTO utenti (id,psw,nome,cognome,email,cellulare) VALUES (NULL,'$psw','$nome','$cognome','$email','$cell')";
$result=mysql_query($sql);
if($result){
// Query is executed
}
else{
//Error
echo mysql_error();
}