billy1990 Posted May 16, 2011 Share Posted May 16, 2011 Hay phpeoples (: I'm new around these parts and I'm looking for a bit of help. I'm trying to answer the following: Upload task8.htm to your web site (found in the zip file you downloaded for this prac set) containing a form with a textbox to enter a customer id, a submit button and a reset button. Create the PHP page named task8.php. This page is the action of task8.htm and will receive the customer ID from the task8.htm page when it submits. Based on that submitted data task8.php should extract the order number, order date, and the shipped field for all orders placed by that customer. Sort the results in ascending order of the order date. Display the results in an appropriate table. Test the PHP script by entering a valid customer id (see your output from task 3 for the customer ids) in the text box of the form and then click submit. Verify that the results you obtain are correct by comparing the resulting data with that obtained from the tables in task 4. Change your SQL query if the data is not correct. Test the script again but this time use a customer id that does not exist. What happens? Modify your task8.php script to better handle this situation with an appropriate error message instead of displaying the table heading. Verify your results. NB: when testing try several valid customer IDs to ensure that the results are correct (never assume that just because you get output that the results are correct). this is my current HTML code: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Prac3 Task 8</title> </head> <body> <h1>Task 8</h1> <!-- for the purpose of this and subseqent tasks DO NOT modify the method of this form --> <form id="customerform" action="task8.php" method="get"> <p>please fill in the following form</p> <p>Customer ID: <input type="text" name="custID"/><br/> <p><input type="submit" value="Submit"> <input type="reset" value="Reset"></p> </form> </body> </html> and this is my current php code: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Prac 3 Task 3</title> </head> <body> <?php $conn = mysql_connect("localhost", "twastudent", "prac3"); mysql_select_db("warehouse", $conn) or die ('Database not found ' . mysql_error() ); $sql = "select * from orders"; $rs = mysql_query($sql, $conn) or die ('Problem with query' . mysql_error()); ?> <?php $custid = $_GET["custID"]; ?> <?php $row= mysql_fetch_array($rs); if ($custid == $row) ?> <table border="1" summary="Customer Details"> <tr> <th>cID</th> <th>Order number</th> <th>Order Date</th> <th>Shipped</th> </tr> <?php { ?> <tr> <td><?php echo $row["customerID"] ?></td> <td><?php echo $row["orderNumber"] ?></td> <td><?php echo $row["orderDate"]?></td> <td><?php echo $row["shipped"]?></td> </tr> <?php } mysql_close($conn); ?> </table></body></html> Currently it does not show me the records for the number that I type in. Quote Link to comment https://forums.phpfreaks.com/topic/236590-php-coding-help-needed/ Share on other sites More sharing options...
SharkBait Posted May 16, 2011 Share Posted May 16, 2011 The php portion.. doesn't do anything with $custid your first query just pulls ALL the data You need to iterate through the array that $row will be to get it to display anything. Quote Link to comment https://forums.phpfreaks.com/topic/236590-php-coding-help-needed/#findComment-1216275 Share on other sites More sharing options...
fugix Posted May 16, 2011 Share Posted May 16, 2011 for starters, change these lines <?php $row= mysql_fetch_array($rs); ?> <table border="1" summary="Customer Details"> <tr> <th>cID</th> <th>Order number</th> <th>Order Date</th> <th>Shipped</th> </tr> <?php if ($custid == $row) { ?> <tr> <td><?php echo $row["customerID";] ?></td> <td><?php echo $row["orderNumber"]; ?></td> <td><?php echo $row["orderDate"]; ?></td> <td><?php echo $row["shipped"]; ?></td> </tr> <?php } mysql_close($conn); ?> </table></body></html> also, not sure why you are setting your post id equal to mysql_fetch_array() Quote Link to comment https://forums.phpfreaks.com/topic/236590-php-coding-help-needed/#findComment-1216277 Share on other sites More sharing options...
jcbones Posted May 17, 2011 Share Posted May 17, 2011 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Prac 3 Task 3</title> </head> <body> <?php $conn = mysql_connect("localhost", "twastudent", "prac3"); mysql_select_db("warehouse", $conn) or die ('Database not found ' . mysql_error() ); $sql = "select * from orders"; //you need to add a where clause that contains the customer ID that is pulled via the $_GET array. $rs = mysql_query($sql, $conn) or die ('Problem with query' . mysql_error()); ?> <?php $custid = $_GET["custID"]; ?> //should be moved higher so that you can extract the right rows. <?php $row= mysql_fetch_array($rs); //should be wrapped in a while loop to get all of the records. if ($custid == $row) //has no bearings on this application, and is bad form as there is no curly brace behind it. ?> <table border="1" summary="Customer Details"> <tr> <th>cID</th> <th>Order number</th> <th>Order Date</th> <th>Shipped</th> </tr> <?php { //curly brace for the if statement, which should immediately follow it.?> <tr> <td><?php echo $row["customerID"] ?></td> <td><?php echo $row["orderNumber"] ?></td> <td><?php echo $row["orderDate"]?></td> <td><?php echo $row["shipped"]?></td> </tr> <?php } //close the if statement. mysql_close($conn); ?> </table></body></html> Quote Link to comment https://forums.phpfreaks.com/topic/236590-php-coding-help-needed/#findComment-1216308 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.