Go4Expert

Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   Script problem/ i don't understand (http://www.go4expert.com/forums/script-i-dont-understand-t21156/)

Jaslynne 1Mar2010 04:20

Script problem/ i don't understand
 
Hello All, I've been taking a PHP class for the past 7 weeks and are getting a little hard. This is the first time I have ever messed with PHP and i just don't seem to get it. I have the following assignment:

-Name a script solution09.php
-Wtihin the script construct a SELECT statement which will query the "expenses" table for all the purchases made.
-Process the resulting recordset with a while loop which will create a separate line for each expense.
-On each line display the category, date, and amount of expenses.
-Create an HTML form , provide the visitor with an input box so they may use it to enter an expenses ategory (THIS IS DONE)
-Modify the schript so that it retrieves the value entered by the visitor
-Modify the SELECT statement created within the script so thatit includes a WHERE clause which will test to make sure that the category column is equal to the valueentered by the visitor.

Now, I think I got the script pretty much done EXCEPT for hte last two steps. I don't understand what im supposed to do or where Im supporsed to start. Any help is greatly appreciated :cryin:

Jaslynne 1Mar2010 04:21

Re: Script problem/ i don't understand
 
sorry i forgot to post my script:
Code:

<?php
$connection=mysql_connect ("localhost", "spike", "9sj7En4");
if (!$connection)
{
die  ('Could not Connect: '. mysql_error());
}
mysql_select_db ("My_DB", $connection) or die (mysql_error());
$result = mysql_query ("SELECT * FROM Expenses") or die (mysql_error());
echo "<table  border='2'>
<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);
?>


angelg107 4Mar2010 05:56

Re: Script problem/ i don't understand
 
PHP Code:

<?php
$connection
=mysql_connect ("localhost""spike""9sj7En4");
if (!
$connection)
{
die  (
'Could not Connect: 'mysql_error());
}
mysql_select_db ("My_DB"$connection) or die (mysql_error());
if(!(isset(
$_POST['submit_button']))){
// they did not click the button
$result mysql_query ("SELECT * FROM Expenses") or die (mysql_error());
echo 
"<table  border='2'>
<tr>
<th>Category</th>
<th>Date</th>
<th>Dollar Amount</th>
</tr>"
;
while (
$rowmysql_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>";
}else{
// the form was submitted
// retrieve all the values from the form here
}
mysql_close ($connection);
?>

Now, you only have to make sure the button name in the form
is 'submit_button' for example :

HTML Code:

<form action="" method="post">
......
<input type="submit" value="GO" name="submit_button" />
</form>

Considering your new to PHP, I want to let you know using single-quotes instead
of double-quotes speeds up your script.

Regards.


All times are GMT +5.5. The time now is 07:41.