PHP - Dropdown - Remember Value On Submit
So I have a registration form setup. When the user submits the form it sets session variables for each of the form fields and then checks the database to see if the username is taken. If the username is taken I have the form fields values to display the value of what the user just submitted. My problem is I have 2 drop down fields: States and Countries I am using the the following for my countries dropdown box and it works to remember the selection the user made, BUT how can I have it remember the option name as well as the option value? IE if the user chooses United States of America and submits the form I want the drop down to display United States of America not US here is the code:
<select id="country" name="country" tabindex = "511"> <option value="<?php if(isset($_SESSION['country'])) echo $_SESSION['country']; ?>" selected="<?php if(isset($_SESSION['country'])) echo $_SESSION['country']; ?>"><?php if(isset($_SESSION['country'])) echo $_SESSION['country']; ?></option> <option value="">(please select a country)</option> <option value="AF">Afghanistan</option> <option value="AL">Albania</option> <option value="DZ">Algeria</option> <option value="AS">American Samoa</option> <option value="AD">Andorra</option> <option value="AO">Angola</option> <option value="AI">Anguilla</option> <option value="AQ">Antarctica</option> <option value="AG">Antigua and Barbuda</option> <option value="AR">Argentina</option> <option value="AM">Armenia</option> <option value="AW">Aruba</option> <option value="AU">Australia</option> <option value="AT">Austria</option> <option value="AZ">Azerbaijan</option> <option value="BS">Bahamas</option> <option value="BH">Bahrain</option> <option value="BD">Bangladesh</option> <option value="BB">Barbados</option> <option value="BY">Belarus</option> <option value="BE">Belgium</option> <option value="BZ">Belize</option> <option value="BJ">Benin</option> <option value="BM">Bermuda</option> <option value="BT">Bhutan</option> <option value="BO">Bolivia</option> <option value="BA">Bosnia and Herzegowina</option> <option value="BW">Botswana</option> <option value="BV">Bouvet Island</option> <option value="BR">Brazil</option> <option value="IO">British Indian Ocean Territory</option> <option value="BN">Brunei Darussalam</option> <option value="BG">Bulgaria</option> <option value="BF">Burkina Faso</option> <option value="BI">Burundi</option> <option value="KH">Cambodia</option> <option value="CM">Cameroon</option> <option value="CA">Canada</option> <option value="CV">Cape Verde</option> <option value="KY">Cayman Islands</option> <option value="CF">Central African Republic</option> <option value="TD">Chad</option> <option value="CL">Chile</option> <option value="CN">China</option> <option value="CX">Christmas Island</option> <option value="CC">Cocos (Keeling) Islands</option> <option value="CO">Colombia</option> <option value="KM">Comoros</option> <option value="CG">Congo</option> <option value="CD">Congo, the Democratic Republic of the</option> <option value="CK">Cook Islands</option> <option value="CR">Costa Rica</option> <option value="CI">Cote d'Ivoire</option> <option value="HR">Croatia (Hrvatska)</option> <option value="CU">Cuba</option> <option value="CY">Cyprus</option> <option value="CZ">Czech Republic</option> <option value="DK">Denmark</option> <option value="DJ">Djibouti</option> <option value="DM">Dominica</option> <option value="DO">Dominican Republic</option> <option value="TP">East Timor</option> <option value="EC">Ecuador</option> <option value="EG">Egypt</option> <option value="SV">El Salvador</option> <option value="GQ">Equatorial Guinea</option> <option value="ER">Eritrea</option> <option value="EE">Estonia</option> <option value="ET">Ethiopia</option> <option value="FK">Falkland Islands (Malvinas)</option> <option value="FO">Faroe Islands</option> <option value="FJ">Fiji</option> <option value="FI">Finland</option> <option value="FR">France</option> <option value="FX">France, Metropolitan</option> <option value="GF">French Guiana</option> <option value="PF">French Polynesia</option> <option value="TF">French Southern Territories</option> <option value="GA">Gabon</option> <option value="GM">Gambia</option> <option value="GE">Georgia</option> <option value="DE">Germany</option> <option value="GH">Ghana</option> <option value="GI">Gibraltar</option> <option value="GR">Greece</option> <option value="GL">Greenland</option> <option value="GD">Grenada</option> <option value="GP">Guadeloupe</option> <option value="GU">Guam</option> <option value="GT">Guatemala</option> <option value="GN">Guinea</option> <option value="GW">Guinea-Bissau</option> <option value="GY">Guyana</option> <option value="HT">Haiti</option> <option value="HM">Heard and Mc Donald Islands</option> <option value="VA">Holy See (Vatican City State)</option> <option value="HN">Honduras</option> <option value="HK">Hong Kong</option> <option value="HU">Hungary</option> <option value="IS">Iceland</option> <option value="IN">India</option> <option value="ID">Indonesia</option> <option value="IR">Iran (Islamic Republic of)</option> <option value="IQ">Iraq</option> <option value="IE">Ireland</option> <option value="IL">Israel</option> <option value="IT">Italy</option> <option value="JM">Jamaica</option> <option value="JP">Japan</option> <option value="JO">Jordan</option> <option value="KZ">Kazakhstan</option> <option value="KE">Kenya</option> <option value="KI">Kiribati</option> <option value="KP">Korea, Democratic People's Republic of</option> <option value="KR">Korea, Republic of</option> <option value="KW">Kuwait</option> <option value="KG">Kyrgyzstan</option> <option value="LA">Lao People's Democratic Republic</option> <option value="LV">Latvia</option> <option value="LB">Lebanon</option> <option value="LS">Lesotho</option> <option value="LR">Liberia</option> <option value="LY">Libyan Arab Jamahiriya</option> <option value="LI">Liechtenstein</option> <option value="LT">Lithuania</option> <option value="LU">Luxembourg</option> <option value="MO">Macau</option> <option value="MK">Macedonia, The Former Yugoslav Republic of</option> <option value="MG">Madagascar</option> <option value="MW">Malawi</option> <option value="MY">Malaysia</option> <option value="MV">Maldives</option> <option value="ML">Mali</option> <option value="MT">Malta</option> <option value="MH">Marshall Islands</option> <option value="MQ">Martinique</option> <option value="MR">Mauritania</option> <option value="MU">Mauritius</option> <option value="YT">Mayotte</option> <option value="MX">Mexico</option> <option value="FM">Micronesia, Federated States of</option> <option value="MD">Moldova, Republic of</option> <option value="MC">Monaco</option> <option value="MN">Mongolia</option> <option value="MS">Montserrat</option> <option value="MA">Morocco</option> <option value="MZ">Mozambique</option> <option value="MM">Myanmar</option> <option value="NA">Namibia</option> <option value="NR">Nauru</option> <option value="NP">Nepal</option> <option value="NL">Netherlands</option> <option value="AN">Netherlands Antilles</option> <option value="NC">New Caledonia</option> <option value="NZ">New Zealand</option> <option value="NI">Nicaragua</option> <option value="NE">Niger</option> <option value="NG">Nigeria</option> <option value="NU">Niue</option> <option value="NF">Norfolk Island</option> <option value="MP">Northern Mariana Islands</option> <option value="NO">Norway</option> <option value="OM">Oman</option> <option value="PK">Pakistan</option> <option value="PW">Palau</option> <option value="PA">Panama</option> <option value="PG">Papua New Guinea</option> <option value="PY">Paraguay</option> <option value="PE">Peru</option> <option value="PH">Philippines</option> <option value="PN">Pitcairn</option> <option value="PL">Poland</option> <option value="PT">Portugal</option> <option value="PR">Puerto Rico</option> <option value="QA">Qatar</option> <option value="RE">Reunion</option> <option value="RO">Romania</option> <option value="RU">Russian Federation</option> <option value="RW">Rwanda</option> <option value="KN">Saint Kitts and Nevis</option> <option value="LC">Saint LUCIA</option> <option value="VC">Saint Vincent and the Grenadines</option> <option value="WS">Samoa</option> <option value="SM">San Marino</option> <option value="ST">Sao Tome and Principe</option> <option value="SA">Saudi Arabia</option> <option value="SN">Senegal</option> <option value="SC">Seychelles</option> <option value="SL">Sierra Leone</option> <option value="SG">Singapore</option> <option value="SK">Slovakia (Slovak Republic)</option> <option value="SI">Slovenia</option> <option value="SB">Solomon Islands</option> <option value="SO">Somalia</option> <option value="ZA">South Africa</option> <option value="GS">South Georgia and the South Sandwich Islands</option> <option value="ES">Spain</option> <option value="LK">Sri Lanka</option> <option value="SH">St. Helena</option> <option value="PM">St. Pierre and Miquelon</option> <option value="SD">Sudan</option> <option value="SR">Suriname</option> <option value="SJ">Svalbard and Jan Mayen Islands</option> <option value="SZ">Swaziland</option> <option value="SE">Sweden</option> <option value="CH">Switzerland</option> <option value="SY">Syrian Arab Republic</option> <option value="TW">Taiwan, Province of China</option> <option value="TJ">Tajikistan</option> <option value="TZ">Tanzania, United Republic of</option> <option value="TH">Thailand</option> <option value="TG">Togo</option> <option value="TK">Tokelau</option> <option value="TO">Tonga</option> <option value="TT">Trinidad and Tobago</option> <option value="TN">Tunisia</option> <option value="TR">Turkey</option> <option value="TM">Turkmenistan</option> <option value="TC">Turks and Caicos Islands</option> <option value="TV">Tuvalu</option> <option value="UG">Uganda</option> <option value="UA">Ukraine</option> <option value="AE">United Arab Emirates</option> <option value="GB">United Kingdom</option> <option value="US">United States</option> <option value="UM">United States Minor Outlying Islands</option> <option value="UY">Uruguay</option> <option value="UZ">Uzbekistan</option> <option value="VU">Vanuatu</option> <option value="VE">Venezuela</option> <option value="VN">Viet Nam</option> <option value="VG">Virgin Islands (British)</option> <option value="VI">Virgin Islands (U.S.)</option> <option value="WF">Wallis and Futuna Islands</option> <option value="EH">Western Sahara</option> <option value="YE">Yemen</option> <option value="YU">Yugoslavia</option> <option value="ZM">Zambia</option> <option value="ZW">Zimbabwe</option> </select> Similar TutorialsThe situation: The script is fetching data from the database and printing it out with a while loop, at the same time the rows are being broken up into pages with pagination. The problem: I'm using if and elseif statements for a sorting and ordering functionality. When I now choose a certain category to print out ONLY the chosen category, then the pagination will still be intact. But as soon as I click forward on the pagination navigation links, a page refresh (reload) will happen and the query will default to it's default setting which is category = ALL (and not anymore that specific category I chose earlier). My question: Is there any way to make the script remember the last pressed submit condition? Meaning that if I choose a certain category which should be printed, then the chosen category still remains chosen even if I click the pagination links which cause a page reload? Here's a small script excerpt, to help picture the example: $select_category is taken with $_REQUEST from a drop down menu. // ALL but NO OTHER if (($select_category == 'All') || (!isset($select_category)) && (!isset($most_liked))) { $query = "SELECT * FROM con, user WHERE con.user_id = user.user_id ORDER BY contributed_date DESC"; pagination_start ($dbc, $query); $offset = $pag_array[0]; $rows_per_page = $pag_array[1]; $query = $query . " LIMIT $offset, $rows_per_page"; knuffix_list ($query, $dbc); pagination_end ($pag_array); // CATEGORY but NOT most_liked } elseif (isset($select_category) && !isset($most_liked)) { $query = "SELECT * FROM con, user WHERE con.user_id = user.user_id AND category = '$select_category' ORDER BY contributed_date DESC"; pagination_start ($dbc, $query); $offset = $pag_array[0]; $rows_per_page = $pag_array[1]; $query = $query . " LIMIT $offset, $rows_per_page"; knuffix_list ($query, $dbc); pagination_end ($pag_array); so I need to know how to make this drop down include hidden fields in it: Code: [Select] <form id="myform1" method="POST"> <select onchange="document.getElementById('myform1').submit()"> <?php //start the table, and the row. // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM products"); while($row = mysql_fetch_array($sql)){ $product = $row["product"]; $id =$row["id"]; $price =$row["price"]; ?> <option><input type="text" name="hiddenField2" class="hiddenField2" value="<?php echo $id; ?>" /> <input type="text" name="hiddenField1" class="hiddenField1" value="<?php echo $price; ?>" /><?php echo $product; ?> </option> <?php // start a column } ?> </select> <noscript> <input type="submit" value="Go" id="Submit1" /> </noscript> </form> Kind of like is shown.......so that each option has an id. then I need it to submit to this code: Code: [Select] <script type="text/javascript"> $(document).ready(function(){ $(".myform1").validate({ debug: false, submitHandler: function(form) { // do other stuff for a valid form $.post('process.php', $(".myform1").serialize(), function(data) { $("#price").load("index.php #price");$("#total").load("index.php #total"); }); } }); }); </script> . Can anyone help? I hope this makes sense???? Hopefully someone can help, firstly i am a newbie at php coding but keen to learn more.
Here is my problem
The database is built correctly with all the information i need, the first part is the dropdown menu which you select a car, next you choose a month and mileage - from there it shall show you the correct price for each one. There is columns for each price, mileage and months i just need to figure out how best to start this thing.
I first started by this
$query = "SELECT DISTINCT Full_Description FROM import"; This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=331067.0 Hello there, I'm trying to show a picture based on the value that was chosen in the dropdown menu of the page before the submit. Let's say i'm having a drop down form with 3 values: Porsche, BMW, Audi, the form also consists of a button to submit form and some other text fields but these aren't really relevant. So what i want is, you choose whatever car, let's say BMW, fill in all the other data of the form, hit submit, and on the next page it should show a Picture which i define for each car. I hope i explained that somehow understandable. Thanks in advance, Sabine hi all, does anyone know the name of the following its a way to make a huge string than can have variables in it. look a bit like this but couldnt remember the right syntax, nor the name so was kinda hard to look on google. ABC>>> some stuff inside ABC; Hey guys not sure what this is called but does anyone have more information on it. Ok when you visit a part of a site or a profile or what ever?? :S:S and you redirect them to login how can u then send them back to where they was when they have logged in? hope someone can help. Hi, I'm creating a remember me feature for my site which obviously sets a cookie and when the visitors loads the site again,he would already be logged in. This is a part of the code which is related : Code: [Select] $login_email = request_var('login_email', ''); $login_password = request_var('login_password', ''); $login_remember = (isset($_POST['remember']) && $_POST['remember'] == 1) ? true: false; setcookie('login_email', $_POST['login_email'], time()+60*60*24*365, '/','localhost',false); setcookie('login_password', md5($_POST['login_password']), time()+60*60*24*365, '/','localhost',false); HTML: Code: [Select] <strong class="normal"><input type="checkbox" name="remember" value="1">Remember</strong> I want to save live data into file. My script fetch the data (one by one) and save it into file by amend method. The live data is not regular and every time it must be checked if the value has been updated or it is still the last value. One way to do so is to read the last line of the file and compare it with the fetched value. But in this case, I need to read the file for every check. Is there a way to remember the last value and compare it with the coming value? to write only new value into the file. Time to ask a stupid question. I have a remember me cookie being set for my login page but I'm wondering what I need to do so that the next time the user comes back to the login page it already has the checkbox checked and the username in the username field which is the cookie. Okay, this is a head scratcher for me... About 10-15 years ago, there was this framework that seemed to be pretty popular in the LAMP work for quickly building websites. (I think it was written in PHP.) The thing I recall about it was that it you could create your own markup tags to markup up fields using curly brackets { }. I wish I could be more specific but this is all that is coming to mind. Any clues of what I might be thinking about? I am wondering how to keep a checkbox checked? I have the folllowing code and it is outputting the correct info, but when i tick checkbox, and then click box "SAVE Days and Recipes Chosen" the checkbox doesn't get set. <?php for($i = 0; $i < $rows; $i++) { ?> <tr> <?php for($j = 0; $j < $columns; $j++) { echo "<TD><font color='8678E9'>" . $data[$i + ($j * $rows)] . "</font></TD>\n"; ?> <td><input type='checkbox' name=$R1 <?php if($R1=="checked"){$R1=="checked"; echo $R1;} elseif($R1=="unchecked"){$R1=="unchecked"; echo $R1;} ?> <td><?php echo"<TD><font color='3923D6'><font size=4>" . $data2[$i + ($j * $rows)] . "</TD>\n"; ?></font></td> <?php echo"<TD align='center'><font color='3923D6'><font size=4>" . $data4[$i + ($j * $rows)] . "</TD>\n"; ?></font></td> <?php echo"<TD align='center'><font color='3923D6'><font size=4>" . $data5[$i + ($j * $rows)] . "</TD>\n"; ?></font></td> <td align="centre"><input type="checkbox" name="ch1[]" method="POST" value=<?php echo $data3[$i + ($j * $rows)]?>,1 >M<br> <input type="checkbox" name="ch1[]" value=<?php echo $data3[$i + ($j * $rows)]?>,2 method="POST">Tu<br> <input type="checkbox" name="ch1[]" value=<?php echo $data3[$i + ($j * $rows)]?>,3 method="POST">W<br> <input type="checkbox" name="ch4[]" <?php if (!isset($ch4)){$Value='unchecked'; echo $Value;} elseif(isset($ch4)){$Value='checked'; echo $Value;}?> value=<?php echo $data3[$i + ($j * $rows)]?>,4 method="POST">Th<br></td> <td align="centre"><input type="checkbox" name="ch1[]" value=<?php echo $data3[$i + ($j * $rows)]?>,5 method="POST">F<br> <input type="checkbox" name="ch1[]" value=<?php echo $data3[$i + ($j * $rows)]?>,6 method="POST">Sa<br> <input type="checkbox" name="ch1[]" value=<?php echo $data3[$i + ($j * $rows)]?>,7 method="POST">Su<br></td> <?php echo"<TD><font color='3923D6'><font size=4>" . $data6[$i + ($j * $rows)] . "</TD>\n"; ?></font></td> <td style='font-weight: bold; text-align: left;'><font color='8678E9'>                    </font></td> <?php } echo "</TR>\n"; } echo "</TABLE>\n"; echo "<br>"; It is the following part that i cuurently need help with <td><input type='checkbox' name=$R1 <?php if($R1=="checked"){$R1=="checked"; echo $R1;} elseif($R1=="unchecked"){$R1=="unchecked"; echo $R1;} ?> I haven't looked at the other checkbox part of <td align="centre"><input type="checkbox" name="ch1[]" method="POST" value=<?php echo $data3[$i + ($j * $rows)]?>,1 >M<br> <input type="checkbox" name="ch1[]" value=<?php echo $data3[$i + ($j * $rows)]?>,2 method="POST">Tu<br> <input type="checkbox" name="ch1[]" value=<?php echo $data3[$i + ($j * $rows)]?>,3 method="POST">W<br> <input type="checkbox" name="ch4[]" <?php if (!isset($ch4)){$Value='unchecked'; echo $Value;} elseif(isset($ch4)){$Value='checked'; echo $Value;}?> value=<?php echo $data3[$i + ($j * $rows)]?>,4 method="POST">Th<br></td> <td align="centre"><input type="checkbox" name="ch1[]" value=<?php echo $data3[$i + ($j * $rows)]?>,5 method="POST">F<br> <input type="checkbox" name="ch1[]" value=<?php echo $data3[$i + ($j * $rows)]?>,6 method="POST">Sa<br> <input type="checkbox" name="ch1[]" value=<?php echo $data3[$i + ($j * $rows)]?>,7 method="POST">Su<br></td> Appreciate any suggestions Hi guys, I wonder if any if you could help me: I have created a login page with "remember me" function... The page will redirect either to Admin Page or User Page depends their 'level'. But when I logged in as Admin and checked the box "remember me" and close all the browser to see IF the "remember me" work. When I open a new browser - and go to the index page - it is okay, I can view the page.... but it redirect me to the USER page NOT Admin page. Does anyone know why this happens? Hi I'm hoping someone can point me in the right direction. I'm trying to create a single page that contains a couple of checkboxes. When the first checkbox is checked I want to set a session. When the second chechbox is checked I want to set a different session. When the page submits ( to itself ) I'd like the checkboxes to reflect if they are checked or not. I can sort of do that part,but I'm having major issues with unsetting the sessions and updating the checkboxes to reflect this. Does anyone have a simple example on how to do this. Many Thanks I am working on a site that is going to have hundreds of polls that people can vote on. Once any user creates a new poll (vote: Hayden Panettiere vs. Kristen Bell as an example) I want to have the database remember what member voted on what, for each poll. So user 1 voted Hayden, user 327 voted Kristen.. etc.. I expect up to 500 users to vote on each topic, but a new column to store each username that voted seems insane. I was thinking arrays, but am not sure if that would work. I don't think that a new table per poll would be very efficient either, it would be like 500++ tables on one database. To explain better, my username is Paradox and I vote for Kristen Bell. When I look at this database I want to see: ID Title Option1 Option2 People who voted option 1(27 people) People who voted option 2(783 people) 1 Heroes 27 783 {Blah, Blah, Blah} {Paradox, Blah, Blah} Is an array a good way to go about this? Because I also want to be able to expand the array to notify each member they voted with the winning or losing team once the poll expires. I am about to attempt to write my first php script from scratch after a year or so of copying and adapting code. I am going to do a registration/login in system and thinking ahead, want to make sure that once someone is logged in, this information is passed from page to page (so they do not have to log in again on each page) and I would also like to provide a 'Remember Me' option. I have had a read up and from what I gather, sessions would be better for showing someone is logged in from page to page and cookies would be the only way to implement a 'Remember Me'. Would this be the best way to approach this or is/are there better ways? Thanks in advance Steve Is it possible to remember the last created random number with PHP or do I need to make use of MySQL? I want to generate an equation with submit button 1 and echo it out, and then I want the script to calculate the printed out equation with submit button 2. The problem: As soon as I click submit button 2, the numbers change into different random numbers, since the PHP starts scanning from the top of the file again as soon as the second button has been pressed. $gen = $_POST['gen']; $calc = $_POST['calc']; $x1 = random_number (); $x2 = random_number (); $op = random_op (); echo " <form action='' method='POST'> <input type='submit' name='gen' value='Generate' /><br /> <input type='submit' name='calc' value='Calculate' /> </form> "; if ($gen) { echo "$x1 $op $x2 = ? <br /><br />"; } if ($calc) { switch ($op) { case '+' : $row_1 = $x1 + $x2; break; case '-' : $row_1 = $x1 - $x2; break; case '*' : $row_1 = $x1 * $x2; break; case '/' : $row_1 = $x1 / $x2; break; } echo "$x1 $op $x2 = $row_1"; } I could of course insert the generated numbers into the database and fetch it out again, but I was wondering if it's possible to remember the numbers (even when the 2nd submit buttons has been pressed) within PHP as well? thanks. Hi everyone, On my website i have a drop down box on the account information page that has a list of countries. In the example below, im using the php to do 2 things, 1: if the user changes the country and clicks submit but an error is found on the page, rather than revert back to the original country it stays as the newly selected one. 2: if the user does not change the country, the country from the database is simple displayed. As you can see below it is taking up quite a bit of code. I was wondering if anybody has any ideas how i can make this smaller? <select name="country"> <option value="select" selected>Select...</option> <option value="Afganistan" <?php if ($submit) { if ($country == "Afganistan"){ echo "selected";}} else {if ($row['country'] == "Afganistan") {echo "selected";}} ?>>Afghanistan</option> <option value="Albania" <?php if ($submit) {if ($country == "Albania"){echo "selected";}} else {if ($row['country'] == "Albania") {echo "selected";}} ?>>Albania</option> <option value="Algeria" <?php if ($submit) {if ($country == "Algeria"){echo "selected";}} else {if ($row['country'] == "Algeria") {echo "selected";}} ?>>Algeria</option> <option value="American Samoa" <?php if ($submit) {if ($country == "American Samoa"){echo "selected";}} else {if ($row['country'] == "American Samoa") {echo "selected";}} ?>>American Samoa</option> <option value="Andorra"<?php if ($submit) {if ($country == "Andorra"){echo "selected";}} else {if ($row['country'] == "Andorra") {echo "selected";}} ?>>Andorra</option> <option value="Angola"<?php if ($submit) {if ($country == "Angola"){echo "selected";}} else {if ($row['country'] == "Angola") {echo "selected";}} ?>>Angola</option> Thanks I would like to know how to take details of my 'users' table from mysql database and check if that user is logged in using cookies or sessions somehow and have that users username displayed on my site, something like: user logged in as: (username), how is this done? What would you guys need to see in order for you to help me? im guessing the login and register scripts which are below, if you need anymore let me know, thanks. Login script: Code: [Select] <?php if(isset($_POST['submit'])){ //check for submit button click $username = $_POST['myusername']; $password = $_POST['mypassword']; // proceed with rest of code $self = $_SERVER['PHP_SELF']; $referer = $_SERVER['HTTP_REFERER']; #if either form field is empty return to the log-in page if( (!$username ) or (!$password ) ) { header( "Location:$referer" ); exit(); } #connect to mysql $conn = @mysql_connect( "myserver", "username", "password" ) or die( "Could not connect" ); #select database $rs = @mysql_select_db( "removalspacelogin", $conn ) or die ( "Could not select db" ); #create query $sql="select * from users where username = '$username' and upassword = '$password'"; #execute query $rs = mysql_query( $sql, $conn ) or die( mysql_error() ); #get number of rows that match username and password $num = mysql_numrows( $rs ); #if there is a match the log-in is done if( $num != 0 ) { header( "Location:login_success.php" ); } else #or return to: login.php { header( "Location:$referer" ); exit(); } } ?> <?php ini_set("display_errors","ON"); ?> <html> <head><title>Check-login</title></head> <body> <?php echo( $msg ); ?> </body> </html> Register users script: Code: [Select] <?PHP $user_name = "removalspace"; $password = "123"; $database = "removalspacelogin"; $server = "removalspacecom.ipagemysql.com"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL = "INSERT INTO users (username, upassword, email) VALUES ('" .$username. "', '" .$upassword. "', '" .$email. "')"; $result = mysql_query($SQL); header( 'Location: http://www.removalspace.com/index.php' ); exit(); } else { print "Database NOT Found "; mysql_close($db_handle); } ?> |