make form work with mysql and php

Hiya hope you guys can help me once again


yes i know php has changed ...   but how to i write a php page to accept details from this form in a mysql database -


thanks in advance

<?php 
	include('profile/validate.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>cs97jjm3 Fantasy F1</title>

<!--[if (gt IE 9)|!(IE)]><!-->
<script src="js/jquery.mobile.customized.min.js"></script>
<!--<![endif]-->
<script>
 $(window).load(function(){
  $().UItoTop({ easingType: 'easeOutQuart' });
  $('.gallery .gall_item').touchTouch();
 });
 $(document).ready(function(){
     jQuery('#camera_wrap').camera({
      loader: false,
      pagination: true ,
      minHeight: '500',
      thumbnails: false,
      height: '22.42708333333333%',
      caption: true,
      navigation: false,
      fx: 'mosaic'
    });
    $('.gallery .gall-item').touchTouch();
  });
</script>
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<link href="css/ie.css" media="screen" rel="stylesheet" />
<![endif]-->
<style>
 margin-top: 100px;
 margin-bottom: 100px;
 margin-right: 150px;
  margin-left: 80px;
  </style>

</head>
<body style="background-color: #FFFFFF; background-image: url('../images/main_texture.png'); margin-top: 80px;
 margin-bottom: 100px;
 margin-right: 150px;
  margin-left: 180px;">
<div class="texture">
<!--==============================
              header
=================================-->
<h2 class="ta__left">
<div class="ta__left">
	Register Have you read the 
	<a href="http://f1cs97jjm3.ddns.net/F1/?page_id=680" target="_parent"><strong>rules</strong></a>?,
			</div>
			<span lang="en-gb">Please Note: one team per email address </span>
			<h2 class="ta__left">Entry Form </h2>
<form id="form1"  class="pure-form pure-form-stacked" method="post" name="form1">
<fieldset>

<label for="Email">Email&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </label>
<input id="Email" name="Email" placeholder="Email Address" required="" type="text" maxlength="50" />
<br class="clear" />
<label for="FullName"><br />Full Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </label>
<input id="FullName" name="FullName" placeholder="Your Name" required="" type="text" maxlength="25" />
<label for="TeamName"><br /><br />Team Name&nbsp; </label>
<input id="TeamName" name="TeamName" placeholder="Your F1 Team Name" required="" type="text"  maxlength="25"/>
<label for="Password"><br /><br />Password&nbsp;&nbsp;&nbsp;&nbsp; </label>
<input id="Password" name="Password" placeholder="enter Password" required="" type="password" maxlength="12"  />
<button type="button" id="eye" title = "click here to see your password" data-toggle="tooltip" >
    <img src="https://cdn0.iconfinder.com/data/icons/feather/96/eye-16.png" alt="eye" />
</button>

<br /><br class="clear" />
<label for="Driver1">Select 1st Driver </label>

<select id="Driver1" class="select-sum" name="Driver1" required="" onchange="updateSelect(this,'Driver2');" >
<option data-id="30" value=" 1   Lewis Hamilton  ">Lewis Hamilton  30 Million </option>
<option data-id="25" value=" 822 Valtteri Bottas "> Valtteri Bottas 25 Million </option>
<option data-id="28" value=" 20  Sebastian Vettel ">Sebastian Vettel 28 Million </option>
<option data-id="22" value=" 844 Charles Leclerc ">Charles Leclerc 22 Million </option>
<option data-id="22" value=" 999 Max Verstappen ">Max Verstappen 22 Million </option>
<option data-id="18" value=" 842 Pierre Gasly">Pierre Gasly 18 Million </option>
<option data-id="14" value=" 817 Daniel Ricciardo ">Daniel Ricciardo 14 Million </option>
<option data-id="13" value=" 807 Nico Hulkenberg ">Nico Hulkenberg 13 Million </option>
<option data-id="12" value=" 154 Romain Grosjean ">Romain Grosjean 12 Million </option>
<option data-id="12" value=" 825 Kevin Magnussen  ">Kevin Magnussen 12 Million </option>
<option data-id="10" value=" 839 Lando Norris">Lando Norris 10 Million </option>
<option data-id="10" value=" 832 Carlos Sainz Jr  ">Carlos Sainz Jr 10 Million </option>
<option data-id="9" value=" 815 Sergio Perez Mendoza ">Sergio Perez Mendoza 9 Million </option>
<option data-id="9" value=" 840 Lance Stroll ">Lance Stroll 9 Million </option>
<option data-id="15" value=" 8   Kimi Raikkonen ">Kimi Raikkonen 15  Million </option>
<option data-id="7" value=" 845 Antonio Giovinazzi ">Antonio Giovinazzi  7 Million </option>
<option data-id="6" value=" 4   Alexander Albon ">Alexander Albon 6 Million </option>
<option data-id="6" value=" 838 Daniil Kvyat ">Daniil Kvyat 6 Million </option>
<option data-id="5" value=" 828 George Russell ">George Russell 5 Million </option>
<option data-id="5" value=" 843 Robert Kubica  ">Robert Kubica 5 Million </option>


</select> <br /><br class="clear" />
<label for="Driver2">Select 2nd Driver</label>
<select id="Driver2" class="select-sum" name="Driver2" required="" onchange="updateSelect(this,'Driver1');" >
<option data-id="30" value=" 1   Lewis Hamilton  ">Lewis Hamilton  30 Million </option>
<option data-id="25" value=" 822 Valtteri Bottas "> Valtteri Bottas 25 Million </option>
<option data-id="28" value=" 20  Sebastian Vettel ">Sebastian Vettel 28 Million </option>
<option data-id="22" value=" 844 Charles Leclerc ">Charles Leclerc 22 Million </option>
<option data-id="22" value=" 999 Max Verstappen ">Max Verstappen 22 Million </option>
<option data-id="18" value=" 842 Pierre Gasly">Pierre Gasly 18 Million </option>
<option data-id="14" value=" 817 Daniel Ricciardo ">Daniel Ricciardo 14 Million </option>
<option data-id="13" value=" 807 Nico Hulkenberg ">Nico Hulkenberg 13 Million </option>
<option data-id="12" value=" 154 Romain Grosjean ">Romain Grosjean 12 Million </option>
<option data-id="12" value=" 825 Kevin Magnussen  ">Kevin Magnussen 12 Million </option>
<option data-id="10" value=" 839 Lando Norris">Lando Norris 10 Million </option>
<option data-id="10" value=" 832 Carlos Sainz Jr  ">Carlos Sainz Jr 10 Million </option>
<option data-id="9" value=" 815 Sergio Perez Mendoza ">Sergio Perez Mendoza 9 Million </option>
<option data-id="9" value=" 840 Lance Stroll ">Lance Stroll 9 Million </option>
<option data-id="15" value=" 8   Kimi Raikkonen ">Kimi Raikkonen 15  Million </option>
<option data-id="7" value=" 845 Antonio Giovinazzi ">Antonio Giovinazzi  7 Million </option>
<option data-id="6" value=" 4   Alexander Albon ">Alexander Albon 6 Million </option>
<option data-id="6" value=" 838 Daniil Kvyat ">Daniil Kvyat 6 Million </option>
<option data-id="5" value=" 828 George Russell ">George Russell 5 Million </option>
<option data-id="5" value=" 843 Robert Kubica  ">Robert Kubica 5 Million </option>

</select> 
<br /><br class="clear" />
<label for="Team1">Your Constructor </label>
<select class="select-sum" id="Team1" name="Team1" required="">
<option data-id="30" value="131 Mercedes ">Mercedes AMG Petronas Motorsport 30 Million </option>
<option data-id="22" value="6   Ferrari  ">Scuderia Ferrari Mission Winnow 22 Million </option>
<option data-id="20" value="9   Red Bull  ">Aston Martin Red Bull Racing 20 Million </option>
<option data-id="15" value="4   Renault  ">Renault F1 Team 15 Million </option>
<option data-id="14" value="210 Haas ">Rich Energy Haas F1 Team 14 Million </option>
<option data-id="13" value="1   McLaren ">McLaren F1 Team 13 Million </option>
<option data-id="12" value="10  Racing Point  ">Racing Point F1 Team 12 Million </option>
<option data-id="11" value="15  Alfa Romeo Racing  ">Alfa Romeo Racing 11 Million </option>
<option data-id="11" value="5   Toro Rosso  ">Red Bull Toro Rosso Honda 11 Million </option>
<option data-id="10" value="3   Williams  ">Williams Martini Racing 10 Million </option>




</select> <br />


<br /><label for="MyRaceId">Double Points Race&nbsp;&nbsp;&nbsp;&nbsp; </label>
<select id="MyRaceId" name="MyRaceId" required="">
<option value="989 Australian Grand Prix">Australian Grand Prix</option>
<option value="990 Bahrain Grand Prix">Bahrain Grand Prix</option>
<option value="991 Chinese Grand Prix">Chinese Grand Prix</option>
<option value="992 Azerbaijan Grand Prix">Azerbaijan Grand Prix</option>
<option value="993 Spanish Grand Prix">Spanish Grand Prix</option>
<option value="994 Monaco Grand Prix">Monaco Grand Prix</option>
<option value="995 Canadian Grand Prix">Canadian Grand Prix</option>
<option value="996 French Grand Prix">French Grand Prix</option>
<option value="997 Austrian Grand Prix">Austrian Grand Prix</option>
<option value="998 British Grand Prix">British Grand Prix</option>
<option value="999 German Grand Prix">German Grand Prix</option>
<option value="1000Hungarian Grand Prix">Hungarian Grand Prix</option>
<option value="1001Belgian Grand Prix">Belgian Grand Prix</option>
<option value="1002Italian Grand Prix">Italian Grand Prix</option>
<option value="1003Singapore Grand Prix">Singapore Grand Prix</option>
<option value="1004Russian Grand Prix">Russian Grand Prix</option>
<option value="1005Japanese Grand Prix">Japanese Grand Prix</option>
<option value="1007Mexican Grand Prix">Mexican Grand Prix</option>
<option value="1006United States Grand Prix">United States Grand Prix</option>
<option value="1008Brazilian Grand Prix">Brazilian Grand Prix</option>
<option value="1009Abu Dhabi Grand Prix">Abu Dhabi Grand Prix</option>

</select> 

<br class="clear" />
<input id="Amount" name="Amount" placeholder="Your F1 Team Name" required="" type="hidden" size="3" hidden /><br>
<h1>Tie-Break </h1>
<label for="LewisEndofyearPosition">Lewis Hamilton's championship position at the end of year&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </label>
<select id="LewisEndofyearPosition" name="LewisEndofyearPosition">
<!--	<label for="LewisEndofyearPosition"><br>Postion for Lewis at end of year </label><select name="LewisEndofyearPosition" id="LewisEndofyearPosition" required>
-->
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
</select> <br /><br class="clear" />
<label for="Total">The constructor who wins the most pole positions in qualifying&nbsp;<br></label><select id="Total" name="Total" required="">
<option  value="131 Mercedes ">Mercedes AMG Petronas Motorsport  </option>
<option  value="6   Ferrari  ">Scuderia Ferrari Mission Winnow </option>
<option value="9   Red Bull  ">Aston Martin Red Bull Racing  </option>
<option  value="4   Renault  ">Renault F1 Team  </option>
<option  value="210 Haas ">Rich Energy Haas F1 Team  </option>
<option  value="1   McLaren ">McLaren F1 Team  </option>
<option  value="10  Racing Point  ">Racing Point F1 Team  </option>
<option  value="15  Alfa Romeo Racing  ">Alfa Romeo Racing  </option>
<option  value="5   Toro Rosso  ">Red Bull Toro Rosso Honda  </option>
<option  value="3   Williams  ">Williams Martini Racing  </option>
</select> <br class="clear" /><br />
<!--<input type="text" name="MyRaceId" id="MyRaceId" required/>-->

 
  <!-- Latest compiled and minified JavaScript -->
<h3>Your Total is Spend in Millions is  <div id="result"> </div> </h3> 

<button type="submit" value="Submit Team" class="btn" id="submit-button">Submit</button>

	
	


 <p></p>
</fieldset>
			</form>
		</div>
	</div>
	
	
	
	<!--==============================
              footer
=================================-->
    </div>

</section>
</div>
<footer id="footer">


<div class="copyright"> 
      </div>
    </div>
  </div>
  <div class="clear"></div>
</footer>
<a id="toTop" class="fa fa-chevron-up" href="#"></a>
<script src="js/isotop_ini.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script>
$(function() {
  setScore();
  $('.select-sum').change(function() {
	setScore();
  });
});
function setScore()
{
    var total = 0;
    $('.select-sum').each(function() {
      var sel = $(this).find('option:selected').data('id');
      total += sel;
    });

    // Set a boolean based on score < 45
    // this is used to set the disabled state
    // without using an if statement
    var disabled = total > 48;

    // because not all submit buttons are <input>'s
    // use the disabled status above to set disabled state
    $('#submit-button').prop({disabled: disabled});
	

    $('#result').html(total);
    var my_txt = $('#result').text(); 
	$("input[name='Amount']").val(my_txt);
}
</script>

<script>
function updateSelect(changedSelect, selectId) {
   var otherSelect = document.getElementById(selectId);
   for (var i = 0; i < otherSelect.options.length; ++i) {
       otherSelect.options[i].disabled = false;
   }
   if (changedSelect.selectedIndex == 0) {
      return;
   }
   otherSelect.options[changedSelect.selectedIndex].disabled = true;
}</script>

<script>
function show() {
    var p = document.getElementById('Password');
    p.setAttribute('type', 'text');
}

function hide() {
    var p = document.getElementById('Password');
    p.setAttribute('type', 'password');
}

var pwShown = 0;

document.getElementById("eye").addEventListener("click", function () {
    if (pwShown == 0) {
        pwShown = 1;
        show();
    } else {
        pwShown = 0;
        hide();
    }
}, false);
</script>
</body>
</html>
	

Open in new window

LVL 31
James MurrellProduct SpecialistAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
When you submit a <form>, the data contained within that form is sent to the script identified by the action attribute. If your form's method is POST, then the data is available to the script in the $_POST array. You would use that to insert data into your DB.

Here's a quick example to get you started. Let's assume a very simple HTML form

<form method="post" action="update.php">
    <input type="text" name="firstname" placeholder="Enter your first name">
    <input type="text" name="lastname" placeholder="Enter your last name">
    <input type="submit" value="Send the Form">
</form>

Open in new window

We've set the action to POST, and when the submit button is clicked it will send the data to the update.php script. That script can access the data by using the POST array, using the name of the field as the key:

$_POST['firstname']
$_POST['lastname']

Here's a very quick example of how you would go about your PHP scripts. First off, create a file to contain your DB connection info. Let's call it db.php

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);
 
