Help create short variable names!!!

Alles, was PHP betrifft, kann hier besprochen werden.

Help create short variable names!!!

Postby CorNenad » 16. August 2012 18:33

Thank you for your help. This is the code that I wrote.
//create short variable names
$tireqty = $_POST ['tireqty'];
$oilqty = $_POST ['oilqty'];
$sparkqty = $_POST ['sparkqty'];

<title>Bob's Auto Parts - Oreder Results</title>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
echo '<p>Order processed at ';
echo date ('H:i:s, jS F Y.');
echo ' Godina';
echo '</p>';
echo '<p>You order is as follows: </p>';
echo $tireqty.' tires<br />';
echo $oilqty.' bootles oil<br />';
echo $sparkqty.' spark plugs<br />';


And this is the result.

Notice: Undefined index: tireqty in C:\xampp\htdocs\bob1.php on line 3

Notice: Undefined index: oilqty in C:\xampp\htdocs\bob1.php on line 4

Notice: Undefined index: sparkqty in C:\xampp\htdocs\bob1.php on line 5
Bob's Auto Parts

Order Results

Order processed at 10:30:48, 17th August 2012. Godina

You order is as follows:

bootles oil
spark plugs

What do we not well that the program worked. Thank you very much.
Last edited by CorNenad on 17. August 2012 10:50, edited 1 time in total.
Posts: 1
Joined: 16. August 2012 18:20
XAMPP Version: 5.6.14
Operating System: Windows 7 ultimate 64x

Re: Help create short variable names!!!

Postby Altrea » 16. August 2012 19:04

Hi CorNenad,

CorNenad wrote:Help

  • It would be much more polite if you would start new topics with a short salutation.
    This here is a community board with volunteer helpers and are maybe more willing to give you a polite help if you are polite too.
  • If you post code snippets you should use the Code-BBtags, because otherwise all your formatation/intention gets lost which will make your code much less readable.
  • Your thread topic is not really fitting your topic. Maybe that is the case because you don't know the technical terms or correct words.
    You are not registering short variable names but global variables out of superglobal variables.

Okay, now relating to your problem:

CorNenad wrote:$tireqty = $_POST ['tireqty'];
$oilqty = $_POST ['oilqty'];
$sparkqty = $_POST ['sparkqty'];

Your $_POST superglobal Array is not filled until you have send a form which uses the post method.
So either you don't have such a form (you don't showed us that form), or you haven't send it.
And without sending it PHP cannot know, what to do with your Array keys (thats what the messages are telling you).

If this form can be accessed with or without sending the form you have to use isset() or empty() to check if the Array keys are filled (or the form is send).

best wishes,
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
AF Moderator
Posts: 7281
Joined: 17. August 2009 13:05
XAMPP Version: 5.6.3
Operating System: Windows 10 Pro x64

Return to PHP

Who is online

Users browsing this forum: No registered users and 4 guests