drop down list to read from 2 fields in table and insert into 2nd table
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
<?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");
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
I kinda wish you would have add all the CSS for the code you presented.
But I did the best I could with what you gave.
I took your code and re-wrote it so that you have all the error messages display on the right side of the form.
I think once you have a look at it, you will like the way I laid it out.
Unfortunately it only display well in IE.
So you will have to fiddle around with the CSS to get it to display better in all browsers.
I did not have a copy of header.inc.php, so I don't know what it will do to the page once it's included.
If you wish to have me help you with the CSS then you will have to show me all your CSS.
And a link to the web site would be helpful.
Or if you don't have one setup yet, then the dimensions of your images would help.
I put all the error messages in $error_array.
This way you can easily change the error message text.