$username = 'yourUsername';
$password = 'yourPassword';
$dsn      = 'mysql:host=localhost;dbname=yourDbName;charset=utf8mb4'; 
$options  = [
    PDO::ATTR_EMULATE_PREPARES   => false,
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
];

try {
    $db = new PDO($dsn, $username, $password, $options);
} catch( PDOException $e ) {
    die( $e->getMessage() );
}

Open in new window

Now create your update.php script:

// connect to your DB
require_once 'db.php';

// safely check you have some values from your form
$firstname = isset( $_POST['firstname'] ) ? $_POST['firstname'] : "";
$lastname = isset( $_POST['lastname'] ) ? $_POST['lastname'] : "";

// get your SQL query ready. We're using a parameterised query here for security!
$sql = "INSERT INTO yourTable (`firstname`, `lastname`) VALUES ( :firstname, :lastname )";

try {

    // Prepare the query
    $insert = $db->prepare($sql);

    // Run the query
    $insert->execute([
        'firstname' => $firstname,
        'lastname' => $lastname,
    ]);

    echo "<p>Record was inserted into the DB</p>";

} catch ( Exception $e ) {

    // Something went wrong so let's bomb out with a message!
    die ( $e->getMessage() );

}

Open in new window

First off we check that the values we expect are actually passed in with the form. This prevents any UndefinedIndex errors. We assign the values from the form to local variables ($firstname / $lastname). We then write the SQL code, using named parameters (:firstname / :lastname) in place of the actual values. This prevents any SQL Injection attacks. We then wrap the preparation and actual execution of the query in to a try/catch block. This is a modern, OOP way of error handling. Inside the Try, we execute the prepared query, passing in the names of the parameters, along with the value of those parameters.

