Where to put the validation code of php form validation - php

If I am doing form validation for the user input, I have to put the phpcode in the page with form right?
Also in the <form> tag do I have to specify anything. I mean if there is an error the user will have to return to the same input page with errors showing up. If it was successful input, the user should goto order-process.php
PHP Validation Code:
<?php
$name = $_POST['name'];
$nameregex = '/^[a-zA-Z]+\s?[a-zA-Z]+$/';
if (!preg_match($nameregex, $name)) {
echo '<font color=red>Please enter a valid name</font>';
}
$email = $_POST['email'];
$emailregex = '/^[a-zA-Z\_\-\.0-9]+\#[a-zA-Z\_\-\.0-9]+$/';
if (!preg_match($emailegex, $email)) {
echo '<font color="red">please Enter a valid email id</font>';
}
$address = $_POST['address'];
$addressregex = '/^[0-9a-zA-Z\,\s]+$/';
if (!preg_match($$addressregex, $address)) {
echo '<font color="red">please Enter a valid Address</font>';
}
$state = $_POST['state'];
$stateregex = '/^[a-zA-Z]+\s?[a-zA-Z]+$/';
if (!preg_match($stateregex, $state)) {
echo '<font color="red">please Enter a valid state name</font>';
}
$pincode = $_POST['pincode'];
$pincoderegex = '/^[a-zA-Z]+\s?[a-zA-Z]+$/';
if (!preg_match($pincoderegex, $pincode)) {
echo '<font color="red">please Enter a valid pincode</font>';
}
?>
HTML Form Code:
<form name="orderform1" action="process-order.php" method="post" id="orderform">
<ol>
<li>
<label for="name">Your Name:*</label>
<input id="name" name="name" class="text" />
</li>
<li>
<label for="email">E-Mail:*</label>
<input id="email" name="email" class="text" />
</li>
<li>
<label for="address1">Address Line 1:*</label>
<input id="address1" name="address1" class="text" />
</li>
<li>
<label for="address2">Address Line 2:</label>
<input id="address2" name="address2" class="text" />
</li>
<li>
<label for="state">State/Province*:</label>
<input id="state" name="state" class="text" />
</li>
<li>
<label for="address">City:</label>
<input id="address" name="address" class="text" />
</li>
<li>
<label for="pincode">Pin Code:*</label>
<input id="pincode" name="pincode" class="text" />
</li>
<li>
<label for="country">Country:*</label>
<select name="country">
<option value="AF">Afghanistan</option>
<option value="AX">Ã…Land Islands</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 Herzegovina</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</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="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="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=" Gg">Guernsey</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 Island And Mcdonald 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="IM">Isle Of Man</option>
<option value="IL">Israel</option>
<option value="IT">Italy</option>
<option value="JM">Jamaica</option>
<option value="JP">Japan</option>
<option value="JE">Jersey</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">Macao</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="PS">Palestinian Territory, Occupied</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="SH">Saint Helena</option>
<option value="KN">Saint Kitts And Nevis</option>
<option value="LC">Saint Lucia</option>
<option value="PM">Saint Pierre And Miquelon</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="CS">Serbia And Montenegro</option>
<option value="SC">Seychelles</option>
<option value="SL">Sierra Leone</option>
<option value="SG">Singapore</option>
<option value="SK">Slovakia</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="SD">Sudan</option>
<option value="SR">Suriname</option>
<option value="SJ">Svalbard And Jan Mayen</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="TL">Timor-Leste</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</option>
<option value="EH">Western Sahara</option>
<option value="YE">Yemen</option>
<option value="ZM">Zambia</option>
<option value="ZW">Zimbabwe</option>
</select>
<li>
<label for="phone">Phone Number(With Country Code):*</label>
<input id="phone" name="phone" class="text" />
</li>
<li class="buttons">
<input type="submit" name="imageField" id="imageField" value="Proceed to Payment" class="send" />
<div class="clr"></div>
</li>
</ol>
</form>

You have to put the php code (for validation) in 'process-order.php'. It will receive the form data.

You can redirect to the same page (i.e. the order form) and choose to display different HTML content depending on the result of the validation:
<?php
// Validation routine here -- you can count the number of validation errors and use this as decision whether to show the form again or not
if ($_POST['submit']) {
$errorCount = 0;
// Validations here + count errors
}
// -- end of validation routine
if ($errorCount == 0) { ?>
<h1>Order Processed</h1>
<p>Your order was processed...</p>
<?php }
// If error count is above zero OR the submit button was never pressed, display form:
else { ?>
<form>...</form>
<?php } ?>

It will go to the form's ACTION (which is process-order.php).
If validation fails, though, the user will have to go back to the form page and everything will be blank.
To have all form fields pre-populated again so everything isn't blank, you can do, for instance
<input id="pincode" name="pincode" class="text" />
change to
<input id="pincode" name="pincode" class="text" value='<?php echo (isset($_POST['pincode'])) ? $_POST['pincode'] : '' ?>' />

Related

Mysqli php edit form

