Inserting into MySQL Newbie


Posted on 16th Feb 2014 07:03 pm by admin

Hi ive got a slight problem where ive made a simple web form where the customer inserts the ammount of tickets and then enters their personal details... then this form does the post method and it then comes up with the confirmation page with all the calculations and how much it is going to cost including postage... All that works fine... When i press the send button to send it to the database and give a message 'order recieved' i get this error...

'Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order (qty_child,qty_adult,adult_cost,child_cost, postage,c_name, h_name, town, ' at line 1'

Right heres the code for the First page
Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Buy your tickets</title>
</head>

<body>
<form action="includes/confirm.php" method="post">
Adult Ticket:
<br />
Quantity:<input type="text" size="5" name="qty_adult" id="Adult Ticket" /> <br /><br />

<div>
Child Ticket:
<br />
Quantity:<input type="text" size="5" name="qty_child" id="Child Ticket" /> <br /><br />
</div>

<div>
Customer Details:
<br />
Name:<br /><input type="text" size="50" name="c_name" id="Customer Name" /> <br /><br />
House Name / Number:<br /><input type="text" size="50" name="h_name" id="House Name" /> <br /><br />
Town:<br /><input type="text" size="50" name="town" id="Town Name" /> <br /><br />
County:<br /><input type="text" size="50" name="county" id="County" /> <br /><br />
Post Code:<br /><input type="text" size="50" name="p_code" id="Post Code" /> <br /><br />
Email Address:<br /><input type="text" size="50" name="email" id="Email" /> <br /><br />
Phone Number:<br /><input type="text" size="50" name="p_num" id="Phone Number" /> <br /><br />
</div>

<input type="submit" />
</form>
</body>
</html>
Heres my confirmation page:
Code: <title>Order Confirmation</title>
<form action="send.php" method="post">
<?php
include("helper.php");

/* DISPLAY THE OUTPUT
======= === ======*/

# Display Adult Order
if ($qty_adult > 0 )
{
echo "You ordered ". $qty_adult . " adult tickets.<br />";
echo "The cost of the tickets is £" .number_format ($calcItem,2) . "<br />";
echo "and the postage is £" .number_format ($calcPost,2) . "<br /><br />";

if ($qty_child == 0)
{
echo "Which gives you a total of £" .number_format ($calcTotal,2) . "<br /><br /> ";
}
}


# Display Child Order
if ($qty_child > 0 )
{
echo "You ordered ". $qty_child . " child tickets.<br />";
echo "The cost of the tickets is £".number_format ($calcChild,2) . "<br />";
echo "and the postage is £".number_format ($calcChildPost,2) ."<br /><br/>";

echo "Which gives you a total of £" .number_format ($calcAll,2) . "<br /> ";
}

# If nothing is ordered

if ($qty_child && $qty_adult = 0)
{
echo "Please choose the ammount of tickets you require before carrying on";
}

echo "<br/>";
echo "Name : " .$c_name ;
echo "<br/>";
echo "House name / Number: " .$h_name ;
echo "<br/>";
echo "Town: " .$town ;
echo "<br/>";
echo "County: " .$county ;
echo "<br/>";
echo "Post Code: " .$p_code ;
echo "<br/>";
echo "Email: " .$email ;
echo "<br/>";
echo "Phone Number: " .$p_num ;
echo "<br/>";
echo "<br/>";
?>
<input type="submit" />

</form>
Heres my helper file with all the calculations and what not:
Code: <?php
# Calculation VARS
$qty_adult = $_POST['qty_adult'];
$qty_child = $_POST['qty_child'];
$a_ticket = $_POST['a_ticket'];
$c_ticket = $_POST['c_ticket'];
$a_price = 25;
$c_price = 0;
$p_price = 1.50;
$calcItem = totalItem($qty_adult, $a_price);
$calcPost = totalPost($qty_adult, $p_price);
$calcTotal = total($calcItem, $calcPost);
$calcChildPost = totalChildPost ($qty_child, $p_price);
$calcAll = totalAll ($calcItem,$calcChildPost,$calcPost);
$calcChild = totalChild ($qty_child, $c_price);

# Customer Detail Input VARS
$c_name = $_POST['c_name'];
$h_name = $_POST['h_name'];
$town = $_POST['town'];
$county = $_POST['county'];
$p_code = $_POST['p_code'];
$email = $_POST['email'];
$p_num = $_POST['p_num'];


/* FUNCTIONS
=========*/