If all goes well, you'll get the Record was inserted message. If there are any problems, an Exception will be thrown and caught and the error message will be shown.
James MurrellProduct SpecialistAuthor Commented:
thanks sorry for delay. trying this tonight
James MurrellProduct SpecialistAuthor Commented:
ok thanks i have tried here is update code


<?php 

// connect to your DB
require_once 'db.php';

// safely check you have some values from your form

$Email =isset($_POST['Email']);  
$FullName =isset($_POST['FullName']);  
$Driver1 =isset($_POST['Driver1']);  
$Driver2 =isset($_POST['Driver2']);  
$Team1 =isset($_POST['Team1']);  
$LewisEndofyearPosition =isset($_POST['LewisEndofyearPosition']);  
$Amount =isset($_POST['Amount']);  
$Total =isset($_POST['Total']);  
$TeamName =isset($_POST['TeamName']);  
$Password =isset($_POST['Password']); 
$pw = md5($Password);
$MyRaceId =isset($_POST['MyRaceId']); 


// get your SQL query ready. We're using a parameterised query here for security!
$sql = "INSERT INTO f1users ( `Email`, `FullName`, `Driver1`, `Driver2`, `Team1`, `LewisEndofyearPosition`, `Amount`, `Total`, `TeamName`, `Password`, `MyRaceId`) VALUES ('$Email', '$FullName', '$Driver1', '$Driver2', '$Team1', '$LewisEndofyearPosition', '$Amount', '$Total', '$TeamName', '$pw', '$MyRaceId')";




