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 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2005
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Vaule / Question might be really easy

    on this adddealer page (http://pastebin.com/298760) how can i have to country option save to rcnitror_zipcode.dealer.country ?
    since its getting the vaules from rcnitror_zipcode.countrys.name
    starts at line 22

    Code:
    <?php
        if(isset($_GET['submit'])){
            mysql_connect("localhost", "rcnitror_kacy", "");
            mysql_select_db("rcnitror_zipcode");
    $query = "insert into dealers(`address1`,`country`,`name`,`phone`,`url`,`fulltime`,`onroad`,`offroad`,`fax`,`email`,`zip`,    `hours`,`carry`,`order`) values ('".$_GET["Address1"]."','".$_GET["Country"]."','".$_GET["Name"]."','".$_GET["Phone"]."','".$_GET["URL"]."','".$_GET["fulltime"]."','".$_GET["onroad"]."','".$_GET["offroad"]."','".$_GET["Fax"]."','".$_GET["Email"]."','".$_GET["Zip"]."','".$_GET["hours"]."','".$_GET["carry"]."','".$_GET['order']."')";
    mysql_query($query) or die(mysql_error());
            if(!$query){
                echo "Sorry but there was an error when processing your request. Please try again. " . mysql_error();
            }
            else
            {
                echo "Success! <a href='search.html'>Return to search</a>";
            }
        }
        else
        {
    ?>
    <body>
        <form action='adddealer.php' method='get'>
    <?php
            mysql_connect("localhost", "rcnitror_kacy", "");
            mysql_select_db("rcnitror_zipcode");
    $select = "SELECT DISTINCT name FROM countries ORDER BY name";
     
    //the result of the query will be stored here
    $rs = mysql_query($select) or die(mysql_error()); 
     
     echo "<label>Please select your country: ";
        echo "<select name='country' id='country'>";
     
     
        //Each row in the rs will be an option
        while ($row = mysql_fetch_assoc($rs)) 
            {
                echo "<option value='".$row['name']."'>".$row['name']."</option>";
            }
    }
     
    //this closes the open .html tags
    echo "</label>";
    echo "</select>";
    ?>
    <br>  
            Dealer Name:        <input type='text' name='Name'><br>
            Hours:              <input type='text' name='Hours'><br>
            Telephone Number:   <input type='text' name='Phone'><br>
            Fax Number:         <input type='text' name='Fax'><br>
            Email Address:      <input type='text' name='Email'><br>
            Website:            <input type='text' name='URL'><br>
            Postcode:           <input type='text' name='Zip'><br>
            Address:           <input type='text' name='Address1'><br>
            Full time hobby shop:
                <input type='radio' name='fulltime' value='yes'>Yes
                <input type='radio' name='fulltime' value='No'>No<br>
            On-road track:
                <input type='radio' name='onroad' value='Yes'>Yes
                <input type='radio' name='onroad' value='No'>No<br>
            Off-road track:
                <input type='radio' name='offroad' value='Yes'>Yes
                <input type='radio' name='offroad' value='No'>No<br>
            Carry Integy parts in stock:
                <input type='radio' name='carry' value='Yes'>Yes
                <input type='radio' name='carry' value='No'>No<br>
            Special order Integy parts:
                <input type='radio' name='order' value='Yes'>Yes
                <input type='radio' name='order' value='no'>No<br>
     
            <input type='submit' name='submit'>
    </form>
    </body>
    </html>
     
    <?php ?>

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    save the id of the country in the dealers table and then when you need to get the name out search the country names table to find the name.

  • #3
    New Coder
    Join Date
    Feb 2005
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts
    im 2 new at this how would i do that? or what?

  • #4
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I'm assuming you country table has columns id and name (at least) with id being an auto incrementing key column.


    This will be the new code you need.

    PHP Code:
    <?php
        
    if(isset($_GET['submit'])){
            
    mysql_connect("localhost""rcnitror_kacy""");
            
    mysql_select_db("rcnitror_zipcode");
    $query "insert into dealers(`address1`,`country`,`name`,`phone`,`url`,`fulltime`,`onroad`,`offroad`,`fax`,`email`,`zip`,      `hours`,`carry`,`order`) values ('".$_GET["Address1"]."','".$_GET["Country"]."','".$_GET["Name"]."','".$_GET["Phone"]."','".$_GET["URL"]."','".$_GET["fulltime"]."','".$_GET["onroad"]."','".$_GET["offroad"]."','".$_GET["Fax"]."','".$_GET["Email"]."','".$_GET["Zip"]."','".$_GET["hours"]."','".$_GET["carry"]."','".$_GET['order']."')";
    mysql_query($query) or die(mysql_error());
            if(!
    $query){
                echo 
    "Sorry but there was an error when processing your request. Please try again. " mysql_error();
            }
            else
            {
                echo 
    "Success! <a href='search.html'>Return to search</a>";
            }
        }
        else
        {
    ?>
    <body>
        <form action='adddealer.php' method='get'>
    <?php
            mysql_connect
    ("localhost""rcnitror_kacy""");
            
    mysql_select_db("rcnitror_zipcode");
    $select "SELECT name,id FROM countries ORDER BY name";
     
    //the result of the query will be stored here
    $rs mysql_query($select) or die(mysql_error()); 
     
     echo 
    "<label>Please select your country: ";
        echo 
    "<select name='country' id='country'>";
     
     
        
    //Each row in the rs will be an option
        
    while ($row mysql_fetch_assoc($rs)) 
            {
                echo 
    "<option value='".$row['id']."'>".$row['name']."</option>";
            }
    }
     
    //this closes the open .html tags
    echo "</label>";
    echo 
    "</select>";
    ?>
    <br>  
            Dealer Name:        <input type='text' name='Name'><br>
            Hours:              <input type='text' name='Hours'><br>
            Telephone Number:   <input type='text' name='Phone'><br>
            Fax Number:         <input type='text' name='Fax'><br>
            Email Address:      <input type='text' name='Email'><br>
            Website:            <input type='text' name='URL'><br>
            Postcode:           <input type='text' name='Zip'><br>
            Address:           <input type='text' name='Address1'><br>
            Full time hobby shop:
                <input type='radio' name='fulltime' value='yes'>Yes
                <input type='radio' name='fulltime' value='No'>No<br>
            On-road track:
                <input type='radio' name='onroad' value='Yes'>Yes
                <input type='radio' name='onroad' value='No'>No<br>
            Off-road track:
                <input type='radio' name='offroad' value='Yes'>Yes
                <input type='radio' name='offroad' value='No'>No<br>
            Carry Integy parts in stock:
                <input type='radio' name='carry' value='Yes'>Yes
                <input type='radio' name='carry' value='No'>No<br>
            Special order Integy parts:
                <input type='radio' name='order' value='Yes'>Yes
                <input type='radio' name='order' value='no'>No<br>
     
            <input type='submit' name='submit'>
    </form>
    </body>
    </html>
     
    <?php ?>
    And anywhere you need to display the country name you will need to use this.

    PHP Code:
    mysql_connect("localhost""rcnitror_kacy""");
            
    mysql_select_db("rcnitror_zipcode");
    $query "SELECT * FROM `dealers` WHERE `id` = '$id' LIMIT 1;";
    $results mysql_query($query) or die(mysql_error());
    $row = (mysql_fetch_assoc($results));
    //variables accessible by $row['columnname']
    var_dump($row); //show all results

    //get country name
    $query2 "SELECT name FROM `countries` WHERE `id` = '".$row['country']."';";
    $results2 mysql_query($query2) or die(mysql_error());
    $row2 = (mysql_fetch_assoc($results2));
    $country $row2['name'];

    echo 
    $country;//show country name 

  • #5
    New Coder
    Join Date
    Feb 2005
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok let me try
    Last edited by bigredkacy; 06-11-2005 at 07:08 AM.


  •  

    Posting Permissions

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