Jump to content

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


lallen30

Recommended Posts

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

 

<html>
<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> </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"> </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>    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> </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"> </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>

once posted, query the database again to return the day based on the street name, something like this do it just after listing all the other vars

 

$sql_day = "SELECT day FROM street_day_list WHERE streetname = '".$_POST['streetname']."'";
$sql_day_query = mysql_query($sql_day) or die(mysql_error());
$dayRow = mysql_fetch_assoc($sql_day_query);

$day = $dayRow['day'];

Thank you very much for your reply I added the code you provided but i couldnt get it to work. I think I might not be putting it in the right place. this is where I added it.

 

		$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'];

		$sql_day = "SELECT day FROM street_day_list WHERE streetname = '".$_POST['streetname']."'";
		$sql_day_query = mysql_query($sql_day) or die(mysql_error());
		$dayRow = mysql_fetch_assoc($sql_day_query);

		$day = $dayRow['day'];

		$curnum = 0;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.