# Calculates the Item total for the adults
function totalItem($price, $qty)
{
$totalItem = ($price * $qty);
return $totalItem;
}

# Calculates the Postage total for the adults
function totalPost($postage, $qty)
{
$totalPost = ($postage * $qty);
return $totalPost;
}

# Calculates the Order Total for the adults
function total($item, $post)
{
$total = ($item + $post);
return $total;
}

# Calculates the Order Total for childrens
function totalChildPost($childQty, $childPost)
{
$totalChildPost = ($childQty * $childPost);
return $totalChildPost;
}

# Calculates the Order Total for childrens
function totalChild($childQty, $childCost)
{
$totalChild = ($childQty * $childCost);
return $totalChild;
}

# Calculates the Order Total
function totalAll($adult, $child, $postA)
{
$totalAll = ($adult + $child + $postA );
return $totalAll;
}
?>
And lastly and the most problematic is the sql :
Code: <?php
include("helper.php");
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}


mysql_select_db("tickets", $con);

# Order
$sql=
"INSERT INTO order (qty_child,qty_adult,adult_cost,child_cost, postage,c_name, h_name, town, county, p_code, email, p_num)
VALUES
('$_POST[qty_child]','$_POST[qty_adult]','$_POST[calcItem]','$_POST[calcChild]','$_POST[calcAll]','$_POST[c_name]', '$_POST[h_name]', '$_POST[town]', '$_POST[county]', '$_POST[p_code]', '$_POST[email]', '$_POST[p_num])";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Order Recieved";

mysql_close($con)
?>


Any help would be greatfull... Or if someone could point me in the right direction that would be great....

Thanks

Posted on 07th May, 2017
amartinelltyish
[b]robes de Herve Leger[/b]
[b][url=http://fr.hervelegerbandagedresses.net/]herve leger[/url][/b]
[b]vêtements ralph lauren pas cher[/b]

[b][url=http://fr.hervelegerbandagedresses.net/]robes de Herve Leger[/url][/b]
[b]herve leger[/b]
[b][url=http://fr.hervelegerbandagedresses.net/]vêtements ralph lauren pas cher[/url][/b]

[b][url=http://fr.hervelegerbandagedresses.net/]robes Herve Leger pas cher[/url][/b]
[b][url=http://fr.hervelegerbandagedresses.net/]Robes de bandage en ligne[/url][/b]


Leger blog

[url=http://tiffany3102.webs.com] Leger [/url]

[url=http://buymoncler61.webs.com] About blog [/url]
Posted on 17th May, 2017
amartinelltyish

[b][url=http://www.jimmychooboots.top/jimmy-choo-flats-c-5.html]Sale Jimmy Choo Flats shoes[/url][/b]
[b][url=http://www.jimmychooboots.top/jimmy-choo-flats-c-5.html]Jimmy Choo Sandy Glitter Fabric Flats shoes[/url][/b]
[b][url=http://www.jimmychooboots.top/jimmy-choo-flats-c-5.html]Jimmy Choo Sandy Patent Leather Flats shoes[/url][/b]








[url=http://authenticchristianlouboutinonsale1.webs.com] Choo blog [/url]

[url=http://monclerkieds34.webs.com] Wedges [/url]

[url=http://tiffanyjewelry789.webs.com] About jimmychooboots.top blog [/url]

Your Answer:

Login to answer
233 Like 36 Dislike
Previous forums Next forums
Other forums

Help with form post data and arrays
Hi all,

I am new to this forum... It has been awhile since i have worked with arrays, and i a

shift numbers with paging
Hi

How would i be able to display 10 numbers 1 2 3 4 5 6 7 8 9 10
and when I click next

Send current URL in URL with a $_GET variable problem.
Hello community,

I have created a function that gets the current variable of a page, example:

Creating a custom API
I'm creating a site, and I need to create a basic API. Unfortunately I have no idea where to start.

Forms Authentication and Refresh at Login page
Hello, When I try to press the Login button in my webapplication at my login.aspx page nothing h

grouping within a foreach?
hello all,

I currently have a list of products spit out from my db via a foreach loop. Right

asking for direction
I have 2 tables in my data, which are "post" and "event"
I won't make a summa

Php script to read msword file
hi,

I need to read a msword file and i want to print the contents in that word file.

i

help finding hacking loopholes
i was attacked by a redirect php injection

my pc is clean of viruses

so i figure that

PHP hyperlinks generator - HELP plz
Hi

I need some help to get this done using php:


1 - I have few hyperlinks say 500

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash