Jump to content

Script Error


veronika

Recommended Posts

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>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.