Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php-插入的数据未保存在phpmyadmin数据库中_Php_Mysql_Database - Fatal编程技术网

php-插入的数据未保存在phpmyadmin数据库中

php-插入的数据未保存在phpmyadmin数据库中,php,mysql,database,Php,Mysql,Database,我想将数据保存在我的phpmyadmin数据库中。但它无法保存。所以,在保存数据时,它会刷新页面,但数据不会显示在数据库中 下面是我想用来保存数据的类: class User{ public function __construct(){ $host='localhost'; $user='root'; $password=''; $conn=mysql_connect($host,$user,$password);

我想将数据保存在我的phpmyadmin数据库中。但它无法保存。所以,在保存数据时,它会刷新页面,但数据不会显示在数据库中

下面是我想用来保存数据的类:

class User{
    public function __construct(){

        $host='localhost';
        $user='root';
        $password='';
        $conn=mysql_connect($host,$user,$password);
        if(!$conn){
            die("Database Not Connected" . mysql_error());
        }

        mysql_select_db("db_sign_up");
        echo "Database created! ";
    }

    public function save_user($data){
        $sql="INSERT INTO tbl_user(first_name,last_name,email_address,password,mobile_number,address,
                                   city_name,country_name,zip_code)
                   VALUES('$data[first_name]','$data[last_name]','$data[email_address]','$data[password]',
                  '$data[mobile_number]','$data[address]','$data[city_name]','$datacountry_name]','$data[zip_code]')";
            if(!mysql_query($sql)){
                die("sl Error". mysql_error());
            }
            echo "Saved Successfully!";
            //mysql_close($conn);
    }
}
这里是用户界面

<?php
    require_once './classes/user.php';
    $obj=new User();
    if(isset($_POST['btn'])){
        $obj->save_user($_POST);
    }
?>

<html>
<head><title> Database Basic</title></head>
<body>
    <form action="sign_up.php" method="post">
        <table border="1">
            <tr><td>Personal Information</td><td></td></tr>
            <tr>
                <td> First Name</td>
                <td>
                    <input type="name" name="first_name" value="<?php if(isset($_POST['first_number'])){ echo htmlentities($_POST['first_name']);} ?> "/>
                </td>
            </tr>
            <tr>
                <td> Last Name</td>
                <td>
                    <input type="name" name="last_name" value="<?php if(isset($_POST['last_name'])){ echo htmlentities($_POST['last_name']);} ?> "/>
                </td>
            </tr>
            <tr>
                <td> Email Address</td>
                <td>
                    <input type="name" name="email_address" value="<?php if(isset($_POST['email_address'])){ echo htmlentities($_POST['email_address']);} ?> "/>

                </td>
            </tr>
            <tr>
                <td> Password</td>
                <td>
                    <input type="password" name="password" value="<?php if(isset($_POST['password'])){ echo htmlentities($_POST['password']);} ?> "/>
                </td>
            </tr>
            <tr>
                <td> Mobile Number</td>
                <td>
                    <input type="name" name="mobile_number" value="<?php if(isset($_POST['mobile_number'])){ echo htmlentities($_POST['mobile_number']);} ?> "/>
                </td>
            </tr>
            <tr>
                <td> Address</td>
                <td>
                    <textarea name="address" rows="4" cols="30"></textarea>
                </td>
            </tr>
            <tr>
                <td> City</td>
                <td>
                    <input type="" name="city_name" value="<?php if(isset($_POST['city_name'])){ echo htmlentities($_POST['city_name']);} ?> "/>
                </td>
            </tr>
            <tr>
                <td> Country</td>
                <td>
                    <select name="country_name">
                        <option value=" ">Select Country ...</option>
                        <option value="bangladesh">Bangladesh</option>
                        <option value="srilanka">Srilanka </option>
                        <option value="india">India</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td> Zip Code</td>
                <td>
                    <input type="name" name="zip_code" value="<?php if(isset($_POST['zip_code'])){ echo htmlentities($_POST['zip_code']);} ?> "/>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="submit" name="btn" value="Save">
                </td>
            </tr>
        </table>
    </form>
</body>

数据库基础
个人信息
名字

它的函数接收一个数组,然后检查数组。db和if中的类型字段已正确填充。 字段int类型=int值

如果以字符串形式返回,则可以将其转换为:

$string = $data[mobile_number];
$int = (int)$string; // convert string type for int.
或者在字段中使用varchar类型
如果不是这样,请详细说明您的代码。

您的INSERT语句中有一个错误:

您在查询中使用的countryname变量为:

'$datacountry_name]'
我认为应该是这样的:

'$data[country_name]'
旁注:

您使用的是不推荐使用的mysql\uu我建议您使用mysqli\uPDO


其次,您的代码是为SQL注入打开的,您需要防止SQL注入。

请显示您的代码..添加..请检查。
$data
变量是数组吗?是数组。。。我搞错了,我没放标签。顺便说一句,谢谢你的帮助!PHPMyAdmin是数据库客户端,而不是数据库。电话号码通常以
0
开头。不能将它们视为整数。我不会在数字前面使用零来保存数据库。:)但是,我只举了一个例子:谢谢你——1昆汀,我很高兴看到人们否定我,只是因为他们认为每个人都是平等的。在我的国家,没有以“0”开头的电话号码