如何将这些数据插入到wampserver中的mysql中

时间:2018-05-23 18:23:25

标签: mysql wampserver

这里是代码。无论我做什么都无法连接到wampserver中phpadmin的mysql数据库所有尝试都失败请帮助解决

if (isset($_POST['continue'])) {
    $j=0;
    while ($j < $passengers)
    {

$register_data2 = array(
    'first_name'        => $_POST["fname"][$j],
    'last_name'         => $_POST["lname"][$j],
    'passport'          => $_POST["passport"][$j],
    'visa'              => $_POST["visa"][$j],
    'address1'          => $_POST["address1"][$j],
    'address2'          => $_POST["address2"][$j],
    'email'             => $_POST["email"][$j],
    'contact'           => $_POST["contact"][$j],
    'pin'               => $_POST["pin"][$j],
    'leaving_from'      => $pieces[0],
    'going_to'          => $pieces[2],
    'depart_date'       => $pieces[7],
    'depart_time'       => $pieces[12],
    'arrival_time'      => $pieces[17],
    'grand_fare'        => $pieces[22],
    'returning_from'    => $pieces1[0],
    'returning_to'      => $pieces1[2],
    'returning_date'    => $pieces1[7],
    'returning_time'    => $pieces1[11],
    'reaching_time'     => $pieces1[16],
    'fare'              => $pieces1[21]
    );

session_start();
    $_SESSION['ticket'][] = $_POST["fname"][$j];
    $_SESSION['ticket'][] = $_POST["lname"][$j];
    $_SESSION['ticket'][] = $_POST["passport"][$j];
    $_SESSION['ticket'][] = $_POST["visa"][$j];
    $_SESSION['ticket'][] = $_POST["pin"][$j];
    register_passenger($register_data2);

    $j = $j+1;

}

$_SESSION['ticket1'] = $pieces[0];
$_SESSION['ticket2'] = $pieces[2];
$_SESSION['ticket3'] = $pieces[7];
$_SESSION['ticket4'] = $pieces[12];
$_SESSION['ticket5'] = $pieces[17];
$_SESSION['ticket6'] = $pieces[22];


$_SESSION['ticket11'] = $pieces1[0];
$_SESSION['ticket22'] = $pieces1[2];
$_SESSION['ticket33'] = $pieces1[7];
$_SESSION['ticket44'] = $pieces1[11];
$_SESSION['ticket55'] = $pieces1[16];
$_SESSION['ticket66'] = $pieces1[21];

}
?>
<?php
if (isset($_POST['pay'])){
if ($_POST['cash'] != $grand_total) {
echo "*Pay the given amount!"."<br>";
}
else{
header ('Location: ticket.php');
}
}
?>
<h2> Select payment method </h2>
<form action="payment.php" method="post">
<input type="radio" name="payment" id="cash" checked="checked" value="cash">
<label for="cash">Cash</label>
<input type="number" id="cash" name="cash" size="8"><br><br>


<input type="radio" name="payment" id="card" value="card">
<label for="card">Card</label>
<select>
<option>Debit card</option>
<option>Credit card</option>
</select>
<br>
<img src="Credit.jpg">
<br>
<input type="submit" name="pay" value="Make payment">
</form>
<?php 
if(isset($_POST["Continue"])){

$firstname      = $_POST['fname'];
    $lastname       = $_POST['lname'];
    $passport   = $_POST['passport'];
    $visa       = $_POST['visa'];
    $address1       = $_POST['address1'];
    $address2   = $_POST['address2'];
    $email      = $_POST['email'];
    $contact        = $_POST['contact'];
    $pin    = $_POST['pin'];




    mysql_query( "INSERT INTO passengers (first_name,last_name,passport,visa,address1,address2,email,contact,pin) VALUES('$lastname','$passport','passport','$visa','$address1','$address2','$email','$contact','$pin')");

}

?>

我无法将数据连接到wampserver中phpadmin的mysql数据库。它没有任何表现。正如你在下面看到的那样,我的许多尝试中的一个尝试纠正,使其失败。不是我试过的方法没有工作。请帮助解决这个问题

1 个答案:

答案 0 :(得分:0)

似乎你搞砸了价值表:

mysql_query( "INSERT INTO passengers  
(first_name,last_name,passport,visa,address1,address2,email,contact,pin)
   VALUES
  ('$lastname','$passport','passport','$visa','$address1','$address2','$email','$contact','$pin')");  

缺少名字,'护照'不应该在那里,等等。应该是:

('$firstname','$lastname','$passport','$visa','$address1','$address2','$email','$contact','$pin')");