I have made some changes to my edit form to update two tables with one query. I am receiving an error "Access denied for user ''#'localhost' to database 'linkyoutube'". I have granted permissions to both tables using the following SQL statements:
CREATE USER 'admin'#'localhost' IDENTIFIED BY 'SDFASF##$R##$';
Grant select, insert, update, delete on linkyoutube.person to 'admin'#'localhost';
Grant select, insert, update, delete on linkyoutube.submited to 'admin'#'localhost';
Any help appreciated.
<?php
//require "admin_login.php";
//include "admin_connect.php"
$conn = mysqli_connect("localhost", "admin", "admin9090", "linkyoutube");
mysql_select_db("linkyoutube");
if (mysqli_connect_errno()){
echo 'Cannot connect to database: ' . mysqli_connect_error($conn);
}
if (!isset($_POST['submit'])) {
$query = "select * from submited left join person on person.person_id=submited.person_id where person.person_id= $_GET[id];";
$result = mysqli_query($conn,$query);
$row = mysqli_fetch_array($result) ;
}
?>
<script type="text/javascript">
function turnpage()
{
document.write("<h1>Record Updated</h1>");
alert("Record Was Modified");
window.location.replace("admint.php");
}
</script>
<?php
if(isset($_GET['id'])){
echo "<script>functioncall('{$_GET['id']}');</script>";
}
?>
<link rel="stylesheet" href="css/style.css?v=1">
<body>
<h1>Submit a link</h1>
<?php include "menu2.php";?><br>
<h1>Modifying Record</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" id="Form1" method="post" onSubmit="return validateForm();">
<p>First Name: <input type="text" name="fname" value="<?php if(isset($row['firstname'])) echo $row['firstname']; ?>" size="60"></p>
<p>Last Name: <input type="text" name="lname" value="<?php if(isset($row['lastname'])) echo $row['lastname']; ?>" size="60"></p>
<p>Email: <input type="text" name="email" value="<?php if(isset($row['email'])) echo $row['email']; ?>" size="60"></p>
<p>Telephone: <input id="phone" name="phone" type="text" placeholder="Eg. +447000 000000" value="<?php if(isset($row['telephone'])) echo $row['telephone']; ?>" required></p>
<p>Address: <input type="text" textarea name="address" type="text" value="<?php if(isset($row['address'])) echo $row['address']; ?>" cols="30" rows="10"></textarea></p>
<p>Select a State <select id="state" type="text" name="state" >
<option value="<?php if(isset($row['state'])) echo $row['state']; ?>"><?php if(isset($row['state'])) echo $row['state']; ?></option>
<option value="">Select State</option>
<option value="Alabama">Alabama</option>
<option value="Alaska">Alaska</option>
<option value="Arizona">Arizona</option>
<option value="Arkansas">Arkansas</option>
<option value="California">California</option>
<option value="Colorado">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
<option value="AS">American Samoa</option>
<option value="GU">Guam</option>
<option value="MP">Northern Mariana Islands</option>
<option value="PR">Puerto Rico</option>
<option value="UM">United States Minor Outlying Islands</option>
<option value="VI">Virgin Islands</option>
</select></p>
<p>Select a Country <select id="country" name="country" ">
<option value="<?php if(isset($row['country'])) echo $row['country']; ?>"><?php if(isset($row['country'])) echo $row['country']; ?></option>
<option value="Afganistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="American Samoa">American Samoa</option>
<option value="Andorra">Andorra</option>
<option value="Angola">Angola</option>
<option value="Anguilla">Anguilla</option>
<option value="Antigua & Barbuda">Antigua & Barbuda</option>
<option value="Argentina">Argentina</option>
<option value="Armenia">Armenia</option>
<option value="Aruba">Aruba</option>
<option value="Australia">Australia</option>
<option value="Austria">Austria</option>
<option value="Azerbaijan">Azerbaijan</option>
<option value="Bahamas">Bahamas</option>
<option value="Bahrain">Bahrain</option>
<option value="Bangladesh">Bangladesh</option>
<option value="Barbados">Barbados</option>
<option value="Belarus">Belarus</option>
<option value="Belgium">Belgium</option>
<option value="Belize">Belize</option>
<option value="Benin">Benin</option>
<option value="Bermuda">Bermuda</option>
<option value="Bhutan">Bhutan</option>
<option value="Bolivia">Bolivia</option>
<option value="Bonaire">Bonaire</option>
<option value="Bosnia & Herzegovina">Bosnia & Herzegovina</option>
<option value="Botswana">Botswana</option>
<option value="Brazil">Brazil</option>
<option value="British Indian Ocean Ter">British Indian Ocean Ter</option>
<option value="Brunei">Brunei</option>
<option value="Bulgaria">Bulgaria</option>
<option value="Burkina Faso">Burkina Faso</option>
<option value="Burundi">Burundi</option>
<option value="Cambodia">Cambodia</option>
<option value="Cameroon">Cameroon</option>
<option value="Canada">Canada</option>
<option value="Canary Islands">Canary Islands</option>
<option value="Cape Verde">Cape Verde</option>
<option value="Cayman Islands">Cayman Islands</option>
<option value="Central African Republic">Central African Republic</option>
<option value="Chad">Chad</option>
<option value="Channel Islands">Channel Islands</option>
<option value="Chile">Chile</option>
<option value="China">China</option>
<option value="Christmas Island">Christmas Island</option>
<option value="Cocos Island">Cocos Island</option>
<option value="Colombia">Colombia</option>
<option value="Comoros">Comoros</option>
<option value="Congo">Congo</option>
<option value="Cook Islands">Cook Islands</option>
<option value="Costa Rica">Costa Rica</option>
<option value="Cote DIvoire">Cote D'Ivoire</option>
<option value="Croatia">Croatia</option>
<option value="Cuba">Cuba</option>
<option value="Curaco">Curacao</option>
<option value="Cyprus">Cyprus</option>
<option value="Czech Republic">Czech Republic</option>
<option value="Denmark">Denmark</option>
<option value="Djibouti">Djibouti</option>
<option value="Dominica">Dominica</option>
<option value="Dominican Republic">Dominican Republic</option>
<option value="East Timor">East Timor</option>
<option value="Ecuador">Ecuador</option>
<option value="Egypt">Egypt</option>
<option value="El Salvador">El Salvador</option>
<option value="Equatorial Guinea">Equatorial Guinea</option>
<option value="Eritrea">Eritrea</option>
<option value="Estonia">Estonia</option>
<option value="Ethiopia">Ethiopia</option>
<option value="Falkland Islands">Falkland Islands</option>
<option value="Faroe Islands">Faroe Islands</option>
<option value="Fiji">Fiji</option>
<option value="Finland">Finland</option>
<option value="France">France</option>
<option value="French Guiana">French Guiana</option>
<option value="French Polynesia">French Polynesia</option>
<option value="French Southern Ter">French Southern Ter</option>
<option value="Gabon">Gabon</option>
<option value="Gambia">Gambia</option>
<option value="Georgia">Georgia</option>
<option value="Germany">Germany</option>
<option value="Ghana">Ghana</option>
<option value="Gibraltar">Gibraltar</option>
<option value="Great Britain">Great Britain</option>
<option value="Greece">Greece</option>
<option value="Greenland">Greenland</option>
<option value="Grenada">Grenada</option>
<option value="Guadeloupe">Guadeloupe</option>
<option value="Guam">Guam</option>
<option value="Guatemala">Guatemala</option>
<option value="Guinea">Guinea</option>
<option value="Guyana">Guyana</option>
<option value="Haiti">Haiti</option>
<option value="Hawaii">Hawaii</option>
<option value="Honduras">Honduras</option>
<option value="Hong Kong">Hong Kong</option>
<option value="Hungary">Hungary</option>
<option value="Iceland">Iceland</option>
<option value="India">India</option>
<option value="Indonesia">Indonesia</option>
<option value="Iran">Iran</option>
<option value="Iraq">Iraq</option>
<option value="Ireland">Ireland</option>
<option value="Isle of Man">Isle of Man</option>
<option value="Israel">Israel</option>
<option value="Italy">Italy</option>
<option value="Jamaica">Jamaica</option>
<option value="Japan">Japan</option>
<option value="Jordan">Jordan</option>
<option value="Kazakhstan">Kazakhstan</option>
<option value="Kenya">Kenya</option>
<option value="Kiribati">Kiribati</option>
<option value="Korea North">Korea North</option>
<option value="Korea Sout">Korea South</option>
<option value="Kuwait">Kuwait</option>
<option value="Kyrgyzstan">Kyrgyzstan</option>
<option value="Laos">Laos</option>
<option value="Latvia">Latvia</option>
<option value="Lebanon">Lebanon</option>
<option value="Lesotho">Lesotho</option>
<option value="Liberia">Liberia</option>
<option value="Libya">Libya</option>
<option value="Liechtenstein">Liechtenstein</option>
<option value="Lithuania">Lithuania</option>
<option value="Luxembourg">Luxembourg</option>
<option value="Macau">Macau</option>
<option value="Macedonia">Macedonia</option>
<option value="Madagascar">Madagascar</option>
<option value="Malaysia">Malaysia</option>
<option value="Malawi">Malawi</option>
<option value="Maldives">Maldives</option>
<option value="Mali">Mali</option>
<option value="Malta">Malta</option>
<option value="Marshall Islands">Marshall Islands</option>
<option value="Martinique">Martinique</option>
<option value="Mauritania">Mauritania</option>
<option value="Mauritius">Mauritius</option>
<option value="Mayotte">Mayotte</option>
<option value="Mexico">Mexico</option>
<option value="Midway Islands">Midway Islands</option>
<option value="Moldova">Moldova</option>
<option value="Monaco">Monaco</option>
<option value="Mongolia">Mongolia</option>
<option value="Montserrat">Montserrat</option>
<option value="Morocco">Morocco</option>
<option value="Mozambique">Mozambique</option>
<option value="Myanmar">Myanmar</option>
<option value="Nambia">Nambia</option>
<option value="Nauru">Nauru</option>
<option value="Nepal">Nepal</option>
<option value="Netherland Antilles">Netherland Antilles</option>
<option value="Netherlands">Netherlands (Holland, Europe)</option>
<option value="Nevis">Nevis</option>
<option value="New Caledonia">New Caledonia</option>
<option value="New Zealand">New Zealand</option>
<option value="Nicaragua">Nicaragua</option>
<option value="Niger">Niger</option>
<option value="Nigeria">Nigeria</option>
<option value="Niue">Niue</option>
<option value="Norfolk Island">Norfolk Island</option>
<option value="Norway">Norway</option>
<option value="Oman">Oman</option>
<option value="Pakistan">Pakistan</option>
<option value="Palau Island">Palau Island</option>
<option value="Palestine">Palestine</option>
<option value="Panama">Panama</option>
<option value="Papua New Guinea">Papua New Guinea</option>
<option value="Paraguay">Paraguay</option>
<option value="Peru">Peru</option>
<option value="Phillipines">Philippines</option>
<option value="Pitcairn Island">Pitcairn Island</option>
<option value="Poland">Poland</option>
<option value="Portugal">Portugal</option>
<option value="Puerto Rico">Puerto Rico</option>
<option value="Qatar">Qatar</option>
<option value="Republic of Montenegro">Republic of Montenegro</option>
<option value="Republic of Serbia">Republic of Serbia</option>
<option value="Reunion">Reunion</option>
<option value="Romania">Romania</option>
<option value="Russia">Russia</option>
<option value="Rwanda">Rwanda</option>
<option value="St Barthelemy">St Barthelemy</option>
<option value="St Eustatius">St Eustatius</option>
<option value="St Helena">St Helena</option>
<option value="St Kitts-Nevis">St Kitts-Nevis</option>
<option value="St Lucia">St Lucia</option>
<option value="St Maarten">St Maarten</option>
<option value="St Pierre & Miquelon">St Pierre & Miquelon</option>
<option value="St Vincent & Grenadines">St Vincent & Grenadines</option>
<option value="Saipan">Saipan</option>
<option value="Samoa">Samoa</option>
<option value="Samoa American">Samoa American</option>
<option value="San Marino">San Marino</option>
<option value="Sao Tome & Principe">Sao Tome & Principe</option>
<option value="Saudi Arabia">Saudi Arabia</option>
<option value="Senegal">Senegal</option>
<option value="Serbia">Serbia</option>
<option value="Seychelles">Seychelles</option>
<option value="Sierra Leone">Sierra Leone</option>
<option value="Singapore">Singapore</option>
<option value="Slovakia">Slovakia</option>
<option value="Slovenia">Slovenia</option>
<option value="Solomon Islands">Solomon Islands</option>
<option value="Somalia">Somalia</option>
<option value="South Africa">South Africa</option>
<option value="Spain">Spain</option>
<option value="Sri Lanka">Sri Lanka</option>
<option value="Sudan">Sudan</option>
<option value="Suriname">Suriname</option>
<option value="Swaziland">Swaziland</option>
<option value="Sweden">Sweden</option>
<option value="Switzerland">Switzerland</option>
<option value="Syria">Syria</option>
<option value="Tahiti">Tahiti</option>
<option value="Taiwan">Taiwan</option>
<option value="Tajikistan">Tajikistan</option>
<option value="Tanzania">Tanzania</option>
<option value="Thailand">Thailand</option>
<option value="Togo">Togo</option>
<option value="Tokelau">Tokelau</option>
<option value="Tonga">Tonga</option>
<option value="Trinidad & Tobago">Trinidad & Tobago</option>
<option value="Tunisia">Tunisia</option>
<option value="Turkey">Turkey</option>
<option value="Turkmenistan">Turkmenistan</option>
<option value="Turks & Caicos Is">Turks & Caicos Is</option>
<option value="Tuvalu">Tuvalu</option>
<option value="Uganda">Uganda</option>
<option value="Ukraine">Ukraine</option>
<option value="United Arab Erimates">United Arab Emirates</option>
<option value="United Kingdom">United Kingdom</option>
<option value="United States of America">United States of America</option>
<option value="Uraguay">Uruguay</option>
<option value="Uzbekistan">Uzbekistan</option>
<option value="Vanuatu">Vanuatu</option>
<option value="Vatican City State">Vatican City State</option>
<option value="Venezuela">Venezuela</option>
<option value="Vietnam">Vietnam</option>
<option value="Virgin Islands (Brit)">Virgin Islands (Brit)</option>
<option value="Virgin Islands (USA)">Virgin Islands (USA)</option>
<option value="Wake Island">Wake Island</option>
<option value="Wallis & Futana Is">Wallis & Futana Is</option>
<option value="Yemen">Yemen</option>
<option value="Zaire">Zaire</option>
<option value="Zambia">Zambia</option>
<option value="Zimbabwe">Zimbabwe</option>
</select>
<p>Gender <p><input type="radio" name="gender" value="Male"<?php if ($row['sex'] == 'Male') echo 'checked="checked"'; ?>checked="checked"> Male</p>
<p><input type="radio" name="gender" value="Female"<?php if ($row['sex'] == 'Female') echo 'checked="checked"'; ?>> Female</p>
<p>Link Address: <input type="text" name="link" size="60" value="<?php if(isset($row['link'])) echo $row['link']; ?>"></p>
<p>Description of the link: <textarea name="description" cols="50" rows="20" value=<?php if(isset($row['description'])) echo $row['description']; ?>></textarea></p>
<p>Link Category 1 <select id="type1" name="type1" value="" >
<option value="<?php if(isset($row['type1'])) echo $row['type1']; ?>"><?php if(isset($row['type1'])) echo $row['type1']; ?></option>
<option value="Video">Video</option>
<option value="Article">Article</option>
<option value="Newspaper">Newspaper</option>
<option value="Magazine">Magazine</option>
<option value="Social Media">Social Media</option>
<option value="Book">Book</option>
<option value="Other">Other</option>
</select></p>
<p>Link Category 2 <select id="type2" name="type2" value="">
<option value="<?php if(isset($row['type2'])) echo $row['type2']; ?>"><?php if(isset($row['type2'])) echo $row['type2']; ?></option>
<option value="Science">Science</option>
<option value="Health">Health</option>
<option value="Technology">Technology</option>
<option value="Comedy">Comedy</option>
<option value="National News">National News</option>
<option value="Home">Home</option>
<option value="Education">Education</option>
</select></p>
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" />
<p><input type="submit" name="submit" value="Modify"> </p>
</form>
<?php
if(isset($_POST['submit'])) {
$selected_radio = $_POST['gender'];
if ($selected_radio == 'Male') {
$sex='Male';
}
else if ($selected_radio == 'Female') {
$sex='Female';
}
$update="UPDATE person p join submited s ON (p.person_id=s.person_id) set update person set firstname='$_POST[fname]', lastname='$_POST[lname]',email='$_POST[email]',
telephone='$_POST[phone]',address='$_POST[address]',state='$_POST[state]',country='$_POST[country]',sex='$sex','$_POST[description]', type1='$_POST[type1]',
type2='$_POST[type2]', link='$_POST[link]' where person_id=$_POST[id]";
mysqli_query($conn,$update) or die(mysql_error());
mysqli_close($conn);
echo "<SCRIPT LANGUAGE='javascript'>turnpage();</SCRIPT>";
//$update1 ="update person set firstname='$_POST[fname]', lastname='$_POST[lname]',email='$_POST[email]',
//telephone='$_POST[phone]',address='$_POST[address]',state='$_POST[state]',
//country='$_POST[country]',sex='$sex'where person_id=$_POST[id]";
//$update2 ="update description='$_POST[description]', type1='$_POST[type1]', type2='$_POST[type2]', link='$_POST[link]' where person_id=$_POST[id]";
//mysqli_query($conn,$update2) or die(mysql_error());
}
?>
The UPDATE statements has some problems. Remove update person set. The value $_POST[description] does not have its respective column. The variables in $_POST should be quoted. Make sure the fields are p (person) or s (submited).
$update="UPDATE person p JOIN submited s
ON (p.person_id=s.person_id)
SET p.firstname='".$_POST['fname']."',
p.lastname='".$_POST['lname']."',
p.email='".$_POST['email']."',
p.telephone='".$_POST['phone']."',
p.address='".$_POST['address']."',
p.state='".$_POST['state']."',
p.country='".$_POST['country']."',
p.sex='$sex',
p.description='".$_POST['description']."',
p.type1='".$_POST['type1']."',
p.type2='".$_POST['type2']."',
p.link='".$_POST['link']."'
WHERE p.person_id=$_POST['id']";

