2016-12-22 1 views
0

私はHTMLを通じてPHPコードを実行したときに、私は、フォームを送信したとき、私はそれがファイルのページが見つからないか削除されていない表示され、私はローカルホスト上で個別にIを実行すると、それが正常にデータベースPHPがHTMLファイルとリンクしている間にデータを送信する方法は?

<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フォーム

<!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'; 
    } 
} 
?> 

SQLコードと私はonclickの提出後にページがホームにリダイレクトされるようにしたいです。

答えて

0

まず、あなたの問題の一部である$server="localhost"があります。これはあなたの開発マシンを探しています。次に、あなたが好きなページにリダイレクトするためのヘッダーを追加することができます。header("path/to/your/page");

localhostをdbホストまたはIPに置き換えます。あなたはあなたのサイトをホスティングしているあなたのプロバイダからd/bを得ることができます。次にヘッダー( "/")を挿入します。ユーザーをルート(ホームページ)に誘導します。あなたのD/Bアップデートの後にこのコードを追加してください。

+0

何親愛なるは、実際に私はローカルに私の全体のプロジェクトを実行していない午前私は何をすべき – hasni

+0

は私がこのplzzzを達成するために何を追加したり、削除する必要がありますが、私に – hasni

+0

を伝えるので、その私はローカルでこれを実行しては生きていけない、私のフロントエンドとバックエンドの作業フォルダは – hasni

関連する問題