Jump to content

PHP and MYSQL Web Development


SlinkyABC

Recommended Posts

Hi,

 

I'm not sure if this is the right place to post this but it seems to be acceptable. Please let me know if it's out of line, though.

 

I recently started learning PHP and am going through PHP and MYSQL Web Development. It seems like a pretty good book so far. Currently I'm working through the code in chapter 1 and am running into an issue.

 

From what I can tell, the code I should have at this point is as follows:

 

 

<html>

<head>

  <title>Bob's Auto Parts - Order Results</title>

</head>

<body>

<h1>Bob's Auto Parts</h1>

<h2>Order Results</h2>

<?php

  // create short variable names

  $tireqty = $_POST('tireqty');

  $oilqty = $_POST('oilqty');

  $sparkqty = $_POST('sparkqty');

 

  echo "<p>Order processed at ";

  echo date('H:i, jS F Y');

  echo "</p>";

 

  echo "<p>Your order is as follows: </p>";

  echo $tireqty.' tires<br />';

  echo $oilqty.' bottles of oil<br />';

  echo $sparkqty.' spark plugs<br /'>';

?>

 

 

</body>

</html>

 

Within the PHP script, two particular blocks of code seem to be giving me problems:

 

  $tireqty = $_POST('tireqty');

  $oilqty = $_POST('oilqty');

  $sparkqty = $_POST('sparkqty');

 

and

 

  echo "<p>Your order is as follows: </p>";

  echo $tireqty.' tires<br />';

  echo $oilqty.' bottles of oil<br />';

  echo $sparkqty.' spark plugs<br /'>';

 

Without these two blocks, the rest of the PHP executes but when I add one or both of these the PHP doesn't show up at all; instead it only executes the HTML and the output from the PHP doesn't show up. IF I remove these and only keep the "Order processed at" part of the script, that part executes fine.

 

I've gone through the code in the book and it seems like what I have is correct. As soon as I try to define or call any of the variables, it seems to break the code.

 

Any ideas? Sorry to bother you with such a basic question but I can't seem to locate a problem with this code based on what I've been taught so far.

 

Thanks!

 

Link to comment
Share on other sites

Those need to be square brackets:

$tireqty = $_POST['tireqty'];
$oilqty = $_POST['oilqty'];
$sparkqty = $_POST['sparkqty'];

Square brackets mean arrays (or strings (which are like arrays of characters, really)) while parentheses mean functions. $_POST is an array, so to get something inside it you need []s.

 

Everything else looks right.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.