Mysql PHP edit form errors

I have an error in my form and I am not sure how to fix it. I receive a Notice Line 353 and 354 Undefined Variable after clicking the button to modify the record. I also see that all of the input boxes have:
Notice: Undefined variable: row in C:\xampp\htdocs\group\modify.php on line 35
Not sure how to fix any help is appreciated. code to the form below:
<?php
//require "admin_login.php";
//include "admin_connect.php"
$conn = mysqli_connect("localhost", "admin",
"admin9090", "linkyoutube");
mysql_select_db("linkyoutube");
if (mysqli_connect_errno()){
echo 'Cannot connect to database: ' .
mysqli_connect_error($conn);
}
if (!isset($_POST['submit'])) {
$query = "select * from submited left join person on person.person_id=submited.person_id where person.person_id= $_GET[id];";
$result = mysqli_query($conn,$query);
$row = mysqli_fetch_array($result) ;
}
?>
<!doctype html>
<head>
<meta charset="utf-8">
<title>LAB 1 6203</title>
<meta name="description" content="6203 Lab 1 ">
<link rel="stylesheet" href="css/style.css?v=1">
</head>
<body>
<h1>Submit a link</h1>
<?php include "menu2.php";?><br>
<h1>Modifying Record</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" id="Form1" method="post" onSubmit="return validateForm();">
<p>First Name: <input type="text" name="fname" value="<?php echo $row['firstname']; ?>" size="60"></p>
<p>Last Name: <input type="text" name="lname" value="<?php echo $row['lastname']; ?>" size="60"></p>
<p>Email: <input type="text" name="email" value="<?php echo $row['email']; ?>" size="60"></p>
<p>Telephone: <input id="phone" name="phone" type="text" placeholder="Eg. +447000 000000" value="<?php echo $row['telephone']; ?>" required></p>
<p>Address: <input type="text" textarea name="address" type="text" value="<?php echo $row['address']; ?>" cols="30" rows="10"></textarea></p>
<p>Select a State <select id="state" type="text" name="state" >
<option value="<?php echo $row['state']; ?>" ><?php echo $row['state']; ?></option>
<option value="">Select State</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
<option value="AS">American Samoa</option>
<option value="GU">Guam</option>
<option value="MP">Northern Mariana Islands</option>
<option value="PR">Puerto Rico</option>
<option value="UM">United States Minor Outlying Islands</option>
<option value="VI">Virgin Islands</option>
</select></p>
<p>Select a Country <select id="country" name="country" ">
<option value="<?php echo $row['country']; ?>"><?php echo $row['country']; ?></option>
<option value="Afganistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="American Samoa">American Samoa</option>
<option value="Andorra">Andorra</option>
<option value="Angola">Angola</option>
<option value="Anguilla">Anguilla</option>
<option value="Antigua & Barbuda">Antigua & Barbuda</option>
<option value="Argentina">Argentina</option>
<option value="Armenia">Armenia</option>
<option value="Aruba">Aruba</option>
<option value="Australia">Australia</option>
<option value="Austria">Austria</option>
<option value="Azerbaijan">Azerbaijan</option>
<option value="Bahamas">Bahamas</option>
<option value="Bahrain">Bahrain</option>
<option value="Bangladesh">Bangladesh</option>
<option value="Barbados">Barbados</option>
<option value="Belarus">Belarus</option>
<option value="Belgium">Belgium</option>
<option value="Belize">Belize</option>
<option value="Benin">Benin</option>
<option value="Bermuda">Bermuda</option>
<option value="Bhutan">Bhutan</option>
<option value="Bolivia">Bolivia</option>
<option value="Bonaire">Bonaire</option>
<option value="Bosnia & Herzegovina">Bosnia & Herzegovina</option>
<option value="Botswana">Botswana</option>
<option value="Brazil">Brazil</option>
<option value="British Indian Ocean Ter">British Indian Ocean Ter</option>
<option value="Brunei">Brunei</option>
<option value="Bulgaria">Bulgaria</option>
<option value="Burkina Faso">Burkina Faso</option>
<option value="Burundi">Burundi</option>
<option value="Cambodia">Cambodia</option>
<option value="Cameroon">Cameroon</option>
<option value="Canada">Canada</option>
<option value="Canary Islands">Canary Islands</option>
<option value="Cape Verde">Cape Verde</option>
<option value="Cayman Islands">Cayman Islands</option>
<option value="Central African Republic">Central African Republic</option>
<option value="Chad">Chad</option>
<option value="Channel Islands">Channel Islands</option>
<option value="Chile">Chile</option>
<option value="China">China</option>
<option value="Christmas Island">Christmas Island</option>
<option value="Cocos Island">Cocos Island</option>
<option value="Colombia">Colombia</option>
<option value="Comoros">Comoros</option>
<option value="Congo">Congo</option>
<option value="Cook Islands">Cook Islands</option>
<option value="Costa Rica">Costa Rica</option>
<option value="Cote DIvoire">Cote D'Ivoire</option>
<option value="Croatia">Croatia</option>
<option value="Cuba">Cuba</option>
<option value="Curaco">Curacao</option>
<option value="Cyprus">Cyprus</option>
<option value="Czech Republic">Czech Republic</option>
<option value="Denmark">Denmark</option>
<option value="Djibouti">Djibouti</option>
<option value="Dominica">Dominica</option>
<option value="Dominican Republic">Dominican Republic</option>
<option value="East Timor">East Timor</option>
<option value="Ecuador">Ecuador</option>
<option value="Egypt">Egypt</option>
<option value="El Salvador">El Salvador</option>
<option value="Equatorial Guinea">Equatorial Guinea</option>
<option value="Eritrea">Eritrea</option>
<option value="Estonia">Estonia</option>
<option value="Ethiopia">Ethiopia</option>
<option value="Falkland Islands">Falkland Islands</option>
<option value="Faroe Islands">Faroe Islands</option>
<option value="Fiji">Fiji</option>
<option value="Finland">Finland</option>
<option value="France">France</option>
<option value="French Guiana">French Guiana</option>
<option value="French Polynesia">French Polynesia</option>
<option value="French Southern Ter">French Southern Ter</option>
<option value="Gabon">Gabon</option>
<option value="Gambia">Gambia</option>
<option value="Georgia">Georgia</option>
<option value="Germany">Germany</option>
<option value="Ghana">Ghana</option>
<option value="Gibraltar">Gibraltar</option>
<option value="Great Britain">Great Britain</option>
<option value="Greece">Greece</option>
<option value="Greenland">Greenland</option>
<option value="Grenada">Grenada</option>
<option value="Guadeloupe">Guadeloupe</option>
<option value="Guam">Guam</option>
<option value="Guatemala">Guatemala</option>
<option value="Guinea">Guinea</option>
<option value="Guyana">Guyana</option>
<option value="Haiti">Haiti</option>
<option value="Hawaii">Hawaii</option>
<option value="Honduras">Honduras</option>
<option value="Hong Kong">Hong Kong</option>
<option value="Hungary">Hungary</option>
<option value="Iceland">Iceland</option>
<option value="India">India</option>
<option value="Indonesia">Indonesia</option>
<option value="Iran">Iran</option>
<option value="Iraq">Iraq</option>
<option value="Ireland">Ireland</option>
<option value="Isle of Man">Isle of Man</option>
<option value="Israel">Israel</option>
<option value="Italy">Italy</option>
<option value="Jamaica">Jamaica</option>
<option value="Japan">Japan</option>
<option value="Jordan">Jordan</option>
<option value="Kazakhstan">Kazakhstan</option>
<option value="Kenya">Kenya</option>
<option value="Kiribati">Kiribati</option>
<option value="Korea North">Korea North</option>
<option value="Korea Sout">Korea South</option>
<option value="Kuwait">Kuwait</option>
<option value="Kyrgyzstan">Kyrgyzstan</option>
<option value="Laos">Laos</option>
<option value="Latvia">Latvia</option>
<option value="Lebanon">Lebanon</option>
<option value="Lesotho">Lesotho</option>
<option value="Liberia">Liberia</option>
<option value="Libya">Libya</option>
<option value="Liechtenstein">Liechtenstein</option>
<option value="Lithuania">Lithuania</option>
<option value="Luxembourg">Luxembourg</option>
<option value="Macau">Macau</option>
<option value="Macedonia">Macedonia</option>
<option value="Madagascar">Madagascar</option>
<option value="Malaysia">Malaysia</option>
<option value="Malawi">Malawi</option>
<option value="Maldives">Maldives</option>
<option value="Mali">Mali</option>
<option value="Malta">Malta</option>
<option value="Marshall Islands">Marshall Islands</option>
<option value="Martinique">Martinique</option>
<option value="Mauritania">Mauritania</option>
<option value="Mauritius">Mauritius</option>
<option value="Mayotte">Mayotte</option>
<option value="Mexico">Mexico</option>
<option value="Midway Islands">Midway Islands</option>
<option value="Moldova">Moldova</option>
<option value="Monaco">Monaco</option>
<option value="Mongolia">Mongolia</option>
<option value="Montserrat">Montserrat</option>
<option value="Morocco">Morocco</option>
<option value="Mozambique">Mozambique</option>
<option value="Myanmar">Myanmar</option>
<option value="Nambia">Nambia</option>
<option value="Nauru">Nauru</option>
<option value="Nepal">Nepal</option>
<option value="Netherland Antilles">Netherland Antilles</option>
<option value="Netherlands">Netherlands (Holland, Europe)</option>
<option value="Nevis">Nevis</option>
<option value="New Caledonia">New Caledonia</option>
<option value="New Zealand">New Zealand</option>
<option value="Nicaragua">Nicaragua</option>
<option value="Niger">Niger</option>
<option value="Nigeria">Nigeria</option>
<option value="Niue">Niue</option>
<option value="Norfolk Island">Norfolk Island</option>
<option value="Norway">Norway</option>
<option value="Oman">Oman</option>
<option value="Pakistan">Pakistan</option>
<option value="Palau Island">Palau Island</option>
<option value="Palestine">Palestine</option>
<option value="Panama">Panama</option>
<option value="Papua New Guinea">Papua New Guinea</option>
<option value="Paraguay">Paraguay</option>
<option value="Peru">Peru</option>
<option value="Phillipines">Philippines</option>
<option value="Pitcairn Island">Pitcairn Island</option>
<option value="Poland">Poland</option>
<option value="Portugal">Portugal</option>
<option value="Puerto Rico">Puerto Rico</option>
<option value="Qatar">Qatar</option>
<option value="Republic of Montenegro">Republic of Montenegro</option>
<option value="Republic of Serbia">Republic of Serbia</option>
<option value="Reunion">Reunion</option>
<option value="Romania">Romania</option>
<option value="Russia">Russia</option>
<option value="Rwanda">Rwanda</option>
<option value="St Barthelemy">St Barthelemy</option>
<option value="St Eustatius">St Eustatius</option>
<option value="St Helena">St Helena</option>
<option value="St Kitts-Nevis">St Kitts-Nevis</option>
<option value="St Lucia">St Lucia</option>
<option value="St Maarten">St Maarten</option>
<option value="St Pierre & Miquelon">St Pierre & Miquelon</option>
<option value="St Vincent & Grenadines">St Vincent & Grenadines</option>
<option value="Saipan">Saipan</option>
<option value="Samoa">Samoa</option>
<option value="Samoa American">Samoa American</option>
<option value="San Marino">San Marino</option>
<option value="Sao Tome & Principe">Sao Tome & Principe</option>
<option value="Saudi Arabia">Saudi Arabia</option>
<option value="Senegal">Senegal</option>
<option value="Serbia">Serbia</option>
<option value="Seychelles">Seychelles</option>
<option value="Sierra Leone">Sierra Leone</option>
<option value="Singapore">Singapore</option>
<option value="Slovakia">Slovakia</option>
<option value="Slovenia">Slovenia</option>
<option value="Solomon Islands">Solomon Islands</option>
<option value="Somalia">Somalia</option>
<option value="South Africa">South Africa</option>
<option value="Spain">Spain</option>
<option value="Sri Lanka">Sri Lanka</option>
<option value="Sudan">Sudan</option>
<option value="Suriname">Suriname</option>
<option value="Swaziland">Swaziland</option>
<option value="Sweden">Sweden</option>
<option value="Switzerland">Switzerland</option>
<option value="Syria">Syria</option>
<option value="Tahiti">Tahiti</option>
<option value="Taiwan">Taiwan</option>
<option value="Tajikistan">Tajikistan</option>
<option value="Tanzania">Tanzania</option>
<option value="Thailand">Thailand</option>
<option value="Togo">Togo</option>
<option value="Tokelau">Tokelau</option>
<option value="Tonga">Tonga</option>
<option value="Trinidad & Tobago">Trinidad & Tobago</option>
<option value="Tunisia">Tunisia</option>
<option value="Turkey">Turkey</option>
<option value="Turkmenistan">Turkmenistan</option>
<option value="Turks & Caicos Is">Turks & Caicos Is</option>
<option value="Tuvalu">Tuvalu</option>
<option value="Uganda">Uganda</option>
<option value="Ukraine">Ukraine</option>
<option value="United Arab Erimates">United Arab Emirates</option>
<option value="United Kingdom">United Kingdom</option>
<option value="United States of America">United States of America</option>
<option value="Uraguay">Uruguay</option>
<option value="Uzbekistan">Uzbekistan</option>
<option value="Vanuatu">Vanuatu</option>
<option value="Vatican City State">Vatican City State</option>
<option value="Venezuela">Venezuela</option>
<option value="Vietnam">Vietnam</option>
<option value="Virgin Islands (Brit)">Virgin Islands (Brit)</option>
<option value="Virgin Islands (USA)">Virgin Islands (USA)</option>
<option value="Wake Island">Wake Island</option>
<option value="Wallis & Futana Is">Wallis & Futana Is</option>
<option value="Yemen">Yemen</option>
<option value="Zaire">Zaire</option>
<option value="Zambia">Zambia</option>
<option value="Zimbabwe">Zimbabwe</option>
</select>
<p>Gender <p><input type="radio" name="gender" value="Male" <?php if ($row['sex'] == 'Male') echo 'checked="checked"'; ?>> Male</p>
<p><input type="radio" name="gender" value="Female" <?php if ($row['sex'] == 'Female') echo 'checked="checked"'; ?>> Female</p>
<p>Link Address: <input type="text" name="link" size="60" value="<?php echo $row['link']; ?>"></p>
<p>Description of the link: <textarea name="description" cols="50" rows="20" value="<?php echo $row['description']; ?>"><?php echo $row['description']; ?></textarea></p>
<p>Link Category 1 <select id="type1" name="type1" value="" >
<option value="<?php echo $row['type1']; ?>"><?php echo $row['type1']; ?></option>
<option value="Video">Video</option>
<option value="Article">Article</option>
<option value="Newspaper">Newspaper</option>
<option value="Magazine">Magazine</option>
<option value="Social Media">Social Media</option>
<option value="Book">Book</option>
<option value="Other">Other</option>
</select></p>
<p>Link Category 2 <select id="type2" name="type2" value="">
<option value="<?php echo $row['type2']; ?>"><?php echo $row['type2']; ?></option>
<option value="Science">Science</option>
<option value="Health">Health</option>
<option value="Technology">Technology</option>
<option value="Comedy">Comedy</option>
<option value="National News">National News</option>
<option value="Home">Home</option>
<option value="Education">Education</option>
</select></p>
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" />
<p><input type="submit" name="submit" value="Modify"> </p>
</form>
<?php
if(isset($_POST['submit'])) {
$update1 ="update person set firstname='$_POST[fname]', lastname='$_POST[lname]',email='$_POST[email]',
telephone='$_POST[phone]',address='$_POST[address]',state='$_POST[state]',
country='$_POST[country]',sex='$_POST[gender]'where person_id=$_POST[id]";
mysqli_query($conn,$update1) or die(mysql_error());
echo "User had been modified!";
//header("Location: admint.php");
}
?>
You are trying to access $row which are not set after form submission ie, $row is available only before you have submitted the form . Access the $row only if it is set. Try with this
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" id="Form1" method="post" onSubmit="return validateForm();">
<p>First Name: <input type="text" name="fname" value="<?php if(isset($row['firstname'])) echo $row['firstname']; ?>" size="60"></p>
<p>Last Name: <input type="text" name="lname" value="<?php if(isset($row['lastname'])) echo $row['lastname']; ?>" size="60"></p>
<p>Email: <input type="text" name="email" value="<?php if(isset($row['email'])) echo $row['email']; ?>" size="60"></p>
<p>Telephone: <input id="phone" name="phone" type="text" placeholder="Eg. +447000 000000" value="<?php if(isset($row['telephone'])) echo $row['telephone']; ?>" required></p>
<p>Address: <input type="text" textarea name="address" type="text" value="<?php if(isset($row['address'])) echo $row['address']; ?>" cols="30" rows="10"></textarea></p>

