Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.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
Javascript 如何在PHP链接HTML文件时提交数据?_Javascript_Php_Html_Sql - Fatal编程技术网

Javascript 如何在PHP链接HTML文件时提交数据?

Javascript 如何在PHP链接HTML文件时提交数据?,javascript,php,html,sql,Javascript,Php,Html,Sql,我有问题,当我通过html运行php代码时,当我提交表单时,它会显示未找到或删除的文件页面,当我在localhost上单独运行时,它会成功地将数据提交到数据库中 <div class="top-nav"> <nav class="navbar navbar-default"> <div class="container"> <div class="navbar-header navbar-left">

我有问题,当我通过html运行php代码时,当我提交表单时,它会显示未找到或删除的文件页面,当我在localhost上单独运行时,它会成功地将数据提交到数据库中

<div class="top-nav">
    <nav class="navbar navbar-default">
        <div class="container">
            <div class="navbar-header navbar-left">
                <h1><a class="navbar-brand wow bounceIn animated" data-wow-delay=".5s" style="visibility: visible; -webkit-animation-delay: .5s;" href="index.html">PROJECT</a></h1>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse navbar-right" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav navbar-left">
                <li class="hvr-bounce-to-bottom "><a href="index.html">Home</a></li>
                    <li class="hvr-bounce-to-bottom"><a href="Currency Converter.html">Currency Converter</a></li>
                    <li class="hvr-bounce-to-bottom active"><a href="Vehicles.html">Vehicles</a></li>
                    <li class="hvr-bounce-to-bottom"><a href="php.php">Car Registeration</a></li>
                </ul>   
                <div class="clearfix"> </div>
            </div>
        </div>  
    </nav>      
</div>

带有html表单的SQL代码

<!DOCTYPE html>
<html>
<head>
<title>Form</title>
<link href="css/form.css" type="text/css" rel="stylesheet" media="all">

</head>
<body>
<div class="container">  
<form id="contact" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<h3>Vehicle Registration Form</h3>
<fieldset>
  <input name="firstname" placeholder="Enter Your First Name here" type="text" tabindex="1" required autofocus>
</fieldset>
<fieldset>
  <input name="lastname" placeholder="Enter Your Last Name here" type="text" tabindex="2" required>
</fieldset>
<fieldset>
  <input name="salary" placeholder="Enter Your Salary here" type="text" tabindex="3" required>
</fieldset>
<fieldset>
  <input  name="mobile" placeholder="Enter Your Mobile No. here" type="text" tabindex="4" required>
</fieldset>
<fieldset>
  <input  name="carbrand" placeholder="Enter Your Car Brand here" type="text" tabindex="5" required>
</fieldset>
<fieldset>
  <button name="submit" type="submit" id="contact-submit">Submit</button>
</fieldset>
 </form>
 </div>
<?php
if($_SERVER["REQUEST_METHOD"]=="POST"){

    $firstname=$_POST["firstname"];
    $lastname=$_POST["lastname"];
    $salary=$_POST["salary"];
    $mobile=$_POST["mobile"];
    $carbrand=$_POST["carbrand"];
    $db="yasir";
    $user="root";
    $pass="";
    $server="localhost";

    $conn=mysqli_connect($server,$user,$pass,$db) or die();
    if($conn){
        $query="INSERT into project  VALUES(null,'".$firstname."','".$lastname."',".$salary.",".$mobile.",'".$carbrand."', null, null)";
        $result = mysqli_query($conn, $query);
        mysqli_close($conn);
        echo 'connected';
    }
}
?>

形式

首先,您有
$server=“localhost”
,这是问题的一部分。这是在寻找你的开发机器。其次,您可以添加标题重定向到您喜欢的任何页面,例如:
标题(“path/to/your/page”)


用数据库主机或IP替换本地主机。你可以从你的提供商那里得到这个,你在那里托管你的站点和d/b。然后放入标题(“/”);将用户引导到您的根目录(主页)。在D/B更新后添加这段代码。

那么我应该做什么我应该添加和删除什么来完成这个plzzz告诉我亲爱的事实上我在本地运行我的整个项目它不是活的我在本地运行我的前端和后端工作文件夹是save htdocsi在Xamppy上创建了一个数据库你不能在纯HTML文件中使用php。它需要有一个php扩展,并在安装了php的web服务器上运行。此外,如果要使用
header()
,则需要将php放在顶部,重定向的正确代码为
header('位置:http://www.example.com/path/to/your/page');