SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Replacing entry in database via button

    Got as far as i could on my own, now i'm stuck again..

    i have a control panel page, that shows either the processed applications, the unprocessed, or both. When clicking on the company name it will go to a results page, which displays all the fields with the relevent data for that entry.

    What i'd like to do is have a text box, where i can input a number, and a 'process' button which changes the processed field to 'yes', and replaces the default 'no' in the database.

    i still can't get to grips with linking/buttons with php, so all/any help very much appreciated!

    Here's the code for the control panel (which can be seen here)

    PHP Code:

    <?php
    echo "<div align=\"center\"><table bgcolor=\"black\" width=\"658\" border=\"0\"><tr><td>";
    echo 
    "<TITLE>JBL Credit Application Control Panel</title>";
    echo 
    "<head><link type=\"text/css\" rel=\"stylesheet\" href=\"form-style.css\"></link></head>";
    echo 
    "<img src=\"logo-forms.gif\" ALIGN=\"MIDDLE\" width=\"140\" height=\"67\" border=\"0\"><FONT id=\"FORMHDR2\">Credit Applications Control Panel</font>";
    echo 
    "<br><br><table border=\"0\" CELLSPACING=\"7\" CELLPADDING=\"4\"><tr>";
    echo 
    "<td WIDTH=\"140\" ALIGN=\"CENTER\" BGCOLOR=\"#000033\"><a href=\"http://www.jbl.co.uk/php/conpan/creditappconpan5.php\">ALL Applications</FONT></td>";
    echo 
    "<td WIDTH=\"140\" ALIGN=\"CENTER\" BGCOLOR=\"#000033\"><a href=\"http://www.jbl.co.uk/php/conpan/creditappconpan5.php?processed=no\">Unprocessed</a></td>";
    echo 
    "<td WIDTH=\"140\" ALIGN=\"CENTER\" BGCOLOR=\"#000033\"><a href=\"http://www.jbl.co.uk/php/conpan/creditappconpan5.php?processed=yes\">Processed</a></td>";
    echo 
    "</tr></table><br><br>";
    echo 
    "<table border=\"0\" CELLSPACING=\"10\" CELLPADDING=\"6\"><tr>";
    echo 
    "<td WIDTH=\"270\" align=center BGCOLOR=\"#000066\"><FONT id=\"FORMHDR\">Company Name</FONT></td>";
    echo 
    "<td WIDTH=\"150\" align=\"center\" BGCOLOR=\"#000066\"><FONT id=\"FORMHDR\">Company Number</FONT></td>";
    echo 
    "<td WIDTH=\"100\" align=\"center\" BGCOLOR=\"#000066\"><FONT id=\"FORMHDR\">Processed?</FONT></td>";
    echo 
    "</tr></table>";
    echo 
    "<table border=\"0\" CELLSPACING=\"5\" CELLPADDING=\"3\" bgcolor=\"black\">";

    //connect to mysql
    //change user and password to your mySQL name and password
    mysql_connect("localhost","root","password"); 
        
    //select which database you want to edit
    mysql_select_db("jblformdb"); 


    $s_sql "SELECT * FROM  credsql WHERE 1 = 1";
    if (
    $_GET['processed'] == 'yes') {$s_sql .= " AND processed = 'yes'";}
    if (
    $_GET['processed'] == 'no') {$s_sql .= " AND processed = 'no'";}

    $companyID intval($_GET['entry_id']);


    $result mysql_query($s_sql);

    //grab all the content
    while($r=mysql_fetch_array($result))
    {
       
    //the format is $variable = $r["companyname"];
       //modify these to match your mysql table columns

       
    $companyname=$r["companyname"];
       
    $companynumber=$r["companynumber"];
       
    $processed=$r["processed"];
       
    $companyID=$r['ID'];
       
       
    //display the row
    echo "<tr><TD WIDTH=5>&nbsp;</TD>";

    echo 
    "<td WIDTH=\"280\"><FONT id=\"FORMTXT\"><a href=\"results.php?entry_id=$companyID&control=1\">$companyname</a></td>";

    echo 
    "<td WIDTH=\"195\"><FONT id=\"FORMTXT\">$companynumber</td>";
    echo 
    "<td WIDTH=\"40\"><FONT id=\"FORMTXT\">$processed</TD></tr>";
    }
    echo 
    "<tr><TD WIDTH=\"5\">&nbsp;</TD><TD COLSPAN=\"3\"><hr size=\"1\" width=\"100%\" align=\"left\"></TD></tr></table>";
    echo 
    "</div></td></tr></table>";
    ?>
    And this is the code for the results.php page

    PHP Code:
    <?php

    ini_set
    ('display_errors','on');
    error_reporting(E_ALL);

    $DBhost "localhost";
    $DBuser "root";
    $DBpass "password";
    $DBName "jblformdb";
    $table "credsql";

    mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

    @
    mysql_select_db("$DBName") or die("Unable to select database $DBName");

    $companyID intval($_GET['entry_id']);
    $sqlquery "SELECT * FROM credsql  WHERE ID=$companyID"$results mysql_query($sqlquery); $data mysql_fetch_array($results);

    mysql_close();

    print 
    "<html><link rel=stylesheet href=form-style.css><body BGCOLOR=WHITE>"
    print 
    "<div align=center><table width=658 border=0 bgcolor=BLACK><TR><TD>"
    print 
    "<table border=0 width=658><tr><td colspan=2>"
    print 
    "<img src=http://www.jbl.co.uk/forms/images/logo-forms.gif width=225 height=108  border=0 align=middle>"
    print 
    "<font face=Verdana, arial color=#6699FF size=+2>Application For A Credit Account</font></td></tr>"
    print 
    "<tr><td colspan=\"2\" align=\"right\" valign=\"center\"><font id=\"FLDTXT\">Assign Acc #: <img src=\"spacer.gif\" width=\"10\" height=\"1\" border=\"0\">";
    print 
    "<input name=\"accnum\" type=\"text\" size=\"6\" MAXLENGTH=\"6\"><img src=\"spacer.gif\" width=\"20\" height=\"1\" border=\"0\">";
    print 
    "<input type=\"button\" value=\"process\"></td></tr>";
    print 
    "<tr><td colspan=2>&nbsp;</td></tr>";
    print 
    "<tr><td colspan=2><font id=HDR>Company Details</FONT></td></tr>"
    print 
    "<tr><td><font id=FLDHDR>Company Name</FONT></td><td bgcolor=#000066><font id=FLDTXT>{$data['companyname']}</FONT></td></tr>";
    print 
    "<tr><td WIDTH=220><font id=FLDHDR>Company Number</FONT></td><td bgcolor=#000066 WIDTH=438><font id=FLDTXT>{$data['companynumber']}</FONT></td></tr>";
    print 
    "<tr><td colspan=2>&nbsp;</td></tr>";
    print 
    "<tr><td colspan=2><font id=HDR>Your Details</FONT></td></tr>"
    print 
    "<tr><td><font id=FLDHDR>Name</td><td bgcolor=#000066><font id=FLDTXT>{$data['regname']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Phone</td><td bgcolor=#000066><font id=FLDTXT>{$data['regphone']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Email</td><td bgcolor=#000066><font id=FLDTXT>{$data['regemail']}</FONT></td></tr>";
    print 
    "<tr><td colspan=2>&nbsp;</td></tr>";
    print 
    "<tr><td colspan=2><font id=HDR>Invoicing Address</FONT></td></tr>"
    print 
    "<tr><td><font id=FLDHDR>Invoicing Name</td><td bgcolor=#000066><font id=FLDTXT>{$data['invoicename']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Address</td><td bgcolor=#000066><font id=FLDTXT>{$data['address']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Address 2</td><td bgcolor=#000066><font id=FLDTXT>{$data['address2']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Address 3</td><td bgcolor=#000066><font id=FLDTXT>{$data['address3']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Town/City</td><td bgcolor=#000066><font id=FLDTXT>{$data['towncity']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>County</td><td bgcolor=#000066><font id=FLDTXT>{$data['county']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>PostCode</td><td bgcolor=#000066><font id=FLDTXT>{$data['postcode']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Phone</td><td bgcolor=#000066><font id=FLDTXT>{$data['phone']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Fax</td><td bgcolor=#333333><font id=FLDTXT>{$data['fax']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Email</td><td bgcolor=#000066><font id=FLDTXT>{$data['email']}</FONT></td></tr>";
    print 
    "<tr><td colspan=2>&nbsp;</td></tr>";
    print 
    "<tr><td colspan=2><font id=HDR>Delivery Address</FONT></td></tr>"
    print 
    "<tr><td><font id=FLDHDR>Same as Invoicing</td><td bgcolor=#333333><font id=FLDTXT>{$data['sameasinv']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Name</td><td bgcolor=#333333><font id=FLDTXT>{$data['deliveryname']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Address</td><td bgcolor=#333333><font id=FLDTXT>{$data['deliveryaddress']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Address 2</td><td bgcolor=#333333><font id=FLDTXT>{$data['deliveryaddress2']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Address 3</td><td bgcolor=#333333><font id=FLDTXT>{$data['deliveryaddress3']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Town/City</td><td bgcolor=#333333><font id=FLDTXT>{$data['deliverytowncity']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>County</td><td bgcolor=#333333><font id=FLDTXT>{$data['deliverycounty']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Postcode</td><td bgcolor=#333333><font id=FLDTXT>{$data['deliverypostcode']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Phone</td><td bgcolor=#333333><font id=FLDTXT>{$data['deliveryphone']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Fax</td><td bgcolor=#333333><font id=FLDTXT>{$data['deliveryfax']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Email</td><td bgcolor=#333333><font id=FLDTXT>{$data['deliveryemail']}</FONT></td></tr>";
    print 
    "<tr><td colspan=2>&nbsp;</td></tr>";
    print 
    "<tr><td><font id=HDR>WebSite</td><td bgcolor=#000066><font id=FLDTXT>{$data['website']}</FONT></td></tr>";
    print 
    "<tr><td colspan=2>&nbsp;</td></tr>";
    print 
    "<tr><td colspan=2><font id=HDR>Purchasing Contacts</FONT></td></tr>"
    print 
    "<tr><td><font id=FLDHDR>Contact Name </td><td bgcolor=#333333><font id=FLDTXT>{$data['contactnamepurch1']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Job Title</td><td bgcolor=#333333><font id=FLDTXT>{$data['jobtitlepurch1']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Responsible for Purchasing </td><td bgcolor=#333333><font id=FLDTXT>{$data['resppurch1']}</FONT></td></tr>";
    print 
    "<tr><td colspan=2>&nbsp;</td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Contact Name</td><td bgcolor=#333333><font id=FLDTXT>{$data['contactnamepurch2']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Job Title</td><td bgcolor=#333333><font id=FLDTXT>{$data['jobtitlepurch2']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Responsible for Purchasing</td><td bgcolor=#333333><font id=FLDTXT>{$data['resppurch2']}</FONT></td></tr>";
    print 
    "<tr><td colspan=2>&nbsp;</td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Contact Name</td><td bgcolor=#333333><font id=FLDTXT>{$data['contactnamepurch3']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Job Title</td><td bgcolor=#333333><font id=FLDTXT>{$data['jobtitlepurch3']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Responsible for Purchasing</td><td bgcolor=#333333><font id=FLDTXT>{$data['resppurch3']}</FONT></td></tr>";
    print 
    "<tr><td colspan=2>&nbsp;</td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Contact Name</td><td bgcolor=#333333><font id=FLDTXT>{$data['contactnamepurch4']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Job Title</td><td bgcolor=#333333><font id=FLDTXT>{$data['jobtitlepurch4']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Responsible for Purchasing</td><td bgcolor=#333333><font id=FLDTXT>{$data['resppurch4']}</FONT></td></tr>";
    print 
    "<tr><td colspan=2>&nbsp;</td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Contact Name</td><td bgcolor=#333333><font id=FLDTXT>{$data['contactnamepurch5']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Job Title</td><td bgcolor=#333333><font id=FLDTXT>{$data['jobtitlepurch5']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Responsible for Purchasing</td><td bgcolor=#333333><font id=FLDTXT>{$data['resppurch5']}</FONT></td></tr>";
    print 
    "<tr><td colspan=2>&nbsp;</td></tr>";
    print 
    "<tr><td><font id=FLDHDR>EstAnnualExp</td><td bgcolor=#333333><font id=FLDTXT>{$data['estannualexp']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Number Of Staff</td><td bgcolor=#333333><font id=FLDTXT>{$data['numofficestaff']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Other Suppliers</td><td bgcolor=#333333><font id=FLDTXT>{$data['othersuppliers']}</FONT></td></tr>";
    print 
    "<tr><td colspan=2>&nbsp;</td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Heard About</td><td bgcolor=#333333><font id=FLDTXT>{$data['hearabout']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Other</td><td bgcolor=#333333><font id=FLDTXT>{$data['hearabout2']}</FONT></td></tr>";
    print 
    "<tr><td colspan=2>&nbsp;</td></tr>";
    print 
    "<tr><td colspan=2><font id=HDR>Reference 1</FONT></td></tr>"
    print 
    "<tr><td><font id=FLDHDR>Line 1</td><td bgcolor=#000066><font id=FLDTXT>{$data['ref1line1']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Line 2</td><td bgcolor=#000066><font id=FLDTXT>{$data['ref1line2']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Line 3</td><td bgcolor=#333333><font id=FLDTXT>{$data['ref1line3']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>ContactName</td><td bgcolor=#000066><font id=FLDTXT>{$data['ref1contactname']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Phone</td><td bgcolor=#000066><font id=FLDTXT>{$data['ref1phone']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Fax</td><td bgcolor=#333333><font id=FLDTXT>{$data['ref1fax']}</FONT></td></tr>";
    print 
    "<tr><td colspan=2>&nbsp;</td></tr>";
    print 
    "<tr><td colspan=2><font id=HDR>Reference 2</FONT></td></tr>"
    print 
    "<tr><td><font id=FLDHDR>Line1</td><td bgcolor=#000066><font id=FLDTXT>{$data['ref2line1']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Line2</td><td bgcolor=#000066><font id=FLDTXT>{$data['ref2line2']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Line3</td><td bgcolor=#333333><font id=FLDTXT>{$data['ref2line3']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Contact Name</td><td bgcolor=#000066><font id=FLDTXT>{$data['ref2contactname']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Phone</td><td bgcolor=#000066><font id=FLDTXT>{$data['ref2phone']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Fax</td><td bgcolor=#333333><font id=FLDTXT>{$data['ref2fax']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Company Type</td><td bgcolor=#000066><font id=FLDTXT>{$data['companytype']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Market Class</td><td bgcolor=#000066><font id=FLDTXT>{$data['marketclass']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Date Established</td><td bgcolor=#000066><font id=FLDTXT>{$data['dateestablished']}</FONT></td></tr>";
    print 
    "<tr><td colspan=2>&nbsp;</td></tr>";
    print 
    "<tr><td colspan=2><font id=HDR>Bank Details</FONT></td></tr>"
    print 
    "<tr><td><font id=FLDHDR>Name</td><td bgcolor=#000066><font id=FLDTXT>{$data['namebankdetails']}</td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Address </td><td bgcolor=#000066><font id=FLDTXT>{$data['address1bankdetails']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Address 2</td><td bgcolor=#000066><font id=FLDTXT>{$data['address2bankdetails']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Address 3</td><td bgcolor=#000066><font id=FLDTXT>{$data['address3bankdetails']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Postcode</td><td bgcolor=#000066><font id=FLDTXT>{$data['postcodebankdetails']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>SortCode</td><td bgcolor=#000066><font id=FLDTXT>{$data['sortcodebankdetails']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Account No</td><td bgcolor=#000066><font id=FLDTXT>{$data['accountnobankdetails']}</FONT></td></tr>";
    print 
    "<tr><td><font id=FLDHDR>Credit Limit Req</td><td bgcolor=#000066><font id=FLDTXT>{$data['creditlimitbankdetails']}</FONT></td></tr>";
    print 
    "</TABLE></td></tr></table></body></div></html>";

    ?>

  2. #2
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    MrAsh

    Here is one way to do this - have the form post back to itself and set a hidden flag to test if the form has been posted. Like this:

    PHP Code:
    <?php   if (isset ($_POST['hidden_check'])){
                
    // insert Posted data
                
    $result mysql_query("UPDATE tableName SET status_field='1' WHERE staus_field_id=" $_POST['set_status'])
                or die(
    mysql_error());


                
    $result mysql_query("SELECT * FROM tableName WHERE staus_field_id=" $_POST['set_status'])
                or die(
    mysql_error());

            } else {
    ?>
                <h2>Change a database values status</h2>
                <form action=" <?php echo $_SERVER['PHP_SELF']; ?>" method='POST'>
                    <input type='hidden'name='hidden_check' value='havePosted'>
              
                    <p id='status'>
                        <label for="set_status">Change Status of Field:</label> <input type="text" name="set_status">
                    </p>
                    <p id='Submit'>
                        <input type="submit" value="Change Status">
                    </p>
                </form>
    <?php    }

    ?>
    You can see that after the 'Change Status' button has been selected then the form posts back to itself and then executes the Update and then the Select (to view the results of the update). Obviously In this quick example I didn't put any error checking or validation but you can easily do that on your own time.

    One other thought regarding your current script... Why not use heredoc syntax (http://ca3.php.net/heredoc) for easier formating, less echo or print function calls and easier readability?
    PHP Code:
    $content =<<<TOC
    <div align="center"><table bgcolor="black" width="658" border="0"><tr><td>
       <TITLE>JBL Credit Application Control Panel</title>
       <head><link type="text/css" rel="stylesheet" href="form-style.css"></link></head>
        <img src="logo-forms.gif" ALIGN="MIDDLE" width="140" height="67" border="0"><FONT id="FORMHDR2">Credit Applications Control Panel</font>
        <br><br>
        <table border="0" CELLSPACING="7" CELLPADDING="4">
         <tr>"
           <td WIDTH="140" ALIGN="CENTER" BGCOLOR="#000033"><a href="http://www.jbl.co.uk/php/conpan/creditappconpan5.php">ALL Applications<FONT><td>
           <td WIDTH="140" ALIGN="CENTER" BGCOLOR="#000033"><a href="http://www.jbl.co.uk/php/conpan/creditappconpan5.php?processed=no">Unprocessed</a></td>
           <td WIDTH="140" ALIGN="CENTER" BGCOLOR="#000033"><a href="http://www.jbl.co.uk/php/conpan/creditappconpan5.php?processed=yes">Processed</a></td>
          "</tr>
        </table>
          <br><br>"
          <table border="0" CELLSPACING="10" CELLPADDING="6">
            <tr>
              <td WIDTH="270" align=center BGCOLOR="#000066"><FONT id="FORMHDR">Company Name</FONT></td>
              <td WIDTH="150" align="center" BGCOLOR="#000066"><FONT id="FORMHDR">Company Number</FONT></td>
              <td WIDTH="100" align="center" BGCOLOR="#000066"><FONT id="FORMHDR">Processed?</FONT></td>
            </tr>
         </table>
    </div>
    TOC;

    echo 
    $content
    Regards,
    ServerStorm
    ictus==""

  3. #3
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Here is a better way - rather than using form buttons. This way involves:
    1. Creating a new PHP session as an array. This is an array so that if you want to you can store more of your table data persistent in the session based array. You could also use just a variable here.
    2. Dynamically building a Table that contains the Company Name, Company Number and Processed? columns
    3. When 'Set Status' is selected at the end of a row the page reloads and then would run the SQL to update the corresponding 'Processed' Db column.
    You will have to change the SQL and uncomment and comment some of the testing and SQL to get it working with your Db. You can copy and paste it 'as is' to get a feel for how it works, without worrying about your database connectivity. Here is the code for creditappconpan5.php:
    PHP Code:
    <?php
    // Creates a new session called status
    session_start();
    if (!isset(
    $_SESSION['status'])) {
        
    $_SESSION['status'] = array();
    }
    if (isset(
    $_GET['status_id'])) {
        
    //Add a status id change to the end of the $_SESSION['status'] array
        
    $_SESSION['status'][0] = $_GET['status_id'];

        
    // You would set your SQL UPDATE here, something like:
        // 'Update tableName Set status_id=' . $_SESSION['status'][0]
        // status_id equals your Processed? column in the Db.

        // Redirect the page to itself. MAKE SURE you DO NOT output anything
        // to the browser before you do this redirect otherwise you will get
        // a header already sent error.
        
    header('Location:'.$_SERVER['PHP_SELF']);
        exit ();
    }
    ?>

        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
        <html>
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
                <title>JBL Credit Application</title>
            </head>
        <body>

            <!-- Add your Images and HTML header stuff here -->

            <table border='1'>
                <thead>
                    <tr>
                        <th>Company Name</th>
                        <th>Company Number</th>
                        <th>Processed?</th>
                    </tr>
                </thead>


    <?php
        
    //Show what status id(s) where affected
        
    echo 'Updated processed? status_id=' $_SESSION['status'][0] . '<br /><br />';

        
    //$current_status will be used below when constructing your table
        
    $current_status $_SESSION['status'][0];

        
    //Clear the session
        
    unset($_SESSION['status']);

        
    //Test rows these would be pulled from the DB normally using some form of a loop
        
    $arr_Rows = array();
        
    $arr_Rows[0] = 'one';
        
    $arr_Rows[1] = 'two';
        
    $arr_Rows[2] = 'three';
        
    $arr_Rows[3] = 'Four';
        
    $arr_Rows[4] = 'Five';

        
    /* Uncomment this section and fill in with your own table and rows
        $sql = "SELECT COUNT(status_id)
                  FROM sometable";

        $result = mysql-query($sql) or die(mysql_error());

        $rowCount = $row['COUNT(status_id)'];

        // initial $i value set to initial set-status_id
        $result = mysql-query($sql) or die(mysql_error());*/

        //Comment this when you Uncomment the section above. This is just used for
        // testing without connecting to the database
        
    $rowCount 5;

        
    // Output your table that contain Company Name, Company Number and Processed?
        
    for ($i 1$i <= $rowCount$i++){

            echo 
    '<tr>';

            
    // bogus company name you would pull this from the DB
            
    echo '<td> Company ' $arr_Rows[$i 1] . '</td>';

            
    // bogus company number, you would pull this from the DB
            
    echo '<td> 100000' $i '</td>';

            
    // This If/Else will only show the current value is being updated.
            // However, you will read these values from your database based on the
            // processed flag being 1 or 0; therefore all process and unprocess will be shown.
            
    if ($i == $current_status) {
                echo 
    '<td> yes </td>';
            }Else{
                echo 
    '<td> no </td>';
            }

            echo 
    '<td><a href="' $_SERVER['PHP_SELF'] .
            
    '?status_id=' $i '">Set Status</a></td>';

            echo 
    '</tr>';
        }
    ?>
            </table>
        </body>
    </html>
    I hope this helps!

    ServerStorm
    ictus==""

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the suggestions, ServerStorm.

    Unfortunately though, i think i've hit my Ceiling of Ability, as i'm really struggling to make sense of all this and the current code. (i think this gives me a good idea of how dyslexics see regular words.)

    So, i'm going to leave it at this point, try and grasp all the basics of php better, and then come back to it once i've learnt more.

    But thanks again, very kind!

  5. #5
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    MrAsh,

    I hope your learning endeavors go well!

    Have you thought about learning the basics of OO (Object Oriented) PHP rather than just procedural basics?

    In many ways OO helps simplify coding. PHP 5.x is very OO friendly and there is a lot of OO PHP learning resources on the Web and here at Sitepoint.

    Regards,
    ServerStorm
    ictus==""


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •