Page 1 of 1

drop down list to read from 2 fields in table and insert in

Posted: Fri Nov 28, 2008 6:43 pm
by lallen30
I'm new to php and I've created a registration page.

This a registration page for a garbage company that when submitted needs let the customer know what their pick up day is based on the name of their street.

I have a drop down list field called 'streetname' which reads from one table that has a list of street names in one column and days in another column. The user can select their street and when submitted it inserts that street name into another table which is called users. This part seems to work fine but what I also need is for the 'day' field in the same row in the "street_day_list" table to be inserted into the same row in the "users" table.

If anyone can please look at my code and let me know what I can add or change to make it work I would be extremely grateful.
Thank you, Larry

the drop down menu section starts on line 117

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="layout.css" rel="stylesheet" type="text/css" />
<script src="rollover.js" type="text/javascript"></script>
<style type="text/css">
.style1 {
    font-size: 24;
    color: #FFFFFF;
    font-weight: bold;
}
.style2 {font-size: 24px;
    color: #FFFFFF;
    font-weight: bold;
}
.style3 {font-size: 27px;
    color: #FFFFFF;
    font-weight: bold;
}
#apDiv1 {
    position:absolute;
    left:170px;
    top:14px;
    width:842px;
    height:80px;
    z-index:auto;
    padding: 10px;
}
#apDiv2 {
    position:absolute;
    left:328px;
    top:93px;
    width:572px;
    height:573px;
    z-index:2;
}
#apDiv3 {
    position:static;
    left:480px;
    top:448px;
    width:254px;
    height:45px;
    z-index:3;
    font-family: Arial, Helvetica, sans-serif;
    border-top-style: solid;
    border-right-style: solid;
    border-bottom-style: solid;
    border-left-style: solid;
 
}
</style>
<script src="../Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>
 
<body  id="page">
<div align="center" id="apDiv2">
 
<?php
 
include("header.inc.php");
 
 
    
    ?>
  <form method="POST" action="register.php">
      <table border="0" style="font-size: 15px; font-weight:bold; font-family: Arial">
          <tr>                
            <td width="176" align="right">
                        <div align="right">Username:                </div></td>
      <td width="635" align="left">
<input type="text" name="username" value="<?php echo $_POST['username'];?>" />                </td>
          </tr>
            <tr>                
                <td width="176" align="right">
                        <div align="right">Password:                </div></td>
                <td align="left">
                        <input type="password" name="password" value="<?php echo $_POST['password'];?>" />                </td>
            </tr>
            <tr>                
                <td width="176" align="right">
                        <div align="right">E-Mail:                </div></td>
                <td align="left">
                        <input name="email" type="text" value="<?php echo $_POST['email'];?>" size="40" />                </td>
            </tr>
            <tr>                
                <td width="176" align="right">
                        <div align="right">First Name:                </div></td>
                <td align="left">
                        <input type="text" name="firstname" value="<?php echo $_POST['firstname'];?>" />                </td>
            </tr>
            <tr>                
                <td width="176" align="right">
                        <div align="right">Last Name:                </div></td>
                <td align="left">
                        <input type="text" name="lastname" value="<?php echo $_POST['lastname'];?>" />                </td>
            </tr>
            <tr>
              
              <td>&nbsp;</td>
          </tr>
              <tr align="right">
              <td width="176"><div align="right"></div></td>
              </tr>
            <tr>                
                <td width="176" align="right"><div align="right">Street number:</div></td>
                <td align="left"><input name="streetnumber" type="text" value="<?php echo $_POST['streetnumber'];?>" size="11" /></td>
            </tr>
            <tr>                
              <td width="176" align="right">
                <div align="right">Street name:</div></td>
              <td align="left">
            
                <?php 
                        // If submitted, check the value of "select". If its not blank value, get the value and put it into $select.
                        if(isset($select)&&$select!=""){
                        $select=$_GET['select'];
                        }
        
                    ?>
                <select name="streetname">
                  <option value="">Please choose your street</option>
                  <?PHP
                                // Get records from database (table "street_day_list").
                                $list=mysql_query("SELECT * FROM street_day_list");
 
                                $row_list = mysql_fetch_assoc($list);
                                $day = $row_list['day'];
 
 
                                // Show records by while loop.
                                while($row_list=mysql_fetch_assoc($list)){
                                
                                ?>
                  <option value="<?PHP 
                            echo $row_list['id']; ?>" <?PHP if($row_list['id']==$select){ echo "streetname", "day"; }?>><?PHP echo $row_list['streetname'];
//                                $day = $row_list['day']==$select;
 
                                  
                                  
                                   ?> </option>
                  <?PHP
                                // End while loop.
                                }
                                ?>
                </select></td>
</tr>
            <tr>                
                <td width="176" align="right">
                        <div align="right">Phone Number:                </div></td>
                <td align="left">
                        <input type="text" name="phonenumber" value="<?php echo $_POST['phonenumber'];?>" />                </td>
            </tr>
            <tr>                
                <td width="176" align="right"><div align="right">Other Number:                </div></td>
                <td align="left">
                        <input type="text" name="othernumber" value="<?php echo $_POST['othernumber'];?>" />                </td>
            </tr>
            <tr>
              <td align="right">&nbsp;</td>
              <td align="left"><input type="submit" name="submit" value="Submit" /></td>
          </tr>
            <tr colspan="2" align="right">
                <td width="176"> 
                  <div align="right"></div></td>
            </tr> 
    </table>
</form>
    <p>
  <?php
        
        if($_POST['submit']){
        
            //error checking
            
            $username = $_POST['username'];
            $password = $_POST['password'];
            $email = $_POST['email'];
            $firstname = $_POST['firstname'];
            $lastname = $_POST['lastname'];
            $streetnumber = $_POST['streetnumber'];
            $streetname = $_POST['streetname'];
            $phonenumber = $_POST['phonenumber'];
            $othernumber = $_POST['othernumber'];
            
            $curnum = 0;
            
            if(!$username) {
                $curnum ++;
                echo "<font color='red'>". $curnum . ". Please enter a Username name</font><br>\n"; ?><br><?php
            }
            
            if(!$password) {
                $curnum ++;
                echo "<font color='red'>". $curnum . ". Please enter a Password name</font><br>\n"; ?><br><?php
            }
 
            if(!$email) {
                $curnum ++;
                echo "<font color='red'>". $curnum . ". Please enter a Password name</font><br>\n"; ?><br><?php
            }
            if(!$firstname) {
                $curnum ++;
                echo "<font color='red'>". $curnum . ". Please enter a First name</font><br>\n"; ?><br><?php
            }
            if(!$lastname) {
                $curnum ++;
                echo "<font color='red'>". $curnum . ". Please enter a Last name</font><br>\n"; ?><br><?php
            }
            if(!$streetnumber) {
                $curnum ++;
                echo "<font color='red'>". $curnum . ". Please enter a Street Number</font><br>\n"; ?><br><?php
            }
            if(!$streetname) {
                $curnum ++;
                echo "<font color='red'>". $curnum . ". Please enter a Street name</font><br>\n"; ?><br><?php
            }
            if(!$phonenumber) {
                $curnum ++;
                echo "<font color='red'>". $curnum . ". Please enter a Phone Number</font><br>\n";
            }
 
 
            
            $sql = "SELECT * FROM `users` WHERE `username`='".$username."'";
 
            $res = mysql_query($sql) or die(mysql_error());
            
            If(mysql_num_rows($res) > 0){
            
                $curnum ++;
                echo $curnum . ". We apologize but the username <b>".$username."</b> has already been taken.<br>&nbsp; &nbsp; Please try another Username.<br>";
            }
    
            
                if($curnum == 0){
 //                              if($day == Tuesday){
                               
//                              if($row_list['id']==$select){ echo 'name'; }
 
                               
                    mysql_query("INSERT INTO `users` VALUES(`id`,'".$username."','".$password."','".$email."','".$firstname."','".$lastname."','".$streetnumber."','".$streetname."','".$phonenumber."','".$othernumber."', '".$day."')") or die(mysql_error());
 
            
                    echo "<font color='green'><b>Thank you ".$firstname." for registering.<br><br>
                                                Your username is ".$username.". <br><br>
                    <?php ?>                            Your password is ".$password.". <br><br>
                                                Please note that your pick up day is </b></font>";
 
//                                if($streetname == 5){
                                
                                echo $day;
 
//                          }
//                  } else {
//                      echo "We appoligize but our registration is temporarily down please click here to continue.";
//                  }
                
                    ?><br><br><div id="apDiv3">
  <p>&nbsp;</p>
  <p><a href="login.php">Click here to Login</a></p>
</div>
  <?php
 
            }
 
            }
        ?>
</p>
 
 
 
 
        </p>
 
 
 
 
 
 
</div>
<div class="w">
    <div id="header">
        <div id="apDiv1">
          <p align="center" class="style3">Gwinnett Clean and Beautiful Service, Inc.</p>
          <p align="center" class="style2">&nbsp;</p>
          <p align="center"><span class="style1">Services provided exclusivly by:WASTEPRO of Georgia, Inc</span><br />
          </p>
      </div>
      <a href="index.html"><img alt="" src="images/logo.gif" class="logo" /></a><br />
      <br />
    </div>
  <div id="content"><br />
  </div>     
  <div id="footer">Waste Pro </div>
</div>
 
</body>
</html>