veronika Posted February 28, 2010 Share Posted February 28, 2010 Hey guys, can someone please help me. I have the following assignments: Assignment #9: Report Generation In this assignment you will create a pair of Web documents - a form and a script - which will display a list of expenditures from our homebudget database. Submission will only require one page - the script. Name your script solution09.php. Within the script, construct a SELECT statement which will query the "expenses" table for all of the family's purchases. Process the resulting recordset with a while loop which will create a separate line for each expense. (NOTE: You can use line-break tags.) On each line, display the category, date, and amount of the expense. (NOTE: How would you modify the table, now that you are beginning to use it? Would you add a "payee" column? How about an "expenseID" column? Discuss these possibilities on the boards, and relate your recommended additions back to the concept of "scope creep", which we have mentioned a few times.) On the HTML form, provide the visitor with an input box he/she may use to enter an expense category. Name the form solution09.html Modify your script so that it retrieves the value entered by the visitor. Modify the SELECT statement created within your script so that it includes a WHERE clause which will test to make sure that the category column is equal to the value entered by the visitor. And I have this script: I keep getting an error in line 18 but i don't know whet the problem is. I know that script is not completer but im trying to understand what this error is and get it out the way... any help is greatly appreciated: <?php $connection=mysql_connect ("localhost", "spike", "9sj7En4"); if (!$connection) { die ('Could not Connect: '. mysql_error()); } mysql_select_db ("My_DB", $connection); $result = mysql_query ("SELECT * FROM Expenses"); echo "<table border='3'> <tr> <th>Category</th> <th>Date</th> <th>Dollar Amount</th> </tr>"; while ($row=mysql_fetch_array ($result)) { echo "<tr>" echo "<td>" .$row ['Category'] ."</td>" ; echo "<td>" .$row ['Date'] ." </td>"; echo "<td>" .$row ['Dollar Amount'] . " </td>"; echo "</tr>"; } echo "</table>"; mysql_close ($connection); ?> <HTML> <HEAD> <TITLE>Solution09</TITLE> </HEAD> <BODY> <h1>Report Generation</h1> </BODY> </HEAD> </HTML> Quote Link to comment https://forums.phpfreaks.com/topic/193702-script-error/ Share on other sites More sharing options...
Dennis1986 Posted February 28, 2010 Share Posted February 28, 2010 Next time please tell us the error message you get and what is on line 18. Anyway I did a count and found the problem. Line 17: echo "<tr>" Missing ; at the end of the line. Quote Link to comment https://forums.phpfreaks.com/topic/193702-script-error/#findComment-1019563 Share on other sites More sharing options...
veronika Posted February 28, 2010 Author Share Posted February 28, 2010 THANKS Dennis 1986... I am very new to PHP so Im not quite understanding a lot of it. But anyways I am now getting the follwing error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\solution09.php on line 15 line 15 has: while ($row= mysql_fetch_array ($result)) What does that error mean? Quote Link to comment https://forums.phpfreaks.com/topic/193702-script-error/#findComment-1019569 Share on other sites More sharing options...
Dennis1986 Posted February 28, 2010 Share Posted February 28, 2010 Glad to help, just ask. The problem is that the variable $result isn't working as intended. To find out what the problem is replace this: mysql_select_db ("My_DB", $connection); $result = mysql_query ("SELECT * FROM Expenses"); With this: mysql_select_db ("My_DB", $connection) or die(mysql_error()); $result = mysql_query ("SELECT * FROM Expenses") or die(mysql_error()); Edit: Then let us know what the error is unless you can fix it yourself. Quote Link to comment https://forums.phpfreaks.com/topic/193702-script-error/#findComment-1019574 Share on other sites More sharing options...
Dennis1986 Posted February 28, 2010 Share Posted February 28, 2010 Tip: When working with databases it's always a good idea to have error handling as backup, so in most cases just add or die(mysql_error()) after all your mysql functions/queries in case something goes wrong. In that way you'll quickly learn from your mistakes Quote Link to comment https://forums.phpfreaks.com/topic/193702-script-error/#findComment-1019575 Share on other sites More sharing options...
veronika Posted February 28, 2010 Author Share Posted February 28, 2010 THANKS that worked...I appreciate the help ~nika Quote Link to comment https://forums.phpfreaks.com/topic/193702-script-error/#findComment-1019584 Share on other sites More sharing options...
Dennis1986 Posted February 28, 2010 Share Posted February 28, 2010 Any time! Quote Link to comment https://forums.phpfreaks.com/topic/193702-script-error/#findComment-1019586 Share on other sites More sharing options...
veronika Posted February 28, 2010 Author Share Posted February 28, 2010 Im not understading the last 2 sections of the assignment: -Modify the script so that it retrieves the values entered by the visitor -Modify the SELECT statement created within the script so that it includes a WHERE clause which will test to make sure that the category column is equal to the value entered by the visitor I ccreated the HTML which containes and input box for the customers to enter a expense. If Im understanding right the .php is supposed to pick up all the entered expenses from the .html and diplay them in a table. Im not understanding the last two steps....PLEASE HELP! Quote Link to comment https://forums.phpfreaks.com/topic/193702-script-error/#findComment-1019620 Share on other sites More sharing options...
Dennis1986 Posted March 1, 2010 Share Posted March 1, 2010 Read this Nika: http://www.w3schools.com/PHP/php_mysql_where.asp When you understand that, all you need to do is use the WHERE clause in your SQL statement and then use the user variable. "SELECT * FROM Expenses WHERE field = '$variable'" The output is now filtered And here's how you get the input from the form into php: http://www.w3schools.com/PHP/php_forms.asp Quote Link to comment https://forums.phpfreaks.com/topic/193702-script-error/#findComment-1019736 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.