dr5648 2015-10-28 16:45
浏览 60

我的数据库没有保存在我的SQL WAMP服务器中形成的表中

I have created a database in MySQL WAMP server and is not saving results. Please tell me what should I do. There is no error while submitting in localhost.

Can't add more details:

<?php

if (isset($_POST['Submit'])) {
    $firstName = $_POST['Name'];
    $fatherName = $_POST['fatherName'];
    $email = $_POST['Email'];
    $NIC = $_POST['NIC'];

    $server = '127.0.0.1';
    $vid = 'root';
    $pwd = '';
    $conn = mysqli_connect($server, $vid, $pwd);
    if (!$conn) { 
        echo "server not found";     
    } else { 
        echo"stored successfully";
        @mysql_select_db("database1");

        //$firstName= "nazi";
        //$fatherName="Ali";
        //$email= "nazia.se@yahoo.com";
        //$NIC= 67567678;

        //$sqlquery="INSERT INTO tab1 (name,fname,email,nic) VALUES ('$firstName',            '$fatherName', '$email', $NIC)";
        $sqlquery = "INSERT INTO form(name,fname,email,nic) VALUES ('$firstName', '$fatherName', '$email', $NIC)";
        //echo $sqlquery;
        mysql_query($sqlquery);
    }
}

if (isset($_POST['Submit'])) {
    if(empty($firstName)){
        echo nl2br("Please write name.
");
        return false;
    }       
    if (empty($fatherName)) {
        echo nl2br("Please write email .
");   
    }
    if (empty($email)) {
        echo nl2br("Please write email .
");
    }
    if (empty($NIC)) {
        echo nl2br("Please write NIC number .
");  
    };
}

?>

<form id="form1" name="form1" method="post" >
<p>&nbsp;</p>
<p align="center" class="style1">   REGISTERATION FORM </p>
<p>&nbsp;</p>
<table width="447" border="1">
        <tr>
         <td width="169">Name</td>
            <td width="262"><label>
          <input name="Name" type="text" />
        </label></td>
      </tr>
      <tr>
        <td>Father Name</td>
        <td><label>
          <input type="text" name="fatherName" />
        </label></td>
      </tr>
      <tr>
        <td>email Address</td>
        <td><label>
          <input name="Email" type="text" />
        </label></td>
      </tr>
      <tr>
        <td>NIC </td>
        <td><label>
          <input name="NIC" type="text" size="15" />
        </label></td>
      </tr>
      <tr>
        <td colspan="2"><input type="submit" name="Submit" value="Submit" />                </td>
      </tr>
    </table>
  </form>
  • 写回答

1条回答 默认 最新

  • doufang8965 2015-10-28 20:46
    关注
    $conn = mysqli_connect($server, $vid, $pwd);
    ...
    @mysql_select_db("database1");
    

    You're not using the right functions here. mysql and mysqli are two totally different things. One of them hasn't even been supported for years. As well, you're leaving yourself wide open for people to wipe out your database. Try something like the following. And if it makes no sense, read up on prepared statements and their benefits.

    $conn = new mysqli($server, $vid, $pwd, "database1");
    $sqlquery = "INSERT INTO form(name,fname,email,nic) VALUES (?, ?, ?, ?)";
    $stmt = $conn->prepare($sqlquery);
    $stmt->bind_param("sssi", $firstName, $fatherName, $email, $NIC);
    $stmt->execute();
    $mysqli->close();
    

    Finally, if you want to check for empty values you should probably do it before you write things to the database, not after.

    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)