(T_ENCAPSED_AND_WHITESPACE), expecting ']' Error

Hey guys, I would appreciate it if someone could help me with the following code I am using to try and insert data into a MYSQL table. I KNOW this code is not great, but its just for testing/learning. For some reason, I seem to be getting the following error:

Parse error: syntax error, unexpected ‘’ (T_ENCAPSED_AND_WHITESPACE), expecting ‘]’ in /home/gamersun/public_html/truckworld/submit.php on line 41

My code is the following:

[php]<?php
if (isset ($_POST[‘submit’])){

require_once(“includes/inc_files.php”);
$servername = “localhost”;
$username = “”;
$password = “”;
$dbname = “”;

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

mysql_select_db(“gamersun_truckworld”,$con);

$sql = “INSERT INTO jobs (username,s_loc,e_loc,distance,earnings,cargo,s_time,e_time,f_cost,m_cost,dam_trailer,dam_truck) VALUES (’$_POST[Your Name]’,’$_POST[Pick up Location]’,’$_POST[Destination]’,’$_POST[Distance]’,’$_POST[Cargo/Load]’,’$_POST[Starting Time]’,’$_POST[Earnings]’,’$_POST[Duration]’,’$_POST[Fuel Cost]’,’$_POST[Maintenance Cost]’,’$_POST[Damage % truck]’,’$_POST[Damage % trailer]’)”;

mysql_query($sql,$con);

mysql_close($con);
}
?>[/php]

Would love it if someone could lighten me up to what is going wrong, I just cant seem to work it out. Sorry if its very simple.

Thanks.

There is no point in “learning” with obsolete code. Use PDO. I have provide a free download to a PDO bumpstart database in my signauture to get you going.

Your insert variables need to be like {$_POST['Pick up Location]}

Even still, the above is not correct to do. You should never let user data go directly into your query. With PDO you will use parameterized query’s.

Thanks for the fast reply, Works fine now.

I will take a look at the PDO, Gave you a Karma :wink:

Thanks!

Sponsor our Newsletter | Privacy Policy | Terms of Service