Jump to content

phpnoob808

New Members
  • Posts

    9
  • Joined

  • Last visited

phpnoob808's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. users.dat looks something like this a:1:{i:0;a:3:{s:2:"ID";s:10:"phpnoob808";s:8:"password";s:11:"phpFREAK123";s:5:"email";s:18:"phpnoob808@aol.com";}}
  2. Still getting the same errors, code looked like this $hulkhamburger = array('Product' => 'Hulk Hamburger', 'Description' => '<img src="hamburger.jpg" "height=100" "width=100">', 'Price' => '$1.00', 'Quantity' => "<form name='quantity' method='post'><input type='text' name='quantity[]'></form>");
  3. I see, I'll go back to the drawing board and come back, thanks guys!!!
  4. Hi guys, Getting fruastrated on the following problem. I was wondering how do I make it so that when the user logs in, it will go through my user.dat file and if the username and password matches, it will let them log in. If not then, re enter the information. I know that it's not secure doing it this way, but it's for a simple project. I have the following so far: login.php <?php include "functions.inc"; //if the form data is clicked... if all valid.. display invoice... otherwise display error $datafile = "users.dat"; $file = file_get_contents($datafile); if(!strpos($file, "search string")) { echo ""; } if (array_key_exists('submit', $_POST)) { if(!strpos($file, "search string")) { echo ""; } header('Location: registration.php'); } else if (array_key_exists('register', $_POST)) { header('Location: invoice.php'); } ?>
  5. Hi jcbones, thank you for the response, indeed there was an error after the inputing a quantity and it said: Notice: Undefined index: quantity in C:\xampp\htdocs\assignment_2\invoice.php on line 47 Notice: Undefined index: quantity in C:\xampp\htdocs\assignment_2\invoice.php on line 47 Notice: Undefined index: quantity in C:\xampp\htdocs\assignment_2\invoice.php on line 47 Notice: Undefined index: quantity in C:\xampp\htdocs\assignment_2\invoice.php on line 47 Notice: Undefined index: quantity in C:\xampp\htdocs\assignment_2\invoice.php on line 47 and about the form, I don't know if it's because of this that's hindering the inputs too, but if you look at my products_info.inc code. The form is within the array. I did this because the form would line up nicely with the rest of the products in a table, and I'm really horrible at finding out how to line it up without the use of the array. you can find the code at the very top of my post. looks something like this: $hulkhamburger = array('Product' => 'Hulk Hamburger', 'Description' => '<img src="hamburger.jpg" "height=100" "width=100">', 'Price' => '$1.00', 'Quantity' => "<input type='text' name='quantity[]'>");
  6. Hi guys, I'm having a hard time displaying the quantity the user selects in my index.php to reflect that same exact quantity in my invoice.php page. Please help! Any suggestions will be greatly appreciated:) my product information is stored in a file called products_info.inc and looks something like this: $hulkhamburger = array('Product' => 'Hulk Hamburger', 'Description' => '<img src="hamburger.jpg" "height=100" "width=100">', 'Price' => '$1.00', 'Quantity' => "<input type='text' name='quantity[]'>"); $atomichotdog = array('Product' => 'Atomic Hot Dog', 'Description' => '<img src="hotdog.jpg" "height=100" "width=100">', 'Price' => '$2.00', 'Quantity' => "<input type='text' name='quantity2[]>"); $friedchicken = array('Product' => 'Fantastic 4 Fried Chicken', 'Description' => '<img src="friedchicken.jpg" "height=100" "width=100">', 'Price' => '$3.00', 'Quantity' => "<input type='text' name='quantity[]'>"); $psyonicpizza = array('Product' => 'Psyonic Pizza', 'Description' => '<img src="pizza.jpg" "height=100" "width=100">', 'Price' => '$4.00', 'Quantity' => "<input type='text' name='quantity[]'>"); $marvelmeatloaf = array('Product' => 'Marvel Meatloaf', 'Description' => '<img src="meatloaf.jpg" "height=100" "width=100">', 'Price' => '$5.00', 'Quantity' => "<input type='text' name='quantity[]'>"); //The following array takes our previous five arrays and puts them into one array for easier coding and reading. $allfood = array ($hulkhamburger, $atomichotdog, $friedchicken, $psyonicpizza, $marvelmeatloaf); Now my index.php looks like this: <?php //Include products info.inc (Which holds all our product arrays and info) //Credit: Tracy & Mark (Thank you!) include 'products_info.inc'; /*The following code centers the table on the page, makes the table background white, makes the table 50% of the browser window, gives it a border of 1 px, gives a padding of 2 px between the cell border and content, and gives 1 px of spacing between cells. */ echo "<table align=center bgcolor='FFFFFF' width=50% border=1 cellpadding=1 cellspacing=2>"; //Credit: Tracy & Mark (Thank you!) echo '<th>Product</th> <th>Description</th> <th>Price</th> <th>Quantity</th>'; //The following code loops through the whole table body and then prints each row. for($i=0; $i<count($allfood); $i++) { //Credit: Tracy & Mark (Thank you!) echo "<tr align=center>"; echo "<td>{$allfood[$i]['Product']}</td>"; echo "<td>{$allfood[$i]['Description']}</td>"; echo "<td>{$allfood[$i]['Price']}</td>"; echo "<td>{$allfood[$i]['Quantity']}</td>"; echo "</tr>"; } //This code ends the table. echo "</table>"; echo "<br>"; ?> The problem arises when I enter any quantity in my index after pressing submit, it goes to this following invoice.php and does not display the quantity that was inputed from the index <?php //Include products info.inc (Which holds all our product arrays and info) //Credit: Tracy & Mark (Thank you!) require 'products_info.inc'; //Display the invoice & 'WELCOME USER. THANK YOU FOR USING THIS DAMN THING msg' /*The following code centers my invoice table on the page, makes the table background white, makes the table 50% of the browser window, gives it a border of 1 px, gives a padding of 2 px between the cell border and content, and gives 1 px of spacing between cells. */ echo "<table align=center bgcolor='FFFFFF' width=50% border=1 cellpadding=1cellspacing=2>"; echo "<tr>"; echo "<td align=center><b>Product</b></td>"; echo "<td align=center><b>Quantity</b></td>"; echo "<td align=center><b>Price</></td>"; echo "<td align=center><b>Extended Price</b></td>"; echo "</tr>"; for($i=0; $i<count($allfood); $i++) { //Credit: Tracy & Mark (Thank you!) $qty= @$_POST['quantity']['$i']; // This calculates the price if the user orders more than 1 item. $extendedprice = $qty*$allfood[$i]['Price']; echo "<tr>"; echo "<td align=center>{$allfood[$i]['Product']}</td>"; echo "<td align=center>$extendedprice</td>"; echo "<td align=center>{$allfood[$i]['Price']}</td>"; echo "</tr>"; } // The goal here was to make it so that if the user selected a certain quantity from index.php, it would carry over and display on the invoice.php if ($qty == 0) { $quantityErr = "<BR><span style='color:red'>Please go back and input a quantity.</spand></BR>"; } elseif ($qty > 0) { echo $qty; } /*echo "<tr>"; echo "<td align=center>Subtotal</b></td>"; echo "<td align=center></td>"; echo "<td align=center></td>"; echo "<tr>"; echo "<td align=center>Tax at 5.75%</td>"; echo "<td align=center></td>"; echo "<td align=center></td>"; echo "<tr>"; echo "<td align=center><b>Grand total</b></td>"; echo "<td align=center></td>"; echo "<td align=center></td>"; */ echo "</table>"; ?> I bolded the items that might be of question, but then again, I'm new to PHP:( Thank you in advance folks!
  7. Thank you so much for the $temp function. We didn't go over it in class. :/
  8. Thank you so much for explaining why the value of $a just disappeared! As far as putting the value somewhere temporarily I'll tinker with the code somemore. Thanks.
  9. Hi Folks! I'm new to the forums and the PHP language. This will be my new home for my programming career, so I hope to learn a lot here. Anyway, I have a head scratcher. $a = <YOUR FIRST NAME>; $b = <YOUR LAST NAME>; $a = $b; $b = $a; echo 'Name (last, first)'.$a.','.$b; The above program tries to swap the values assigned to the variables $a and $b in order to display your name in the format <last>, <first>. It will not work! What’s wrong with the above program and how can you fix it (without changing the first or last lines)? How can you fix this if you are allowed to change any of the lines? Why might be a problem with doing it this way? I've done the research and can't seem to find out why the output is stille 'last name, last name'. Any help will be greatly appreciated, thanks!
×
×
  • 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.