try {

    // Prepare the query
    $insert = $db->prepare($sql);

    // Run the query
    $insert->execute([
        `Email`=> $Email,
        `FullName` => $FullName,
        `Driver1` => $Driver1, 
        `Driver2` => $Driver2,
        `Team1` => $Team1, 
        `LewisEndofyearPosition` => $LewisEndofyearPosition, 
        `Amount` => $Amount, 
        `Total` => $Total, 
        `TeamName`=> $TeamName, 
        `Password` => $pw, 
        `MyRaceId` => $MyRaceId

    ]);

    echo "<p>Record was inserted into the DB</p>";

} catch ( Exception $e ) {

    // Something went wrong so let's bomb out with a message!
    die ( $e->getMessage() );

}
?>

Open in new window


here is db code : important bits removed :-)

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);
 
$username = '?????????';
$password = '?????????????';
$dsn      = 'mysql:host=localhost;dbname=F1database;charset=utf8mb4'; 
$options  = [
    PDO::ATTR_EMULATE_PREPARES   => false,
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
];

try {
    $db = new PDO($dsn, $username, $password, $options);
} catch( PDOException $e ) {
    die( $e->getMessage() );
}
?>

Open in new window



i am getting message Record was inserted into the DB   but nothing in database ?????

feel free to see form at http://f1cs97jjm3.ddns.net/register.html

