简体   繁体   English

PHP没有向mysql表提交值

[英]PHP not submitting values to mysql table

I am trying to submit a form with php to submit the data to a table that I have already created in the database. 我正在尝试使用php提交表单以将数据提交到我已在数据库中创建的表中。 All of the mysql_connect information is correct. 所有mysql_connect信息都是正确的。 Is there something in my code that I am not doing correctly? 我的代码中有什么东西我做得不对吗?

PHP: PHP:

if (isset($_POST['submit']) && strlen($_POST['firstName'])>0 && strlen($_POST['lastName'])>0 && strlen($_POST['email'])>0)
{
    $first_name=$_POST['firstName']; 
    $last_name=$_POST['lastName']; 
    $email=$_POST['email'];
    $phone=$_POST['phone'];
    $city=$_POST['city'];
    $make=$_POST['make'];
    $model=$_POST['model'];
    $year=$_POST['year']; 
    mysql_connect("******", "*****", "****") or die(mysql_error()); 
    mysql_select_db("buddyTruk") or die(mysql_error());
    mysql_query("ALTER TABLE drivers ADD PRIMARY KEY (email)");
    mysql_query("REPLACE INTO `drivers` VALUES ('$first_name', '$last_name', '$email', '$phone', '$city', '$make', '$model', '$year')"); 

 } 


 ?> 

HTML: HTML:

<form id="drivers-form" class="form-horizontal" method="get" action="index.php">
                <input type="text" name="firstName" class="form-control input-lg" placeholder="First Name" required/> 
                <input type="text" name="lastName" class="form-control input-lg" placeholder="Last Name" required/>
                <input type="email" name="email" class="form-control input-lg" placeholder="Email" required/>
                <input type="tel" name="phone" class="form-control input-lg" placeholder="Phone" required/>
                <input type="text" name="city" class="form-control input-lg" placeholder="City" required/>
                <input type="text" name="make" class="form-control input-lg" placeholder="Make" required/>
                <input type="text" name="model" class="form-control input-lg" placeholder="Model" required/> 
                <input type="text" name="year" class="form-control input-lg" placeholder="Year" required/> 
                <button class="btn btn-success btn-lg" name="submit" type="submit" value="submit">Submit</button>
            </form>

You have the wrong method on your form. 您的表单上有错误的方法。 Change the form method to "post" : 将表单方法更改为"post"

<form id="drivers-form" class="form-horizontal" method="post" action="index.php">

If you want to use "get" as the form method, you would access the values with $_GET , however, get is not recommended. 如果要使用"get"作为表单方法,则可以使用$_GET访问值,但不建议使用get

Please stop using mysql as it is long deprecated. 请停止使用mysql因为它已被弃用。 Use mysqli or PDO instead. 请改用mysqliPDO Most importantly, use prepared statements. 最重要的是, 使用准备好的陈述。 Anyone could easily steal and erase all of your data with your current code. 任何人都可以使用您当前的代码轻松窃取并删除所有数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM