Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2005
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Function addForm going awry

    Hi,

    This is what my code is supposed to do :

    a.)Select a customer (say. CompanyD) from db table A. This gives us a variable $cid

    b.)Select an address (say. LocationX) from table B (which has a field called $cid corresp. to companies in Table A). This will result in variable $caid

    c.)Add the name of a person who works in the LocationX office of CompanyD. This will generate a new record, which will be identified by a field CCID (variable $ccid)

    d.)Both customer and address can change for each record. This data will go into table C

    Table C also has fields CID, CAID and resp. values of ($cid and $caid)

    Now, I have got the foll. code but the addForm function and the code thereafter is plain wrong and i dont know how to set it right . Would someone be able to have a look ? Thanks ! Or if someone knows a more efficient way to code, i dont mind re-doing the whole thing.
    I have just put in 1 variable -mobile to test it out and will add the others like name etc once i get this working.


    Thanks ! Swati
    PHP Code:

    <?
    session_cache_limiter
    ('public');
    include (
    "../include/session.php");

     if(!isset(
    $_SESSION['userid'])){

     echo 
    "<center><font face='Verdana' size='2' color=red>Sorry, Please login and use this page </font></center>";

     exit;}


    $userid $_SESSION['userid'];


    ?>

    <?php
    function citySelect ($current$dis='') {
        
    $sql "SELECT CITYID, City
                FROM Cities
                ORDER BY City"
    ;
        
    $res mysql_query($sql) or die(mysql_error());
        
    $str "<SELECT name='cityid' $dis>\n";
        while (list(
    $id,$name)=mysql_fetch_row($res)) {
            
    $selected $id==$current 'selected' '';
            
    $str .= "<option value=$id $selected>$name</option>\n";
        }
        
    $str .= "</select>\n";
        return 
    $str;
    }


    function 
    companyList($co) {
        
    $sql "SELECT CID, Company
                FROM Customers
                WHERE Company LIKE '%$co%'
                ORDER BY Company"
    ;
        
    $res mysql_query($sql) or die(mysql_error());
        
    $str "<table cellspacing='0' cellpadding='2' border='0'>\n";
        while (list(
    $id,$name)=mysql_fetch_row($res)) {
            
    $str .= "<tr><td><a href='?action=select&amp;company=$id'>Select</td><td>$name</td></tr>\n";
        }
        
    $str .= "</table>";
        return 
    $str;
    }

    function 
    addressList($cid) {
        global 
    $fmCompany;
        
    $sql "SELECT a.CAID, a.Street, a.CITYID, a.Pincode, a.Areacode, a.Phone, a.Fax, a.Email, c.Company
                FROM Custaddress a
                INNER JOIN Customers c ON a.CID = c.CID
                WHERE a.CID = '$cid'"
    ;
        
    $res mysql_query($sql) or die(mysql_error());
        
    $str '<form method="post">
                <input type="hidden" name="fname" value="fmAddress">
                <table border="1"><center><font face=Verdana size=2 color=white>
                <tr><th>Street</th><th>City</th><th>Pincode</th><th>Areacode</th><th>Phone</th><th>Fax</th><th>Email</th>
                <th>Select</th></tr>'
    ;
        while (list(
    $caid$st$city$pc$ac$ph$fax$em$co)=mysql_fetch_row($res)) {
            
    $fmCompany $co;
            
    $str .= "<tr><td>$st</td><td>" citySelect($city'disabled') . "</td><td>$pc</td><td>$ac</td><td>$ph</td><td>$fax</td><td>$em</td>
                    <td><input type='radio' name='address' value='$caid'></td></tr>"
    ;
        }
        
    $str .= '</table><br>
        <input type="submit" name="action" value="Select address where the new person can be contacted">
        </form>'
    ;
        return 
    $str;
    }


    function 
    addForm() {
      global 
    $fmCompany;
           
    $str "<form method='post'>
                <input type='hidden' name='caid' value='$caid'>
                <input type='hidden' name='cid' value='$cid'>
                <table border='1'><center><font face=Verdana size=2 color=white>"
    ;

        
    $fmCompany $co;
        
    $str .= "<tr><td>Mobile</td><td><input type='text' value='$mobile' size='100'></td></tr>

                <tr><td>&nbsp</td><td><input type='submit' name='action' value='INSERT'></td></tr>"
    ;

        
    $str .= '</table></form>';
        return 
    $str;


      
    $sql "INSERT INTO Custcontact (CID, CAID ,Mobile) VALUES ('$cid', '$caid', '$mobile')           WHERE CAID = '{$_POST['caid']}' AND CID = '{$_POST['cid']}' ";
        
    mysql_query($sql);
        echo 
    "<center><font face=Verdana size=2 color=white>Contact Added";
    }

    if (isset(
    $_REQUEST['action'])) {

        switch (
    $_REQUEST['action'])  {
            case 
    'Search':
                    
    $srch $_POST['srch'];
                    
    $fmCompany stripslashes($_POST['srch']);
                    
    $body companyList($srch);
                    break;
            case 
    'select':
                    
    $body addressList($_GET['company']);
                    break;
                     case 
    'Select address where the new person can be contacted':
                    
    $body addForm($_POST['address']);
                    break;
                    case 
    'Insert':
                    
    $body '';
                    
    addForm();
                    break;
        }
    }
    else 
    $body '';
    ?>
    <form name='fmSearch' method='POST'>
            <input type="hidden" name="fname" value="fmSearch"><center><font face='Verdana' size='2' color=white>
            Company Name <input type="text" name="srch" value="<?php echo $fmCompany ?>" size="80">
            <input type="submit" name="action" value="Search">
    </form>

    <?php echo $body ?>

  • #2
    New Coder
    Join Date
    Jul 2006
    Location
    London
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Happy to help

    First of all, I would look at the design of your database, your tables should be normalised.
    Consider if the customer and address details really need to be separate etc.
    If you provide a proper description of what you are trying to achieve rather than 'what if scenario', I might be able to guide you through the design of both the db and subsequent functions.
    If you are not comfortable posting stuff here, you can message me via this forum.

    Cheers

  • #3
    Regular Coder
    Join Date
    Aug 2005
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The database is ok . I need to have the data in separate tables because of many to one and one to many relationships.

    Also, i have contacts who work out of 2 office locations of a company so i cannot be typing out the same address multiple times.

    The problem arises with the way i have defined addForm and the subsequent insert and isset operations. There's a problem them that i'm not able to straighten out !

    Any ideas ? Thanks


  •  

    Posting Permissions

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