quick page of results at http://f1cs97jjm3.ddns.net/ava.php
Price Your IT Services for Profit

Managed service contracts are great - when they're making you money. Yes, you’re getting paid monthly, but is it actually profitable? Learn to calculate your hourly overhead burden so you can master your IT services pricing strategy.

Chris StanyonWebDevCommented:
OK. The code you've got doesn't really match the code I've posted. Firstly, you're never getting the data from the POST array. You have this:

$Email =isset($_POST['Email']);  

My code looked like this:

$firstname = isset( $_POST['firstname'] ) ? $_POST['firstname'] : "";

All your code does is set the $Email variable to true or false (0 or 1). My code checks to see if the POST variable is set. If it is, then it sets the variable to the value, otherwise it sets it to an empty string. It's called a ternary operator, and is a shortcut for an if/else statement. You need to change your code to use these ternary operators.

Secondly, my code is using a parameterised query. It uses named placeholders instead of the values:

INSERT INTO yourTable (col1, col2, col3) VALUES (:value1, :value2, :value3);

A place holder in a parameterised query is a name preceded by a colon, and it doesn't get wrapped in quotes. Whatever parameter names you use, you then add to the array that you pass into execute, so for the above you would have:

$update->execute([
    'value1' => $someVariable1,
    'value2' => $someVariable2,
    'value3' => $someVariable3,
]);

Also notice that the key names of an array need to be wrapped in quotes (single or double). In your code you're wrapping them in backticks! It won't work.

