If someone could just talk to me and maybe point me in a direction. I work better if I have someone who understands it guiding me that I can talk to. Im not asking for it to be done for me. Thank you
The array below represents the item number of the items a small company has in stock.
$inventory = array ("ABC123X","TWX325R","NPR779N","PUY343S","MIS394A","RSE874W","WER343P");
Form:
Write an HTML form that accepts a single text input of an inventory number.
(ALREADY DONE: Will be using $item = $_POST["item"]; in the script
PHP Script: Write a PHP script that searches the array.
If the item is in stock (is in the array), print the item in stock message.
If the item is not in stock (not in the array), print the item not in stock message.
Hints:
Use a foreach loop to search your array for the data sent to you by the user. Use a sequential search. (eg: Compare the first item, then the next, then the next, until you find the item you are seeking.)
You will need to nest an if-statement in your loop since not every item will be a match.
Create a flag variable that tracks whether or not an item is found. Set $flag = false at the beginning of your program. Set $flag to true ONLY if the item is found. At the end of your program, test $flag to determine whether or not you need to display the item not in stock message.
I have the following which is bits and peices but I am trying to figure out how to put it all together. I am basically doing this on my own with little information and have tried googling it
<?php
$item = $_POST["item"];
$inventory = array("ABC123X","TWX325R","NPR779N","PUY343S","MIS394A","RSE874W","WER343P")
$flag = false
foreach ($item as $inventory)
if ($flag == true)
print "<font size=+3><b>ACME Hardware Store</b></font><br><br>";
print "We have item $item in stock! Feel free to contact us for more info.";
else
if ($flag == false)
print "<font size=+3><b>ACME Hardware Store</b></font><br><br>";
print "That item not in inventory! Please contact us if you would like to special order it.";
?>
ifandforeachsyntax is incorrect and should trigger a error (why did not you mention it?). Read ru2.php.net/manual/en/control-structures.if.php + ru.php.net/manual/en/control-structures.foreach.php more carefullyhomeworktag. And you can read howforeachworks in the link I gave above.if(x == true), just writeif($flag)that is enough... lol don't need to OVER compare, yourifends up beingif(true). You are doing this right now:if(true == true)