0
    $name = $_GET['fullname'];
    $phone = $_GET['phone'];
    $address = $_GET['address'];
    $size = $_GET['size'];
    $toppings = $_GET['toppings'];
    $delivery = $_GET['type'];



    mysql_connect ("localhost", "root", "") or die ('Error: ' . mysql_error());
    mysql_select_db ("pizzaorders");
    $query ="INSERT INTO orders (fullname, phone, address, size, toppings, delivery)  VALUES ('".$name."', '".$phone."', '".$address."','".$size."','".$toppings."','".$delivery.")";
    $done=mysql_query($query);
    echo $done;        

    $total = 0;
    $total = sizecost()  + deliverycost() + toppingcost();

    echo " $name  your {$_GET["size"]} pizza will come in 45 minutes.";
    echo "Total: $ $total";
    echo " Your Toppings are ";
    foreach($toppings as $topping) {
    echo $topping  ;
     }
    echo "Your Delivery Type:{$_GET["type"]}";
    echo "Database Updated";

    function sizecost() {
        $size = 0;
        if ($_GET['size'] == "Small"){
            $size+=5;

        }
        else if ($_GET['size'] == "Medium"){
            $size+=10;

        }
        else if ($_GET['size'] == "Large"){
             $size+=15;
        }
         return $size;


    }

   function toppingcost() {
        $toppings = $_GET['toppings'];

        foreach($toppings as $topping) {
         $topping=1;    
         $topping=$topping+1; 
     }
        return $topping;
    }

    function deliverycost() {
        $deliverycost = 0;
        if ($_GET['type'] == "delivery") {
            $deliverycost += 5;
        }
        return $deliverycost;
    }
3
  • What do you mean "not entering"? Is there an error or is the data just not showing up? Commented Apr 21, 2011 at 12:46
  • any error? any more precise question? Commented Apr 21, 2011 at 12:47
  • But its not giving such error. Its just goes fine but I don't see any entries in database. Commented Apr 21, 2011 at 12:48

6 Answers 6

8

Last value is missing a single quote at the end.

Sign up to request clarification or add additional context in comments.

Comments

2

Use echo mysql_error after mysql_query

Comments

2

IMPORTANT

You MUST use mysql_real_escape_string() to protect against [my]sql injection.

2 Comments

And simply to handle any strings that actually contain quotation marks.... eg I like "Kickin' Cajun Chicken" topping on my pizza
I agree - and to protect against tasty pizzas as well. :-]
2

You can save a lot of effort with using PDO;

$db = new PDO('mysql:host=localhost;dbname=pizzaorders', "root", "");

$query = $db->prepare("INSERT INTO orders
           (fullname, phone, address, size, toppings, delivery)
           VALUES (?,?,?,?,?,?)");
$query->execute(array($name, $phone, $address, $size, $toppings, $delivery));

Or you can just use the $_GET[] variables there.

Comments

0

first you could print the erros on the screen so you know what's wrong

$done=mysql_query($query) or die(mysql_error());

and second, you are missing a quote at the end

,'".$delivery.")"; should be ,'".$delivery."')";

Edit:

to answer your second question:

I don't think you can use $_GET['type'] inside a function

better to get the type outside a function and then pass it as a parameter, like follow:

$type = mysql_real_escape_string($_GET['type']);
deliverycost($type);

and in your function

function deliverycost($type) 
{
      if(empty($type))
      {
            //throw error, type cannot be empty
      }
        $deliverycost = 0;
        if ($type == "delivery") {
            $deliverycost += 5;
        }
        return $deliverycost;
    }

2 Comments

fixed it! thanks. One more thing something is going wrong with deliverycost() too.
sorry forgot to mention I answered your second question in my answer above
0

Make sure you escape the single quotes like:

mysql_real_escape_string($name)

The query would be:

$query ="INSERT INTO orders (fullname, phone, address, size, toppings, delivery) 
VALUES ('".mysql_real_escape_string($name)."', '".mysql_real_escape_string($phone)."', '".mysql_real_escape_string($address)."','".mysql_real_escape_string($size)."','".mysql_real_escape_string($toppings)."','".mysql_real_escape_string($delivery)."')";

Also echo the query to see what query is being sent to the database.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.