$insert->execute([
    `Email`=> $Email,
    `FullName` => $FullName,

Sort out those issues (have another read through my code if needed) and you should be good to go.

While you're trying to figure this stuff out and learn how it all works, it's often helpful to start with something very basic. Your HTML file is 350 lines long. Most of that just becomes white noise when you're starting out. It may be easier to just start with a simple form and a couple of fields - it helps keep you focused.
James MurrellProduct SpecialistAuthor Commented:
Thanks Chris and i really mean that: i had a major headache over this: plus a real headache for 4 days :-(

i have / i think i have done as you said  but i now get SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

<?php 

// connect to your DB
require_once 'db.php';

// safely check you have some values from your form


$Email =isset($_POST['Email']) ? $_POST['Email'] : "";  
$FullName =isset($_POST['FullName']) ? $_POST['FullName'] : "";  
$Driver1 =isset($_POST['Driver1']) ? $_POST['Driver1'] : "";  
$Driver2 =isset($_POST['Driver2']) ? $_POST['Driver2'] : "";  
$Team1 =isset($_POST['Team1']) ? $_POST['Team1'] : "";  
$LewisEndofyearPosition =isset($_POST['LewisEndofyearPosition']) ? $_POST['LewisEndofyearPosition'] : "";  
$Amount =isset($_POST['Amount']) ? $_POST['Amount'] : "";  
$Total =isset($_POST['Total']) ? $_POST['Total'] : "";  
$TeamName =isset($_POST['TeamName']) ? $_POST['TeamName'] : "";  
$Password =isset($_POST['Password']) ? $_POST['Password'] : ""; 
$pw = md5($Password);
$MyRaceId =isset($_POST['MyRaceId']) ? $_POST['MyRaceId'] : ""; 


// get your SQL query ready. We're using a parameterised query here for security!
$sql = "INSERT INTO f1users ( `Email`, `FullName`, `Driver1`, `Driver2`, `Team1`, `LewisEndofyearPosition`, `Amount`, `Total`, `TeamName`, `Password`, `MyRaceId`) VALUES (:Email, :FullName, :Driver1, :Driver2, :Team1, :LewisEndofyearPosition, :Amount, :Total, :TeamName, :Password, :MyRaceId)";


try {

    // Prepare the query
    $insert = $db->prepare($sql);

    // Run the query
    $insert->execute([
        `Email`=> $Email,
        `FullName` => $FullName,
        `Driver1` => $Driver1, 
        `Driver2` => $Driver2,
        `Team1` => $Team1, 
        `LewisEndofyearPosition` => $LewisEndofyearPosition, 
        `Amount` => $Amount, 
        `Total` => $Total, 
        `TeamName`=> $TeamName, 
        `Password` => $Password, 
        `MyRaceId` => $MyRaceId

    ]);

    echo "<p>Record was inserted into the DB</p>";

} catch ( Exception $e ) {

    // Something went wrong so let's bomb out with a message!
    die ( $e->getMessage() );

}
?>

Open in new window



sorry . hope you can help me
Chris StanyonWebDevCommented:
Ok. You're still using backticks around you array keys.  You need to be using quotes. You have this:

`Email`=> $Email

You need this

'Email'=> $Email
James MurrellProduct SpecialistAuthor Commented:
Doh Thanks it has written record to sql but with no data....??? only the submission and date added fields which are setup to auto ??? any ideas ?

sql table after insert
Chris StanyonWebDevCommented:
OK. Time to visualise the data your script is receiving. You can do this easily by using the var_dump() function. Edit your script to output the POSTed data:

<?php 
// connect to your DB
require_once 'db.php';

// visualise the data you're receiving
var_dump( $_POST );

// safely check you have some values from your form
$Email =isset($_POST['Email']) ? $_POST['Email'] : "";  
...

Open in new window

Now when you submit your form to the script, you should get a dump of the raw data that was POSTed by your form. Double check that it's correct. ** Remove the var_dump() line before you go live - it's only for testing and debugging!

One other thing of note. In your current code, you're actually trying to store the plain text password into the DB. NEVER do that. You should be using the password_hash() function:

$Password = isset($_POST['Password']) ? $_POST['Password'] : "";
$Password = password_hash( $Password, PASSWORD_DEFAULT );

Open in new window

You'd probably want to add in some logic to prevent blank passwords!

When you need to check the password, you then use the password_verify() function.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
James MurrellProduct SpecialistAuthor Commented:
Great Expert: helped me understand simple errors i was making.  Very understanding and helpful wish i could give more points
Chris StanyonWebDevCommented:
Glad I could help James :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.