0

here are is the code.no matter what i did couldnt connect to mysql database in phpadmin in the wampserver all attempts has failed please help to solve

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')");

}

?>

i couldnt connect the data to mysql database in the phpadmin in the wampserver. it shows up nothing. as you can see below one of my many attempt to correct to make it work it up as fail. non of the method that i tried didnt work. please help to sove this problem

  • Your script is at risk of [SQL Injection Attack](//stackoverflow.com/questions/60174) Have a look at what happened to [Little Bobby Tables](http://bobby-tables.com/) Even [if you are escaping inputs, its not safe!](//stackoverflow.com/questions/5741187) Use [prepared parameterized statements](https://php.net/manual/en/mysqli.quickstart.prepared-statements.php). – John Conde May 23 '18 at 18:24
  • Too much code. You can remove a lot of this code which is not necessary to troubleshoot the question. – John Conde May 23 '18 at 18:24
  • And if you can't connect in phpmyadmin then this isn't a coding issue. It's a mysql or server issue. – John Conde May 23 '18 at 18:25
  • other tables are working fine but only the passenger table – stackdroid May 23 '18 at 18:26
  • FYI, [you shouldn't use `mysql_*` functions in new code](http://stackoverflow.com/questions/12859942/). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [red box](http://php.net/manual/en/function.mysql-connect.php)? Learn about [*prepared statements*](https://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide which one is best for you. – John Conde May 23 '18 at 18:27
  • You don't know what's wrong because you don't check for errors in your code. Never assume the code is always going to work flawlessly. Use [`mysql_error()`](http://php.net/manual/en/mysql.error.php) to get a detailed error message from the database. – John Conde May 23 '18 at 18:27
  • there is no error showing in the table. other tables are working fine – stackdroid May 23 '18 at 18:30
  • i need to know how to connect $register_data2 array into the database – stackdroid May 23 '18 at 18:31
  • Could you tell the error code and error message? – Eperbab May 23 '18 at 18:48
  • there is no error code or error message the problem couldnt connect this data array into mysql – stackdroid May 23 '18 at 18:50

1 Answers1

0

It seems you messed up the values list:

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')");  

First name is missing, 'passport' should not be there, etc. It should be:

('$firstname','$lastname','$passport','$visa','$address1','$address2','$email','$contact','$pin')");  
Eperbab
  • 378
  • 4
  • 13