Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding to existing PHP form 1

Status
Not open for further replies.

vba317

Programmer
Mar 5, 2009
708
US
I am using PHP 5.5. I would like to add a inputbox to an existing form. This is my first time modifying any code in PHP. I was hoping for some input so I don't mess it up. I would like to add a group 3 input box below where the current group 2 box is.

Any help is appreciated
Tom


Current Code
Code:
odbc_free_result($get_f2);
            $sel_f2.= "</select>";
            // Build Form
            $display_block="<p align='center'><b><font color=000080>EDIT REPORT - GROUPED</font></b></p>
                            <form method='post' action='".$_SERVER['PHP_SELF']."?cl=".$clid."&id=".$rptqid."'>
                            <p align='center'><table width='95%' cellpadding='3' cellspacing='3' border='0'>
                            <tr><td width='15%' align='right' valign='top'><b><font color='000080'>REPORT:</font></b></td>
                                <td width='35%' align='left' valign='top'><b><font color='000080'>".$r_rdsc."</font></b></td>
                                <td width='15%' align='right' valign='top'><b><font color='000080'>TAB:</font></b></td>
                                <td width='35%' align='left' valign='top'><input type='text' name='ztab' size='35' maxlength='25' value='".$r_tab."'></td></tr>
                            <tr><td width='15%' align='right' valign='top'><b><font color='000080'>TITLE:</font></b></td>
                                <td colspan='3' align='left' valign='top'><input type='text' name='zttl' size='110' maxlength='100' value='".$r_ttl."'></td></tr>
                            <tr><td width='15%' align='right' valign='top'><b><font color='000080'>SUBTITLE:</font></b></td>
                                <td colspan='3' align='left' valign='top'><input type='text' name='zstl' size='110' maxlength='100' value='".$r_stl."'></td></tr>
                            <tr><td width='15%' align='right' valign='top'><b><font color='000080'>GROUP 1:</font></b></td>
                                <td width='35%' align='left' valign='top'>".$sel_g1."</td></tr>
              [Blue]            <td width='15%' align='right' valign='top'><b><font color='000080'>GROUP 2:</font></b></td>
                                <td width='35%' align='left' valign='top'>".$sel_g2."</td></tr>   [/Blue]
                            <tr><td width='15%' align='right' valign='top'><b><font color='000080'>FILTER 1:</font></b></td>
                                <td width='35%' align='left' valign='top'>".$sel_f1."</td></tr>
                                <td width='15%' align='right' valign='top'><b><font color='000080'>FILTER 2:</font></b></td>
                                <td width='35%' align='left' valign='top'>".$sel_f2."</td></tr>
                            <tr><td colspan='4' align='center' valign='bottom'><input type='submit' name='submit' value='UPDATE REPORT'></td></tr>
                            </table></p></form>";
        } else { // Process
            if((isset($_POST['ztab'])) && (trim($_POST['ztab'])!='')
                    && (isset($_POST['zttl'])) && (trim($_POST['zttl'])!='')) { // Required Fields
                if((ChkTabUnique($rptsqlcn,$clid,$_POST['ztab'],$rptqid)==0) 
						and (strlen($_POST['ztab'])<31)) { // Check to be sure tab unique and within length limit
                    // Get Posted Data
                    $nw_tab=($_POST['ztab']); // Function to fix tab names
                    $nw_ttl=FixPostText($_POST['zttl']);
                    $nw_stl=FixPostText($_POST['zstl']);
                    $nw_g1=$_POST['zgr1'];
                    if($nw_g1==1) { // No primary group, can't have secondary group
                        $nw_g2=1;
                    } else {
                        $nw_g2=$_POST['zgr2'];
                    }
                    $nw_f1=$_POST['zfl1'];
                    if($nw_f1==1) { // No primary filter, can't have secondary filter
                        $nw_f2=1;
                    } else {
                        $nw_f2=$_POST['zfl2'];
                    }



I am thinking that the following code might work below where the code is Blue up above. But what would I change so the group 3 button goes below the group 2 input box? Also I have two other input boxes below the group 2 input box would those get automatically reformatted?

Code:
<td width='15%' align='right' valign='top'><b><font color='000080'>GROUP 3:</font></b></td>
<td width='35%' align='left' valign='top'>".$sel_g2."</td></tr>
 
Lets start with some clarification.

What exactly is in the variable $sel_g2?

I'm assuming your input code is stored in there somehow.

In which case you'd likely have to add a $sel_g3 with the relevant HTML for it. As otherwise both your Group 2 and Group 3 would be the same input and as such Group 2 would be overwritten with Group3's value when the form is submitted.


With that said, you are building a straight forward table with your groups. Your Group 2 row sseems to be missing an opening table row tag (<tr>) so it may cause some issues.

But you can try it and add the code you posted as plus opening and closing table row tags like this:


Code:
<tr>
[tab]<td width='15%' align='right' valign='top'><b><font color='000080'>GROUP 1:</font></b></td>
[tab]<td width='35%' align='left' valign='top'>".$sel_g1."</td>
</tr>
[COLOR=#A40000][b]<tr>[/b][/color]
[tab]<td width='15%' align='right' valign='top'><b><font color='000080'>GROUP 2:</font></b></td>
[tab]<td width='35%' align='left' valign='top'>".$sel_g2."</td>
</tr>

[highlight #874A20][white]<tr>
[tab]<td width='15%' align='right' valign='top'><b><font color='000080'>GROUP 3:</font></b></td>
[tab]<td width='35%' align='left' valign='top'>".$sel_g3."</td>
</tr>[/white][/highlight]

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Sorry about the confusion. I thought I copied enough code but I clearly didn't. This is all the code that is above the code I previously posted. Are you suggesting that I

Code:
<?php
/*
 * ADD/EDIT REPORT
 */
session_start();
include ('odbc_bi.php'); // ODBC Connection to Admin Database
include ('odbc_rpts.php'); // ODBC Connection to Monthly Report Database
include ('cpuser.php'); // user functions
include ('cpclient.php'); // client functions
include ('rptdata.php'); // Monthly Report Data functions

if(isset($_SESSION['usr'])) { // User Authenticated
    // Get Variables
    $usr=$_SESSION['usr'];
    $clid=$_GET['cl'];
    $rptqid=$_GET['id'];
    if(CheckEditRights($usr,$clid,4,$bisqlcn)==0) {
        // No edit rights, re-direct back
        $intro="<b><font color='FF0000'>*** NO EDIT RIGHTS FOR THIS SECTION ***</font></b>";
        $menu_block="<ul>
                    <li><a href='home.php?cl=".$clid."&v=4&pg=1'>HOME</a></li>
                    </ul>";
        $display_block="<p align='center'><b>Please click <a href='home.php?cl=".$clid."&v=2&pg=1'>HERE</a> to return to client profile.</b></p>";
    } else {
        $intro="<font color='000080'>".GetClientName($clid,$bisqlcn)."</font>";
        $menu_block="<ul><li><a href='home.php?cl=".$clid."&v=4&pg=0'>RETURN</a></li></ul>";
        if(!isset($_POST['submit'])) { // Not posted, show form
            // Get Data
            $sql_edt="SELECT rptid,tabnm,rpttitle,rptsubtitle,grp1,grp2,filt1,filt2
                      FROM dbo.rptq_rpts
                      WHERE qrptid=".$rptqid.";";
            $get_edt=odbc_exec($rptsqlcn,$sql_edt) or die(odbc_errormsg());
            $r_rpt=odbc_result($get_edt,'rptid');
            $r_tab=odbc_result($get_edt,'tabnm');
            $r_ttl=odbc_result($get_edt,'rpttitle');
            $r_stl=odbc_result($get_edt,'rptsubtitle');
            $r_grp1=odbc_result($get_edt,'grp1');
 [Blue]           $r_grp2=odbc_result($get_edt,'grp2');
            $r_fl1=odbc_result($get_edt,'filt1');  [/Blue]
            $r_fl2=odbc_result($get_edt,'filt2');
            odbc_free_result($get_edt);
            // Report Name
            $r_rdsc=GetRptDesc($rptsqlcn,$r_rpt);
            // Group 1 Select
            $sel_g1="<select name='zgr1' size=1>";
            $sql_g1="SELECT grpid,grpdsc FROM dbo.rpt_subs ORDER BY grpdsc;";
            $get_g1=odbc_exec($rptsqlcn,$sql_g1) or die(odbc_errormsg());
            while($g1rec=odbc_fetch_array($get_g1)) {
                if($g1rec['grpid']==$r_grp1) {
                    $sel_g1.="<option selected value=".$g1rec['grpid'].">".$g1rec['grpdsc']."</option>";
                } else {
                    $sel_g1.="<option value=".$g1rec['grpid'].">".$g1rec['grpdsc']."</option>";
                }
            }
            odbc_free_result($get_g1);
            $sel_g1.= "</select>";
            // Group 2 Select
            $sel_g2="<select name='zgr2' size=1>";
            $sql_g2="SELECT grpid,grpdsc FROM dbo.rpt_subs ORDER BY grpdsc;";
            $get_g2=odbc_exec($rptsqlcn,$sql_g2) or die(odbc_errormsg());
            while($g2rec=odbc_fetch_array($get_g2)) {
                if($g2rec['grpid']==$r_grp2) {
                    $sel_g2.="<option selected value=".$g2rec['grpid'].">".$g2rec['grpdsc']."</option>";
                } else {
                    $sel_g2.="<option value=".$g2rec['grpid'].">".$g2rec['grpdsc']."</option>";
                }
            }
            odbc_free_result($get_g2);
            $sel_g2.= "</select>";
            // Filter 1 Select
            $sel_f1="<select name='zfl1' size=1>";
            $sql_f1="SELECT grpid,grpdsc FROM dbo.rpt_subs ORDER BY grpdsc;";
            $get_f1=odbc_exec($rptsqlcn,$sql_f1) or die(odbc_errormsg());
            while($f1rec=odbc_fetch_array($get_f1)) {
                if($f1rec['grpid']==$r_fl1) {
                    $sel_f1.="<option selected value=".$f1rec['grpid'].">".$f1rec['grpdsc']."</option>";
                } else {
                    $sel_f1.="<option value=".$f1rec['grpid'].">".$f1rec['grpdsc']."</option>";
                }
            }
            odbc_free_result($get_f1);
            $sel_f1.= "</select>";
            // Filter 2 Select
            $sel_f2="<select name='zfl2' size=1>";
            $sql_f2="SELECT grpid,grpdsc FROM dbo.rpt_subs ORDER BY grpdsc;";
            $get_f2=odbc_exec($rptsqlcn,$sql_f2) or die(odbc_errormsg());
            while($f2rec=odbc_fetch_array($get_f2)) {
                if($f2rec['grpid']==$r_fl2) {
                    $sel_f2.="<option selected value=".$f2rec['grpid'].">".$f2rec['grpdsc']."</option>";
                } else {
                    $sel_f2.="<option value=".$f2rec['grpid'].">".$f2rec['grpdsc']."</option>";
                }
            }
            odbc_free_result($get_f2);
            $sel_f2.= "</select>";
            // Build Form


Would I also have to change g2 to g3 in this code?

Code:
 odbc_free_result($get_g2);
            $sel_g2.= "</select>";
            // Filter 1 Select
            $sel_f1="<select name='zfl1' size=1>";
            $sql_f1="SELECT grpid,grpdsc FROM dbo.rpt_subs ORDER BY grpdsc;";
            $get_f1=odbc_exec($rptsqlcn,$sql_f1) or die(odbc_errormsg());
            while($f1rec=odbc_fetch_array($get_f1)) {
                if($f1rec['grpid']==$r_fl1) {
                    $sel_f1.="<option selected value=".$f1rec['grpid'].">".$f1rec['grpdsc']."</option>";
                } else {
                    $sel_f1.="<option value=".$f1rec['grpid'].">".$f1rec['grpdsc']."</option>";
 
You would need to add a new code block for g3 so as to not affect the preexisting sel_g2 code block. So you get a new dropdown that will be submitted with your form without affecting the Original sel_g2 dropdown named zgr2. Otherwise your new dropdown would be identical to the original sel_g2 and would overwrite it as I said when your form is submitted so you would not get its value.

Code:
  // Group 3 Select
           [b] $sel_g3=[/b]"<select name='[b]zgr3[/b]' size=1>";
            [b]$sql_g3=[/b]"SELECT grpid,grpdsc FROM dbo.rpt_subs ORDER BY grpdsc;";
            [b]$get_g3=[/b]odbc_exec($rptsqlcn,$sql_g2) or die(odbc_errormsg());
            while([b]$g3rec[/b]=odbc_fetch_array([b]$get_g3[/b])) {
                if([b]$g3rec[/b]['grpid']==[b]$r_grp3[/b]) {
                    $sel_g3.="<option selected value=".[b]$g3rec[/b]['grpid'].">".[b]$g3rec[/b]['grpdsc']."</option>";
                } else {
                    $sel_g3.="<option value=".[b]$g3rec[/b]['grpid'].">".[b]$g3rec[/b]['grpdsc']."</option>";
                }
            }
            odbc_free_result($get_g3);
            $sel_g3.= "</select>";

Code:
$r_grp2=odbc_result($get_edt,'grp2');
[COLOR=#A40000]$r_grp3=odbc_result($get_edt,'grp3');[/color] [green]//would only work if your table actually has a grp3 column. Otherwise keep it as grp2 Though it would then take the value of that column. Just like the previous variiable. [/green]
$r_fl1=odbc_result($get_edt,'filt1');


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
It took me awhile to get back to this. I have moved the original file to another directory I have now copied the file with the changes into the original folder. When I pull up the website there is no group 3 box. Am I supposed to do another step?

Tom
 
Ignore my previous post. I found that this particular function is related to two files, I had just updated one of the files. I have updated both files and it looks correct. I am going to test right now to see if the code does what I want it to.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top