douchi0638 2014-12-13 15:10
浏览 41
已采纳

Php脚本注册

i have a problem with my php registration's script. This is my code:

    <?php

//response è un array
$response = array();
//response con chiave success, ha valore -1
$response["success"] = -1;



/*ci colleghiamo al database(attenti perchè se lavorate in locale 
l'host è 10.0.2.2 e non 127.0.0.1)*/
 mysql_connect("localhost","fbaprova","")
    or die("Impossibile connettersi al server MySQL.
"); 
//selezioniamo il db a cui ci vogliamo connettere
mysql_select_db("my_fbaprova")
    or die("Impossibile aprire il database.
");
//creo la tabella nel database
mysql_query("CREATE TABLE IF NOT EXISTS `my_fbaprova`.`Utente` (
            `Ut_Id` INT NOT NULL AUTO_INCREMENT,
            `Ut_Username` VARCHAR(45) NOT NULL,
            `Ut_Email` VARCHAR(45) NOT NULL,
            `Ut_Password` VARCHAR(45) NOT NULL,
            `Ut_PartiteVinte` INT NOT NULL,
            `Ut_PartitePerse` INT NOT NULL,
            PRIMARY KEY (`Ut_Id`))
         ENGINE = InnoDB;"); 
//inserisco i dati  nell'array post
$Ut_Username = $_POST['Ut_Username'];
$Ut_Email = $_POST['Ut_Email'];
$Ut_Password = $_POST['Ut_Password'];
$Ut_PartiteVinte = $_POST['Ut_PartiteVinte'];
$Ut_PartitePerse = $_POST['Ut_PartitePerse'];

//usarlo per la registrazione
$result = mysql_query("INSERT INTO `my_fbaprova`.`Utente` 
                        ( `Ut_Username`, `Ut_Email`,`Ut_Password` , `Ut_PartiteVinte`, `Ut_PartitePerse`) 
                        VALUES ($Ut_Username, $Ut_Email, $Ut_Password, $Ut_PartiteVinte,      $Ut_PartitePerse;");

if($result){

 // success
 $response["success"]= 1;
}else{
 //insuccess
 $response["success"] = -1;
}


// il response sarà = 1 se i dati sono stati inseriti, altrimenti sarà uguale a -1 nel caso l'username o l'email sia già presente nel db
echo json_encode($response);


mysql_close();

    ?>

But when i simulated A post with Postman application, from chrome store, the result is always success =-1.

as you'll see, i've not many experience with php. However, with this code, the table is created , in my db. Can someone help me?

  • 写回答

1条回答 默认 最新

  • duandai6373 2014-12-13 15:18
    关注

    Remove the unwanted semicolon from insert query

      $Ut_PartitePerse;");
    

    And your variables should have been wrapped with single quote like

     '$Ut_PartitePerse'
    

    So your insert query should be like

      mysql_query("INSERT INTO `my_fbaprova`.`Utente` 
                        ( `Ut_Username`, `Ut_Email`,`Ut_Password` , `Ut_PartiteVinte`, `Ut_PartitePerse`) 
                        VALUES ('$Ut_Username', '$Ut_Email', '$Ut_Password', '$Ut_PartiteVinte', '$Ut_PartitePerse')";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line