FILE_APPEND not working properly with file_put_contents

I'm passing form data as JSON via AJAX to a PHP file which then saves the JSON in a text file on the server.
The problem is that when I use FILE_APPEND the data is not written on the file when the JSON data already exists in the text file.
My HTML code is:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="eloqua.css">
<script src="http://code.jquery.com/jquery-1.9.0.js"></script>
<script type="text/javascript">
$(document).ready(function(){
localStorage.clear();
$("form").on("submit", function() {
if(window.localStorage!==undefined) {
var fields = $(this).serialize();
localStorage.setItem("eloqua-fields", JSON.stringify( fields ));
alert("Stored Succesfully");
$(this).find("input[type=text]").val("");
alert("Now Passing stored data to Server through AJAX jQuery");
$.ajax({
type: "POST",
url: "backend.php",
data: fields
});
} else {
alert("Storage Failed. Try refreshing");
}
});
});
</script>
<script type="text/javascript">
function validateForm()
{
var a=document.forms["EloquaForm"]["C_FirstName"].value;
if (a==null || a=="")
{
alert("First name must be filled out");
return false;
}
var b=document.forms["EloquaForm"]["C_LastName"].value;
if (b==null || b=="")
{
alert("Last name must be filled out");
return false;
}
var y=document.forms["EloquaForm"]["C_EmailAddress"].value;
var atpos=y.indexOf("#");
var dotpos=y.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=y.length)
{
alert("Not a valid e-mail address");
return false;
}
}
</script>
</head>
<body>
<p><img src="red-asterix.jpeg"> indicates a required field</p>
<div class="form-container" style="width: 625px">
<form class="form-eloqua" name="EloquaForm" action="http://s33.t.eloqua.com/e/f2" onsubmit="return validateForm();" method="post">
<span class="form-eloqua-label"><span>First Name</span></span><input id="firstname" type="text" name="C_FirstName" />
<span class="form-eloqua-label"><span>Last Name</span></span><input id="lastname" type="text" name="C_LastName" />
<span class="form-eloqua-label"><span>Email Address</span></span><input id="email" type="text" name="C_EmailAddress" />
<span class="form-eloqua-label">Title</span><input id="title" type="text" name="C_Title" />
<span class="form-eloqua-label">Company</span><input id="company" type="text" name="C_Company" />
<span class="form-eloqua-label">ZIP or Postal Code</span><input id="postcode" type="text" name="zipOrPostalCode" />
<span class="form-eloqua-label">Country</span><select id="country" name="country">
<option value="">Please select ...</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="AG">Angola</option>
<option value="AI">Anguilla</option>
<option value="AG">Antigua & Barbuda</option>
<option value="AR">Argentina</option>
<option value="AA">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="BL">Bonaire</option>
<option value="BA">Bosnia & Herzegovina</option>
<option value="BW">Botswana</option>
<option value="BR">Brazil</option>
<option value="BC">British Indian Ocean Ter</option>
<option value="BN">Brunei</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="IC">Canary Islands</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="CD">Channel Islands</option>
<option value="CL">Chile</option>
<option value="CN">China</option>
<option value="CI">Christmas Island</option>
<option value="CS">Cocos Island</option>
<option value="CO">Colombia</option>
<option value="CC">Comoros</option>
<option value="CG">Congo</option>
<option value="CK">Cook Islands</option>
<option value="CR">Costa Rica</option>
<option value="CT">Cote D'Ivoire</option>
<option value="HR">Croatia</option>
<option value="CU">Cuba</option>
<option value="CB">Curacao</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="TM">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="FA">Falkland Islands</option>
<option value="FO">Faroe Islands</option>
<option value="FJ">Fiji</option>
<option value="FI">Finland</option>
<option value="FR">France</option>
<option value="GF">French Guiana</option>
<option value="PF">French Polynesia</option>
<option value="FS">French Southern Ter</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="GB">Great Britain</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="GY">Guyana</option>
<option value="HT">Haiti</option>
<option value="HW">Hawaii</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="IA">Iran</option>
<option value="IQ">Iraq</option>
<option value="IR">Ireland</option>
<option value="IM">Isle of Man</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="NK">Korea North</option>
<option value="KS">Korea South</option>
<option value="KW">Kuwait</option>
<option value="KG">Kyrgyzstan</option>
<option value="LA">Laos</option>
<option value="LV">Latvia</option>
<option value="LB">Lebanon</option>
<option value="LS">Lesotho</option>
<option value="LR">Liberia</option>
<option value="LY">Libya</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</option>
<option value="MG">Madagascar</option>
<option value="MY">Malaysia</option>
<option value="MW">Malawi</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="ME">Mayotte</option>
<option value="MX">Mexico</option>
<option value="MI">Midway Islands</option>
<option value="MD">Moldova</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">Nambia</option>
<option value="NU">Nauru</option>
<option value="NP">Nepal</option>
<option value="AN">Netherland Antilles</option>
<option value="NL">Netherlands (Holland, Europe)</option>
<option value="NV">Nevis</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="NW">Niue</option>
<option value="NF">Norfolk Island</option>
<option value="NO">Norway</option>
<option value="OM">Oman</option>
<option value="PK">Pakistan</option>
<option value="PW">Palau Island</option>
<option value="PS">Palestine</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="PO">Pitcairn Island</option>
<option value="PL">Poland</option>
<option value="PT">Portugal</option>
<option value="PR">Puerto Rico</option>
<option value="QA">Qatar</option>
<option value="ME">Republic of Montenegro</option>
<option value="RS">Republic of Serbia</option>
<option value="RE">Reunion</option>
<option value="RO">Romania</option>
<option value="RU">Russia</option>
<option value="RW">Rwanda</option>
<option value="NT">St Barthelemy</option>
<option value="EU">St Eustatius</option>
<option value="HE">St Helena</option>
<option value="KN">St Kitts-Nevis</option>
<option value="LC">St Lucia</option>
<option value="MB">St Maarten</option>
<option value="PM">St Pierre & Miquelon</option>
<option value="VC">St Vincent & Grenadines</option>
<option value="SP">Saipan</option>
<option value="SO">Samoa</option>
<option value="AS">Samoa American</option>
<option value="SM">San Marino</option>
<option value="ST">Sao Tome & Principe</option>
<option value="SA">Saudi Arabia</option>
<option value="SN">Senegal</option>
<option value="RS">Serbia</option>
<option value="SC">Seychelles</option>
<option value="SL">Sierra Leone</option>
<option value="SG">Singapore</option>
<option value="SK">Slovakia</option>
<option value="SI">Slovenia</option>
<option value="SB">Solomon Islands</option>
<option value="OI">Somalia</option>
<option value="ZA">South Africa</option>
<option value="ES">Spain</option>
<option value="LK">Sri Lanka</option>
<option value="SD">Sudan</option>
<option value="SR">Suriname</option>
<option value="SZ">Swaziland</option>
<option value="SE">Sweden</option>
<option value="CH">Switzerland</option>
<option value="SY">Syria</option>
<option value="TA">Tahiti</option>
<option value="TW">Taiwan</option>
<option value="TJ">Tajikistan</option>
<option value="TZ">Tanzania</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 & Tobago</option>
<option value="TN">Tunisia</option>
<option value="TR">Turkey</option>
<option value="TU">Turkmenistan</option>
<option value="TC">Turks & Caicos Is</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 of America</option>
<option value="UY">Uruguay</option>
<option value="UZ">Uzbekistan</option>
<option value="VU">Vanuatu</option>
<option value="VS">Vatican City State</option>
<option value="VE">Venezuela</option>
<option value="VN">Vietnam</option>
<option value="VB">Virgin Islands (Brit)</option>
<option value="VA">Virgin Islands (USA)</option>
<option value="WK">Wake Island</option>
<option value="WF">Wallis & Futana Is</option>
<option value="YE">Yemen</option>
<option value="ZR">Zaire</option>
<option value="ZM">Zambia</option>
<option value="ZW">Zimbabwe</option>
</select>
<div class="form-eloqua-separator"></div>
<span class="form-eloqua-label">Annual Revenue Range</span><select name="C_Annual_Revenue1"> <option value="">Please select ...</option> <option value="0-100,000,000">0-100,000,000</option><option value="100,000,001-300,000,000">100,000,001-300,000,000</option><option value="300,000,001-500,000,000">300,000,001-500,000,000</option><option value="500,000,001-2,000,000,000">500,000,001-2,000,000,000</option><option value="2 Billion +">2 Billion +</option></select>
<div class="submit-button"><input type="submit" id="submit" value="Submit" /></div>
<div id="output"></div>
<input type="hidden" name="elqoffer" value="GGB2BContentMktg" />
<input type="hidden" name="elqchannel" value="TheMarketer" />
<input type="hidden" name="elqbq" value="14Q2" />
<input type="hidden" name="elqbc" value="UK" />
<input type="hidden" name="elqFormName" value="2013-Syndication-1372365875136" />
<input type="hidden" name="elqSiteId" value="33" />
</form>
</div>
</body>
</html>
and my PHP code is:
<?php
date_default_timezone_set('America/Chicago'); // CDT
echo '<h2>Server Timezone : ' . date_default_timezone_get() . '</h2>';
$current_date = date('d/m/Y == H:i:s ');
print "<h2>Server Time : " . $current_date . "</h2>";
$dataObject = $_POST; //Fetching all posts
echo "<pre>"; //making the dump look nice in html.
var_dump($dataObject);
echo "</pre>";
//Writes it as json to the file, you can transform it any way you want
$json = json_encode($dataObject);
file_put_contents('your_data.txt', $json . PHP_EOL, FILE_APPEND);
?>
If I understood ( after seeing hackingarticles.com/marketer/your_data.txt).Your code look as working. Try change to:
$file_content = array();
if ( file_exists('your_data.txt')){
$file_content = (array)json_decode(file_get_contents('your_data.txt'));
unlink('your_data.txt');
}
$file_content['users'][] = array('user'=>$_POST);
file_put_contents('your_data.txt',json_encode($file_content));

drop down list to change value on select

drop down value not appearing for second list , tried everything .When user selects country , state should get populated from DB into 2nd drop down, please help. Code:
Javascript part used to get selected value from 1st drop down and set 2nd drop down
<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
document.getElementById("statename").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("statename").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getstate.php?q="+str,true);
xmlhttp.send();
}
</script>
Html part :
Select Country
<option value="" >Select One</option>
<option value="Afghanistan" >Afghanistan</option>
<option value="Aland Islands" >Aland Islands</option>
<option value="Albania" >Albania</option>
<option value="Algeria" >Algeria</option>
<option value="American Samoa" >American Samoa</option>
<option value="Andorra" >Andorra</option>
<option value="Angola" >Angola</option>
<option value="Anguilla" >Anguilla</option>
<option value="Antarctica" >Antarctica</option>
<option value="Antigua and Barbuda" >Antigua and Barbuda</option>
<option value="Argentina" >Argentina</option>
<option value="Armenia" >Armenia</option>
<option value="Aruba" >Aruba</option>
<option value="Australia" >Australia</option>
<option value="Austria" >Austria</option>
<option value="Azerbaijan" >Azerbaijan</option>
<option value="Bahamas" >Bahamas</option>
<option value="Bahrain" >Bahrain</option>
<option value="Bangladesh" >Bangladesh</option>
<option value="Barbados" >Barbados</option>
<option value="Belarus" >Belarus</option>
<option value="Belgium" >Belgium</option>
<option value="Belize" >Belize</option>
<option value="Benin" >Benin</option>
<option value="Bermuda" >Bermuda</option>
<option value="Bhutan" >Bhutan</option>
<option value="Bolivia" >Bolivia</option>
<option value="Bosnia and Herzegovina" >Bosnia and Herzegovina</option>
<option value="Botswana" >Botswana</option>
<option value="Bouvet Island" >Bouvet Island</option>
<option value="Brazil" >Brazil</option>
<option value="British Indian Ocean Territory" >British Indian Ocean Territory</option>
<option value="British Virgin Islands" >British Virgin Islands</option>
<option value="Brunei" >Brunei</option>
<option value="Bulgaria" >Bulgaria</option>
<option value="Burkina Faso" >Burkina Faso</option>
<option value="Burundi" >Burundi</option>
<option value="Cambodia" >Cambodia</option>
<option value="Cameroon" >Cameroon</option>
<option value="Canada" >Canada</option>
<option value="Cape Verde" >Cape Verde</option>
<option value="Cayman Islands" >Cayman Islands</option>
<option value="Central African Republic" >Central African Republic</option>
<option value="Chad" >Chad</option>
<option value="Chile" >Chile</option>
<option value="China" >China</option>
<option value="Christmas Island" >Christmas Island</option>
<option value="Cocos (Keeling) Islands" >Cocos (Keeling) Islands</option>
<option value="Colombia" >Colombia</option>
<option value="Comoros" >Comoros</option>
<option value="Congo" >Congo</option>
<option value="Cook Islands" >Cook Islands</option>
<option value="Costa Rica" >Costa Rica</option>
<option value="Croatia" >Croatia</option>
<option value="Cuba" >Cuba</option>
<option value="Cyprus" >Cyprus</option>
<option value="Czech Republic" >Czech Republic</option>
<option value="Democratic Republic of Congo" >Democratic Republic of Congo</option>
<option value="Denmark" >Denmark</option>
<option value="Djibouti" >Djibouti</option>
<option value="Dominica" >Dominica</option>
<option value="Dominican Republic" >Dominican Republic</option>
<option value="East Timor" >East Timor</option>
<option value="Ecuador" >Ecuador</option>
<option value="Egypt" >Egypt</option>
<option value="El Salvador" >El Salvador</option>
<option value="Equatorial Guinea" >Equatorial Guinea</option>
<option value="Eritrea" >Eritrea</option>
<option value="Estonia" >Estonia</option>
<option value="Ethiopia" >Ethiopia</option>
<option value="Falkland Islands" >Falkland Islands</option>
<option value="Faroe Islands" >Faroe Islands</option>
<option value="Federated States of Micronesia" >Federated States of Micronesia</option>
<option value="Fiji" >Fiji</option>
<option value="Finland" >Finland</option>
<option value="France" >France</option>
<option value="French Guyana" >French Guyana</option>
<option value="French Polynesia" >French Polynesia</option>
<option value="French Southern Territories" >French Southern Territories</option>
<option value="Gabon" >Gabon</option>
<option value="Gambia" >Gambia</option>
<option value="Georgia" >Georgia</option>
<option value="Germany" >Germany</option>
<option value="Ghana" >Ghana</option>
<option value="Gibraltar" >Gibraltar</option>
<option value="Greece" >Greece</option>
<option value="Greenland" >Greenland</option>
<option value="Grenada" >Grenada</option>
<option value="Guadeloupe" >Guadeloupe</option>
<option value="Guam" >Guam</option>
<option value="Guatemala" >Guatemala</option>
<option value="Guinea" >Guinea</option>
<option value="Guinea-Bissau" >Guinea-Bissau</option>
<option value="Guyana" >Guyana</option>
<option value="Haiti" >Haiti</option>
<option value="Heard Island and Mcdonald Islands" >Heard Island and Mcdonald Islands</option>
<option value="Honduras" >Honduras</option>
<option value="Hong Kong" >Hong Kong</option>
<option value="Hungary" >Hungary</option>
<option value="Iceland" >Iceland</option>
<option value="India" >India</option>
<option value="Indonesia" >Indonesia</option>
<option value="Iran" >Iran</option>
<option value="Iraq" >Iraq</option>
<option value="Iraq-Saudi Arabia Neutral Zone" >Iraq-Saudi Arabia Neutral Zone</option>
<option value="Ireland" >Ireland</option>
<option value="Israel" >Israel</option>
<option value="Italy" >Italy</option>
<option value="Ivory Coast" >Ivory Coast</option>
<option value="Jamaica" >Jamaica</option>
<option value="Japan" >Japan</option>
<option value="Jordan" >Jordan</option>
<option value="Kazakhstan" >Kazakhstan</option>
<option value="Kenya" >Kenya</option>
<option value="Kiribati" >Kiribati</option>
<option value="Kuwait" >Kuwait</option>
<option value="Kyrgyzstan" >Kyrgyzstan</option>
<option value="Laos" >Laos</option>
<option value="Latvia" >Latvia</option>
<option value="Lebanon" >Lebanon</option>
<option value="Lesotho" >Lesotho</option>
<option value="Liberia" >Liberia</option>
<option value="Libya" >Libya</option>
<option value="Liechtenstein" >Liechtenstein</option>
<option value="Lithuania" >Lithuania</option>
<option value="Luxembourg" >Luxembourg</option>
<option value="Macau" >Macau</option>
<option value="Macedonia" >Macedonia</option>
<option value="Madagascar" >Madagascar</option>
<option value="Malawi" >Malawi</option>
<option value="Malaysia" >Malaysia</option>
<option value="Maldives" >Maldives</option>
<option value="Mali" >Mali</option>
<option value="Malta" >Malta</option>
<option value="Marshall Islands" >Marshall Islands</option>
<option value="Martinique" >Martinique</option>
<option value="Mauritania" >Mauritania</option>
<option value="Mauritius" >Mauritius</option>
<option value="Mayotte" >Mayotte</option>
<option value="Mexico" >Mexico</option>
<option value="Moldova" >Moldova</option>
<option value="Monaco" >Monaco</option>
<option value="Mongolia" >Mongolia</option>
<option value="Montserrat" >Montserrat</option>
<option value="Montenegro" >Montenegro</option>
<option value="Morocco" >Morocco</option>
<option value="Mozambique" >Mozambique</option>
<option value="Myanmar" >Myanmar</option>
<option value="Namibia" >Namibia</option>
<option value="Nauru" >Nauru</option>
<option value="Nepal" >Nepal</option>
<option value="Netherlands" >Netherlands</option>
<option value="Netherlands Antilles" >Netherlands Antilles</option>
<option value="New Caledonia" >New Caledonia</option>
<option value="New Zealand" >New Zealand</option>
<option value="Nicaragua" >Nicaragua</option>
<option value="Niger" >Niger</option>
<option value="Nigeria" >Nigeria</option>
<option value="Niue" >Niue</option>
<option value="Norfolk Island" >Norfolk Island</option>
<option value="North Korea" >North Korea</option>
<option value="Northern Mariana Islands" >Northern Mariana Islands</option>
<option value="Norway" >Norway</option>
<option value="Oman" >Oman</option>
<option value="Pakistan" >Pakistan</option>
<option value="Palau" >Palau</option>
<option value="Palestinian Territories" >Palestinian Territories</option>
<option value="Panama" >Panama</option>
<option value="Papua New Guinea" >Papua New Guinea</option>
<option value="Paraguay" >Paraguay</option>
<option value="Peru" >Peru</option>
<option value="Philippines" >Philippines</option>
<option value="Pitcairn Islands" >Pitcairn Islands</option>
<option value="Poland" >Poland</option>
<option value="Portugal" >Portugal</option>
<option value="Puerto Rico" >Puerto Rico</option>
<option value="Qatar" >Qatar</option>
<option value="Reunion" >Reunion</option>
<option value="Romania" >Romania</option>
<option value="Russia" >Russia</option>
<option value="Rwanda" >Rwanda</option>
<option value="Saint Helena and Dependencies" >Saint Helena and Dependencies</option>
<option value="Saint Kitts and Nevis" >Saint Kitts and Nevis</option>
<option value="Saint Lucia" >Saint Lucia</option>
<option value="Saint Pierre and Miquelon" >Saint Pierre and Miquelon</option>
<option value="Saint Vincent and the Grenadines" >Saint Vincent and the Grenadines</option>
<option value="Samoa" >Samoa</option>
<option value="San Marino" >San Marino</option>
<option value="Sao Tome and Principe" >Sao Tome and Principe</option>
<option value="Saudi Arabia" >Saudi Arabia</option>
<option value="Senegal" >Senegal</option>
<option value="Serbia" >Serbia</option>
<option value="Seychelles" >Seychelles</option>
<option value="Sierra Leone" >Sierra Leone</option>
<option value="Singapore" >Singapore</option>
<option value="Slovakia" >Slovakia</option>
<option value="Slovenia" >Slovenia</option>
<option value="Solomon Islands" >Solomon Islands</option>
<option value="Somalia" >Somalia</option>
<option value="South Africa" >South Africa</option>
<option value="South Georgia and South Sandwich Islands" >South Georgia and South Sandwich Islands</option>
<option value="South Korea" >South Korea</option>
<option value="Spain" >Spain</option>
<option value="Spratly Islands" >Spratly Islands</option>
<option value="Sri Lanka" >Sri Lanka</option>
<option value="Sudan" >Sudan</option>
<option value="Suriname" >Suriname</option>
<option value="Svalbard and Jan Mayen" >Svalbard and Jan Mayen</option>
<option value="Swaziland" >Swaziland</option>
<option value="Sweden" >Sweden</option>
<option value="Switzerland" >Switzerland</option>
<option value="Syria" >Syria</option>
<option value="Taiwan" >Taiwan</option>
<option value="Tajikistan" >Tajikistan</option>
<option value="Tanzania" >Tanzania</option>
<option value="Thailand" >Thailand</option>
<option value="Togo" >Togo</option>
<option value="Tokelau" >Tokelau</option>
<option value="Tonga" >Tonga</option>
<option value="Trinidad and Tobago" >Trinidad and Tobago</option>
<option value="Tunisia" >Tunisia</option>
<option value="Turkey" >Turkey</option>
<option value="Turkmenistan" >Turkmenistan</option>
<option value="Turks And Caicos Islands" >Turks And Caicos Islands</option>
<option value="Tuvalu" >Tuvalu</option>
<option value="Uganda" >Uganda</option>
<option value="Ukraine" >Ukraine</option>
<option value="United Arab Emirates" >United Arab Emirates</option>
<option value="United Kingdom" >United Kingdom</option>
<option value="United States" >United States</option>
<option value="United States Minor Outlying Islands" >United States Minor Outlying Islands</option>
<option value="Uruguay" >Uruguay</option>
<option value="US Virgin Islands" >US Virgin Islands</option>
<option value="Uzbekistan" >Uzbekistan</option>
<option value="Vanuatu" >Vanuatu</option>
<option value="vVatican City" >Vatican City</option>
<option value="Venezuela" >Venezuela</option>
<option value="Vietnam" >Vietnam</option>
<option value="Wallis and Futuna" >Wallis and Futuna</option>
<option value="Western Sahara" >Western Sahara</option>
<option value="Yemen" >Yemen</option>
<option value="Zambia" >Zambia</option>
<option value="Zimbabwe" >Zimbabwe</option>
</select>
<h2>State</h2>
<p>
<select name="sub_category" id="statename"></select> </p>
<h2>Select Category </h2>
<input name="" src="http://animalswecare.in/images/search_button.gif" type="image" />
</div>
Code for getstate.php (used to get state for selected country if found in DB)
<?php
$q=$_GET["q"];
require_once("../appvars.php");
require_once("../connectuser.php");
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die("error connecting please refresh or try later");
$query = ("SELECT * FROM ads_DB WHERE country=$q") or die("error querying");
$data=mysqli_query($dbc, $query) or die("error here");
echo "<select name='sub_category'>";
?>
<option value="All" selected>All</option>
<?php
while($row = mysqli_fetch_array($data))
{
?>
<option value="<?php echo $row['state']; ?>" ><?php echo $row['state']; ?></option>
<?php
}
?>
<option value="Other" >Other</option>
<?php
echo "</select>";
mysqli_close($dbc);
?>
</form>
link is : http://animalswecare.in/ads/adleft.php
I have used similar code at other place and their it is workin , don't why not working here.
Same thing done here for pet and breed and it is working too : http://animalswecare.in/ads/post-free-pets-animals-ads.php
Try Like this
SELECT * FROM ads_DB WHERE country='$q'
Bcoz u are using a string value in the where clause.single quotes is needed for strings..
Hope it helps..
Are you calling showUser ? in the select change ?
<select name=blah onchange="showUser()">
You check for readyState 4 = completed but your server returns readyState 1 loaded.
you get this error in the link you provided :
Error: uncaught exception: [Exception... "Not enough arguments [nsIXMLHttpRequest.send]"
nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame ::
http://animalswecare.in/ads/adleft.php :: showUser :: line 27" data: no]
so please also try
xmlhttp.send(null)
in your AJAX code. It might help.

drop down data to appear in form php

I have some data in db,now i m making them to display in the front end so,i ii have a update button,if i click it the selected values to come to database
dpaste.com/hold/180863
Thnx in advance.
Chk does your query is giving you any output, here :$result = mysql_query("SELECT FROM customers");
echo ur query and paste in ur SQL query panel of ur PHPmyadmin. see do u get any value or not? if it does not then ur query is incorrect
u have not ended with proper tag here:
<? php
?>
"?>"
UPDATED
<?php
$result = mysql_query("SELECT * FROM Customer"); while($row = mysql_fetch_assoc($result)){ echo "Name: ".$row['0'].", Address:".$row['1'] .", City:".$row['city'].", pincode:".$row['pincode'].", State:".$row['state'].", Country:".$row['country'].", Phone:".$row['phone'].", Mobile:".$row['mobile'].", Fax:".$row['fax'].", Email:".$row['email'].", Website:".$row['url'].", Notes:".$row['notes'].";
?>
u didnt put the ">" at the end in script u refrenced to
UPDATED
DAF, your url : http://localhost/up.php?customer=aaaaa,sssssssssssssss,aaaaaaa,22222Andhra+Pradesh,in,2222221,1111111,0,v#gmail.com,,
is displaying all the values posted , its being appended in the url, I need to see the complete code you are working on
UPDATED
<html>
<body>
<form action="up.php">
<?php
// Create the connection and select the DB-->
$con = mysql_connect("localhost","root","");
if ($con) {
mysql_selectdb("form",$con);
// Select records from the DB
$query = "SELECT * FROM customer";
$result = mysql_query($query);
// Display records from the table
while ($row = mysql_fetch_array($result)) {
$value = $row;
}
}
?>
<p>
<label for="cname"><b>Name:</b></label>
<em>*</em><input id="cname" name="name" size="25" class="required" value="<?php echo $value['name'];?>" minlength="5" />
</p>
<p>
<label for="caddress"><b>Address:</b></label>
<em>*</em><textarea id="caddress" name="address" cols="22" class="required" minlength="3" /><?php echo $value['address'];?></textarea>
</p>
<p>
<label for="ccity"><b>City/Town:</b></label>
<em>*</em><input id="ccity" name="city" size="25" value="<?php echo $value['city'];?>" class="required" minlength="5" />
</p>
<p>
<label for="cpincode"><b>Pincode:</b></label>
<em>*</em><input id="cpincode" name="pincode" size="25" class="required" value="<?php echo $value['cpincode'];?>" digits="5" />
</p>
<p>
<label for="cstate"><b>State:</b></label>
<em>*</em><select class="state" id="cstate" name="state">
<option value="" >Select One</option>
<option <?php if($value['state'] == Andaman and Nicobar){ $selected = "selected='selected'";}else{$selected = "";} echo $selected;?>>Andaman and Nicobar</option>
<option <?php if($value['state'] == Andhra Pradesh){ $selected = "selected='selected'";}else{$selected = "";} echo $selected;?>>Andhra Pradesh</option>
<option <?php if($value['state'] == Arunachal Pradesh){ $selected = "selected='selected'";}else{$selected = "";} echo $selected;?>>Arunachal Pradesh</option>
---
---
---- similar as above
</select>
</p>
<p>
<label for="ccountry"><b>Country:</b></label>
<em>*</em><select class="country" id="ccountry" name="country">
// here as well do as above with $value['country']
<option value="" >Select One</option>
<option value="af" >Afghanistan</option>
<option value="ax" >Aland Islands</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 Herzegovina</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="vg" >British Virgin Islands</option>
<option value="bn" >Brunei</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="ck" >Cook Islands</option>
<option value="cr" >Costa Rica</option>
<option value="hr" >Croatia</option>
<option value="cu" >Cuba</option>
<option value="cy" >Cyprus</option>
<option value="cz" >Czech Republic</option>
<option value="cd" >Democratic Republic of Congo</option>
<option value="dk" >Denmark</option>
<option value="xx" >Disputed Territory</option>
<option value="dj" >Djibouti</option>
<option value="dm" >Dominica</option>
<option value="do" >Dominican Republic</option>
<option value="tl" >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</option>
<option value="fo" >Faroe Islands</option>
<option value="fm" >Federated States of Micronesia</option>
<option value="fj" >Fiji</option>
<option value="fi" >Finland</option>
<option value="fr" >France</option>
<option value="gf" >French Guyana</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 Island and Mcdonald Islands</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" SELECTED >India</option>
<option value="id" >Indonesia</option>
<option value="ir" >Iran</option>
<option value="iq" >Iraq</option>
<option value="xe" >Iraq-Saudi Arabia Neutral Zone</option>
<option value="ie" >Ireland</option>
<option value="il" >Israel</option>
<option value="it" >Italy</option>
<option value="ci" >Ivory Coast</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="kw" >Kuwait</option>
<option value="kg" >Kyrgyzstan</option>
<option value="la" >Laos</option>
<option value="lv" >Latvia</option>
<option value="lb" >Lebanon</option>
<option value="ls" >Lesotho</option>
<option value="lr" >Liberia</option>
<option value="ly" >Libya</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</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="md" >Moldova</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="kp" >North Korea</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="ps" >Palestinian Occupied Territories</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 Islands</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" >Russia</option>
<option value="rw" >Rwanda</option>
<option value="sh" >Saint Helena and Dependencies</option>
<option value="kn" >Saint Kitts and Nevis</option>
<option value="lc" >Saint Lucia</option>
<option value="pm" >Saint Pierre and Miquelon</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</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 South Sandwich Islands</option>
<option value="kr" >South Korea</option>
<option value="es" >Spain</option>
<option value="pi" >Spratly Islands</option>
<option value="lk" >Sri Lanka</option>
<option value="sd" >Sudan</option>
<option value="sr" >Suriname</option>
<option value="sj" >Svalbard and Jan Mayen</option>
<option value="sz" >Swaziland</option>
<option value="se" >Sweden</option>
<option value="ch" >Switzerland</option>
<option value="sy" >Syria</option>
<option value="tw" >Taiwan</option>
<option value="tj" >Tajikistan</option>
<option value="tz" >Tanzania</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="uk" >United Kingdom</option>
<option value="xd" >United Nations Neutral Zone</option>
<option value="us" >United States</option>
<option value="um" >United States Minor Outlying Islands</option>
<option value="uy" >Uruguay</option>
<option value="vi" >US Virgin Islands</option>
<option value="uz" >Uzbekistan</option>
<option value="vu" >Vanuatu</option>
<option value="va" >Vatican City</option>
<option value="ve" >Venezuela</option>
<option value="vn" >Vietnam</option>
<option value="wf" >Wallis and Futuna</option>
<option value="eh" >Western Sahara</option>
<option value="ye" >Yemen</option>
<option value="zm" >Zambia</option>
<option value="zw" >Zimbabwe</option>
<option value="rs" >Serbia</option>
<option value="me" >Montenegro</option>
</select>
</p>
<p>
<label for="cphone"><b>Phone:</b></label>
<em>*</em><input id="cphone" name="phone" size="25" value="<?php echo $value['phone'];?>" class="required" digits="4" />
</p>
<p>
<label for="cmobile"><b>Mobile:</b></label>
<em>*</em><input id="cmobile" name="mobile" value="<?php echo $value['mobile'];?>" size="25" class="required" digits="4" />
</p>
<P>
<label for="num"><b>Fax:</b></label>
<em> </em ><input id="cnum" name="fax" size="25" class="num" value="<?php echo $value['fax'];?>" digits="10" />
</p>
<p>
<label for="cemail"><b>Email:</b></label>
<em>*</em><input id="cemail" name="email" size="25" value="<?php echo $value['email'];?>" class="email" />
</p>
<p>
<label for="curl"><b>Website:</b></label>
<em> </em><input id="curl" name="url" size="25" value="<?php echo $value['url'];?>" class="url" value="" />
</p>
<p>
<label for="cnotes"><b>Notes:</b></label>
<em> </em><textarea id="cnotes" name="notes" cols="22" class="notes" /><?php echo $value['notes'];?></textarea>
</p>
<input type ="submit" value="update" />
</body>
</html>
you're query should be atleast
$result = mysql_query("SELECT column FROM customers")
or
$result = mysql_query("SELECT * FROM customers")

Categories