Script problem/ i don't understand

Discussion in 'PHP' started by Jaslynne, Feb 28, 2010.

  1. Jaslynne

    Jaslynne New Member

    Joined:
    Feb 28, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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:
     
  2. Jaslynne

    Jaslynne New Member

    Joined:
    Feb 28, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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);
    ?>
     
    Last edited by a moderator: Feb 28, 2010
  3. angelg107

    angelg107 New Member

    Joined:
    Mar 4, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    PHP:
    <?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:
    <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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice