MYSQL syntax error: inserting image location - mysql

Thanks for taking a moment to look at my issue.
I am working on registration / login system with image upload for user avatar.
I feel I am pretty close but am getting an error in my MYSQL syntax that inserts the image location into the database.
The error reads:
"You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '' at line 2."
Everything else seems to be working okay.
FYI: The directory to store images is "user_pic," the table name is "myMembers," and the column name is "pic_location."
Here is the PHP:
<?php
include_once("scripts/checkuserlog.php");
?>
<?php
// This code runs only if the username is posted
if (isset ($_POST['username'])){
$username = preg_replace('#[^A-Za-z0-9]#i', '', $_POST['username']); // filter everything but letters and numbers
$gender = preg_replace('#[^a-z]#i', '', $_POST['gender']); // filter everything but lowercase letters
$b_m = preg_replace('#[^0-9]#i', '', $_POST['birth_month']); // filter everything but numbers
$b_d = preg_replace('#[^0-9]#i', '', $_POST['birth_day']); // filter everything but numbers
$b_y = preg_replace('#[^0-9]#i', '', $_POST['birth_year']); // filter everything but numbers
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
$user_pic = $_FILES['user_pic'];
$humancheck = $_POST['humancheck'];
$email1 = stripslashes($email1);
$pass1 = stripslashes($pass1);
$email2 = stripslashes($email2);
$pass2 = stripslashes($pass2);
$email1 = strip_tags($email1);
$pass1 = strip_tags($pass1);
$email2 = strip_tags($email2);
$pass2 = strip_tags($pass2);
// Connect to database
include_once "scripts/connect_to_mysql.php";
$emailCHecker = mysql_real_escape_string($email1);
$emailCHecker = str_replace("`", "", $emailCHecker);
// Database duplicate username check setup for use below in the error handling if else conditionals
$sql_uname_check = mysql_query("SELECT username FROM myMembers WHERE username='$username'");
$uname_check = mysql_num_rows($sql_uname_check);
// Database duplicate e-mail check setup for use below in the error handling if else conditionals
$sql_email_check = mysql_query("SELECT email FROM myMembers WHERE email='$emailCHecker'");
$email_check = mysql_num_rows($sql_email_check);
// Error handling for missing data
if ((!$username) || (!$gender) || (!$b_m) || (!$b_d) || (!$b_y) || (!$email1) || (!$email2) || (!$pass1) || (!$pass2) || (!$user_pic)) {
$errorMsg = 'ERROR: You did not submit the following required information:<br /><br />';
if(!$username){
$errorMsg .= ' * User Name<br />';
}
if(!$gender){
$errorMsg .= ' * Gender: Confirm your sex.<br />';
}
if(!$b_m){
$errorMsg .= ' * Birth Month<br />';
}
if(!$b_d){
$errorMsg .= ' * Birth Day<br />';
}
if(!$b_y){
$errorMsg .= ' * Birth year<br />';
}
if(!$email1){
$errorMsg .= ' * Email Address<br />';
}
if(!$email2){
$errorMsg .= ' * Confirm Email Address<br />';
}
if(!$pass1){
$errorMsg .= ' * Login Password<br />';
}
if(!$pass2){
$errorMsg .= ' * Confirm Login Password<br />';
}
if(!$user_pic){
$errorMsg .= ' * Add a Profile Photo<br />';
}
} else if ($email1 != $email2) {
$errorMsg = 'ERROR: Your Email fields below do not match<br />';
} else if ($pass1 != $pass2) {
$errorMsg = 'ERROR: Your Password fields below do not match<br />';
} else if (strlen($username) < 4) {
$errorMsg = "<u>ERROR:</u><br />Your User Name is too short. 4 - 20 characters please.<br />";
} else if (strlen($username) > 20) {
$errorMsg = "<u>ERROR:</u><br />Your User Name is too long. 4 - 20 characters please.<br />";
} else if ($uname_check > 0){
$errorMsg = "<u>ERROR:</u><br />Your User Name is already in use inside of our system. Please try another.<br />";
} else if ($email_check > 0){
$errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside of our system. Please use another.<br />";
} else if ($_FILES['user_pic']['size'] > 2000000 ){
$errorMsg = "<u>ERROR:</u><br />Your image is too large.<br />";
unlink($_FILES['user_pic']['tmp_name']);
} else if (!preg_match("/\.(gif|jpg|png|jpeg)$/i", $_FILES['user_pic']['name'])) {
$errorMsg = "<u>ERROR:</u><br />Your image is in an unacceptable format.<br />";
unlink($_FILES['user_pic']['tmp_name']);
} else {
// Error handling is ended, process the data and add member to database
$email1 = mysql_real_escape_string($email1);
$pass1 = mysql_real_escape_string($pass1);
// Add MD5 Hash to the password variable
$db_password = md5($pass1);
// Convert Birthday to a DATE field type format(YYYY-MM-DD) out of the month, day, and year supplied
$full_birthday = "$b_y-$b_m-$b_d";
// GET USER IP ADDRESS
$ipaddress = getenv('REMOTE_ADDR');
//add the avatar
$name = $_FILES['user_pic']['name'];
$tmp_name = $_FILES['user_pic']['tmp_name'];
$location = "user_pic/$name";
move_uploaded_file($tmp_name, "user_pic/.$name");
// Add user info into the database table for the main site table
$sql = mysql_query("INSERT INTO myMembers (username, gender, birthday, email, password, pic_location, ipaddress, sign_up_date)
VALUES('$username','$gender','$full_birthday','$email1','$db_password', '$location', '$ipaddress', now()")
or die (mysql_error());
$id = mysql_insert_id();
// Create directory to hold each user's files(pics, MP3s, etc.)
$newname = "image01.jpg";
$place_file = move_uploaded_file( $_FILES['user_pic']['tmp_name'], "members/$id/".$newname);
mysql_query("INSERT INTO myMembers (pic_location) VALUES ('$location')");
include_once 'msgToUser.php';
exit();
}// Close else after duplication checks
} else { // if the form is not posted with variables, place default empty variables so no warnings or errors show
$errorMsg = "";
$username = "";
$gender = "";
$b_m = "";
$b_d = "";
$b_y = "";
$email1 = "";
$email2 = "";
$pass1 = "";
$pass2 = "";
$user_pic = "";
}
?>
I believe the offending query is:
"mysql_query("INSERT INTO myMembers (pic_location) VALUES
('$location')");"
because the problem arose after adding this section.
I also tried including the pic_location in prior query so that it read
"$sql = mysql_query("INSERT INTO myMembers (username, gender,
birthday, email, password, pic_location, ipaddress, sign_up_date)
VALUES('$username','$gender','$full_birthday','$email1','$db_password',
'$location','$ipaddress', now()") or die (mysql_error());"
but that did not seem to work either…
This is the HTML portion if you're interested:
<html>
<body>
<h4>Create your Account: </h4><h9>all fields required</h9>
<table class="table_f" width="100%" cellpadding="3">
<form action="register.php" method="post" enctype="multipart/form-data">
<tr>
<td colspan="2"><font color="#94A0D1"><?php print "$errorMsg"; ?></font></td>
</tr>
<tr>
<td><h11>User Name:</h11></td>
<td><input name="username" type="text" class="formFields" id="username" value="<?php print "$username"; ?>" size="32" maxlength="20" />
</tr>
<tr>
<td><h11>Gender:</h11></td>
<td><label>
<input name="gender" style="color: #a2a2a2; font-family: 'light', Verdana; font-size: 11px; letter-spacing: 1px" type="radio" id="gender" value="m" checked="checked" />Male
<input type="radio" name="gender" id="gender" value="f" />Female
</label></td>
</tr>
<tr>
<td><h11>Date of Birth: </h11></td>
<td>
<select name="birth_month" class="formFields" id="birth_month">
<option value="<?php print "$b_m"; ?>"><?php print "$b_m"; ?></option>
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="birth_day" class="formFields" id="birth_day">
<option value="<?php print "$b_d"; ?>"><?php print "$b_d"; ?></option>
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="birth_year" class="formFields" id="birth_year">
<option value="<?php print "$b_y"; ?>"><?php print "$b_y"; ?></option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
<option value="1999">1999</option>
<option value="1998">1998</option>
<option value="1997">1997</option>
<option value="1996">1996</option>
<option value="1995">1995</option>
<option value="1994">1994</option>
<option value="1993">1993</option>
<option value="1992">1992</option>
<option value="1991">1991</option>
<option value="1990">1990</option>
<option value="1989">1989</option>
<option value="1988">1988</option>
<option value="1987">1987</option>
<option value="1986">1986</option>
<option value="1985">1985</option>
<option value="1984">1984</option>
<option value="1983">1983</option>
<option value="1982">1982</option>
<option value="1981">1981</option>
<option value="1980">1980</option>
<option value="1979">1979</option>
<option value="1978">1978</option>
<option value="1977">1977</option>
<option value="1976">1976</option>
<option value="1975">1975</option>
<option value="1974">1974</option>
<option value="1973">1973</option>
<option value="1972">1972</option>
<option value="1971">1971</option>
<option value="1970">1970</option>
<option value="1969">1969</option>
<option value="1968">1968</option>
<option value="1967">1967</option>
<option value="1966">1966</option>
<option value="1965">1965</option>
<option value="1964">1964</option>
<option value="1963">1963</option>
<option value="1962">1962</option>
<option value="1961">1961</option>
<option value="1960">1960</option>
<option value="1959">1959</option>
<option value="1958">1958</option>
<option value="1957">1957</option>
<option value="1956">1956</option>
<option value="1955">1955</option>
<option value="1954">1954</option>
<option value="1953">1953</option>
<option value="1952">1952</option>
<option value="1951">1951</option>
<option value="1950">1950</option>
<option value="1949">1949</option>
<option value="1948">1948</option>
<option value="1947">1947</option>
<option value="1946">1946</option>
<option value="1945">1945</option>
<option value="1944">1944</option>
<option value="1943">1943</option>
<option value="1942">1942</option>
<option value="1941">1941</option>
<option value="1940">1940</option>
<option value="1939">1939</option>
<option value="1938">1938</option>
<option value="1937">1937</option>
<option value="1936">1936</option>
<option value="1935">1935</option>
<option value="1934">1934</option>
<option value="1933">1933</option>
<option value="1932">1932</option>
<option value="1931">1931</option>
</select>
</div>
</td>
</tr>
<tr>
<td><h11>Email Address: </h11></td>
<td><input name="email1" type="text" class="formFields" id="email1" value="<?php print "$email1"; ?>" size="32" maxlength="48" /></td>
</tr>
<tr>
<td><h11>Confirm Email: </h11></td>
<td><input name="email2" type="text" class="formFields" id="email2" value="<?php print "$email2"; ?>" size="32" maxlength="48" /></td>
</tr>
<tr>
<td><h11>Create Password: </h11></td>
<td><input name="pass1" type="password" class="formFields" id="pass1" size="32" maxlength="16" />
</tr>
<tr>
<td><h11>Confirm Password: </h11></td>
<td><input name="pass2" type="password" class="formFields" id="pass2" size="32" maxlength="16" />
</tr>
<tr>
<td><h11>Add Profile Photo: </h11></td>
<input type='hidden' name='MAX_FILE_SIZE' value='2000000'>
<td width="521"><input name="user_pic" type="file" class="formFields" size="42" />
50 kb max </td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" style="color: #a2a2a2; font-family: helvetica; font-size: 11px; letter-spacing: 1px" name="Submit" value="Register" />
</td>
</tr>
</form>
</table>
<br /></td>
</tr>
</table>
</body>
</html>
Thanks for any advice that will help me address this issue.
I'm sure that the script could be better so any general comments on improving it are welcome, also.
Thanks a lot. I really appreciate any help.
nbewley

You've missed a closing parenthese in your query. Change:
$sql = mysql_query("INSERT INTO myMembers (username, gender, birthday, email, password, pic_location, ipaddress, sign_up_date)
VALUES('$username','$gender','$full_birthday','$email1','$db_password', '$location', '$ipaddress', now()")
or die (mysql_error());
to
$sql = mysql_query("INSERT INTO myMembers (username, gender, birthday, email, password, pic_location, ipaddress, sign_up_date)
VALUES('$username','$gender','$full_birthday','$email1','$db_password', '$location', '$ipaddress', now())")
or die (mysql_error());
Also, unrelated, MD5 has been cryptographically broken. You should store passwords in SHA256 using PHP's hash function: hash( 'sha256', $password );
Alternative troubleshooting, try printing out the value of $location and posting it. You may need to escape that string as well.

you miss ) in this line end that close the VALUES
$sql = mysql_query("INSERT INTO myMembers (username, gender, birthday, email, password, pic_location, ipaddress, sign_up_date)
VALUES('$username','$gender','$full_birthday','$email1','$db_password', '$location', '$ipaddress', now()")
should be
$sql = mysql_query("INSERT INTO myMembers (username, gender, birthday, email, password, pic_location, ipaddress, sign_up_date)
VALUES('$username','$gender','$full_birthday','$email1','$db_password', '$location', '$ipaddress', now())")

Related

Multi forms with selects but all $_POST are overwritten with last $_POST

In below test code I try to save and use 3 $_POST variables. But only the last $_POST variable is stored. The rest is overwritten with the last $_POST variable.
Purpose of the question is to select first the wanted country. Select from a table the country as selected. Then select the wanted a car_brand from the selected country. Then select the wanted company and filter this from the selected country+car_brand.
I have tried to store the 3 $_POST into a $_SESSION also tried it with $_REQUEST via type="hidden" without getting the 3 $_POST variables.
Question: what do I do wrong and how can I solve this problem?
session_start();
$content .= ' <form id="sel_country" method="POST">
<select name="country" onchange="this.form.submit()" >
<option value="NL">Netherlands</option>
<option value="DE">German</option>
<option value="GB">England</option>
</select>
</form>';
$content .= '<form id="sel_car_brand" method="POST">
<select name="brand" onchange="this.form.submit()" >
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="audi">Audi</option>
</select>
</form>';
$content .= ' <form id="sel_company" method="POST">
<select name="company" onchange="this.form.submit()">
<option value="dealer">Dealer</option>
<option value="service">Service</option>
<option value="import">Importer</option>
</select>
</form>';
$_SESSION['country'] = $_POST['country'];
$_SESSION['brand'] = $_POST['brand'];
$_SESSION['company'] = $_POST['company'];
var_dump($_SESSION) ;
Had a session_start() at the beginning and then stock your variable in it. Like $_SESSION['country'] = $_POST['country'] when $_POST['country'] is defined (do a var_dump() to verify it) and you'll be able to access your datas stocked in your $_SESSION.
session_start();
$content .= ' <form id="sel_country" method="POST">
<select name="country" onchange="this.form.submit()" >
<option value="NL">Netherlands</option>
<option value="DE">German</option>
<option value="GB">England</option>
</select>
</form>';
$_SESSION['country'] = $_POST['country'];
$content .= '<form id="sel_car_brand" method="POST">
<select name="brand" onchange="this.form.submit()" >
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="audi">Audi</option>
</select>
</form>';
$_SESSION['brand'] = $_POST['brand'];
$content .= ' <form id="sel_company" method="POST">
<select name="company" onchange="this.form.submit()">
<option value="dealer">Dealer</option>
<option value="service">Service</option>
<option value="import">Importer</option>
</select>
</form>';
$_SESSION['company'] = $_POST['company'];
var_dump($_SESSION) ;
// Edited by moliets: var_dump response: array(3) { ["country"]=> NULL ["brand"]=> NULL ["company"]=> string(6) "import" }

html form many options

Hi I would like to hear if there are alternatives for these forms
so I dont have to write for every single option
1. For the age form
For the country form
<select name="age">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<!--And again and again and... again-->
<option value="99">99</option>
</select>
<select name="country">
<option value="England">England</option>
<option value="Sweeden">Sweeden</option>
<option value="Norway">Norway</option>
<option value="Denmark">Denmark</option>
<option value="Usa">Usa</option>
<option value="Spain">Spain</option>
<option value="Scotland">Scotland</option>
<option value="Ireland">Ireland</option>
<option value="French">French</option>
<option value="Italy">Italy</option>
<option value="Germany">Germany</option>
<option value="Poland">Poland</option>
<option value="Netherland">Netherland</option>
<option value="Australia">Australia</option>
<option value="China">China</option>
<option value="Japan">Japan</option>
<option value="Singapore">Singapore</option>
<option value="Russia">Russia</option>
<option value="Other">Other</option>
</select>
Hope you understand my question. Sos for bad english
There is a HTML "range" input, but it's not the most common input method out there and will require some javascript with it. Other than that, the only reasonable method is PHP. Though, if you do use PHP, you can copy and paste the HTML and then insert it into your HTML file if you don't want that page to have PHP. Below are a few HTML only examples. May not work in all browsers, so your server side code should always validate. http://jsfiddle.net/h96nU/1/
The below code shows a few inputs using various methods. The range input will update to show the range value that is currently selected. The last number input uses the HTML5 pattern attribute.
input:invalid {
border: 1px solid red;
}
input:valid {
border: 1px solid green;
}
<div>
<input id="range" type="range" min="1" max="120" step="1" />
<span id="range_value">0</span>
</div>
<div>
<input type="number" />
</div>
<div>
<input type="text" />
</div>
<div>
<input type="number" min="1" max="120" step="1" id="n1" name="age" pattern="\d+" />
</div>
var input = document.getElementById('range');
input.addEventListener('change',input_change,false);
function input_change(e) {
var target = e.target || e.srcElement;
var value = target.value;
var showdiv = document.getElementById('range_value');
showdiv.textContent = value;
}
More about Data Validation in HTML can be found at https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Data_form_validation
For PHP method of an age input loop, look below.
<?php
$min = 1;
$max = 100;
echo '<select name="age">';
for($i = $min; $i <= $max; $i++) {
echo '<option value="'.$i.'">'.$i.'</option>';
}
echo '</select>';
?>
If you are using PHP for example you could do it like this:
<?php
$myArray = ['USA','Australia','ETC ETC ETC'];
echo '<select name="country">';
foreach ($myArray as $value) {
echo '<option value="'.$value.'">';
echo $value;
echo "</option>";
}
echo "</select>";
?>
The output of this example would be :
<select name="country">
<option value="USA">USA</option>
<option value="Australia">Australia</option>
<option value="ETC ETC ETC">ETC ETC ETC</option>
</select>
For your age selectbox:
<?php
$maxAge = 99;
echo '<select name="age">';
for ($i=1; $i < $maxAge; $i++) {
echo '<option value="'.$i.'">';
echo $i;
echo "</option>";
}
echo "</select>";
?>

html select dropdown wont stay selected

I have a select dropdown list on my website(www.irishbonus.comule.com/en/). However when I select an option from the dropdown list and press submit I would like that the option stay selected.
Here is the code for the select:
<form action="" method="post">
<strong> Select Subject:</strong>
<select name="formSubject" class="dropdown">
<option value=">>>">">>>"</option>
<option value="Accounting">Accounting</option>
<option value="Agricultural Science">Agricultural Science</option>
<option value="Agricultural Economics">Agricultural Economics</option>
<option value="Applied Mathematics">Applied Mathematics</option>
<option value="Arabic">Arabic</option>
<option value="Art (jc only)">Art (jc only)</option>
<option value="Biology">Biology</option>
<option value="Business (jc only)">Business (jc only)</option>
<option value="Business Studies">Business Studies</option>
<option value="Chemistry">Chemistry</option>
<option value="Civic (jc only)">Civic (jc only)</option>
<option value="Classical Studies">Classical Studies</option>
<option value="Construction Studies">Construction Studies</option>
//more options
<option value="Typewriting (jc only)">Typewriting (jc only)</option>
</select>
<table width="300px">
<tr>
<td valign="top">
<strong>Insert Mark:</strong>
<input type="text" name="formMark" maxlength="2" size="4" value="<?=$mark;?>"/>
</td>
</tr>
</table>
<input type="submit" />
</form>
You need to use a server-side language for this. You already seem to be using PHP so just add some PHP code to do it. The best solution would be storing your options inside an array and then iterating over the array, outputting the <option> tags and adding the selected attribute if the value matches the submitted value.
<select name="formSubject" class="dropdown">
<?php
$options = ['Accounting', 'Agricultural Science', '...'];
$selected = isset($_POST['formSubject']) ? $_POST['formSubject'] : '';
foreach($options as $option) {
echo '<option value="'.$option.'"'.($selected == $option ? ' selected' : '').'>'.$option.'</option>';
}
?>
</select>
He forgot the array(), that is why the parse error is there
here:
<select name="formSubject" class="dropdown">
<?php
$options = array('Accounting', 'Agricultural Science', '...');
$selected = isset($_POST['formSubject']) ? $_POST['formSubject'] : '';
foreach($options as $option) {
echo '<option value="'.$option.'"'.($selected == $option ? ' selected' : '').'>'.$option.'</option>';
}
?>
</select>
while ($row = $result->fetch_assoc()) {
$selected = "";
if(isset($_GET['spec'])) {
if($_GET['spec'] == $row['id']) {
$selected = "selected='selected'";
}
}
print "<option ". $selected ." value='". $row['id'] ."'>". $row['ime']. "</option>";
}
$result->free();

MYSQL - You have an error in your SQL syntax [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I found an error in my code when i try to insert my form in db...
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '' at line 2
Form:
<div class="form">
<form id="contactform" method="POST" action="">
<p class="contact"><label for="name">Name</label></p>
<input id="name" name="name" placeholder="First and last name" required="" tabindex="1" type="text" value="<?php echo $name;?>">
<p class="contact"><label for="email">Email</label></p>
<input id="email" name="email" placeholder="example#domain.com" required="" type="email" value="<?php echo $email;?>">
<p class="contact"><label for="username">Create a username</label></p>
<input id="username" name="username" placeholder="username" required="" tabindex="2" type="text" value="<?php echo $username;?>">
<p class="contact"><label for="password">Create a password</label></p>
<input type="password" id="password" name="password" required="" placeholder="Set password">
<p class="contact"><label for="repassword">Confirm your password</label></p>
<input type="password" id="repassword" name="repassword" required="" placeholder="Confirm password"> </br>
<label>Birthday</label></br>
<select class="select-style" name="birthMonth" >
<option value="" class="nothing">Month</option>
<option value="01">January</option>
<option value="02">February</option>
<option value="03" >March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12" >December</option>
</select>
<select class="select-style" name="birthDay" required="">
<option value="" class="nothing">Day</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<input class="birthyear" maxlength="4" name="birthYear" placeholder="Year" required="" value="<?php echo $birthYear;?>">
</br>
<label>Gender</label>
<select class="select-style" style="width:400px;" name="gender" >
<option class="nothing" value="select">i am..</option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="others">Other</option>
</select><br><br>
<input class="buttom" name="submit" id="submit" tabindex="5" value="Sign me up!*" type="submit">
<font style="color:white; size:10px; background-color:black"> * - By clicking on "Sign me up" button, you completly agree with <u>Terms & Conditions of use</u> .</font>
Validate:
if(isset($_POST['submit'])){
//VARIABLES
$name = $_POST['name'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];
$confPass = $_POST['repassword'];
$birthDay = $_POST['birthDay'];
$birthMonth = $_POST['birthMonth'];
$birthYear = $_POST['birthYear'];
$gender = $_POST['gender'];
$type = 'user';
$birthday = date($birthDay."/".$birthMonth."/".$birthYear);
$date0 = mktime(0,0,0,date("m"),date("d"),date("Y"));
$today = date("Y/m/d", $date0);
echo '<script type="text/javascript">','hideTerms();','</script>';
if(strlen($password) < 5 or $password != $confPass){
echo "<span id='abouTitle'> Something wrong..</span>";
echo "<script type='text/javascript'> alert('Password too small or different');</script>";
}else{
echo "<span id='abouTitle'>Bem-Vindo, ".$username."!</span></br></br>";
echo '<font style="color:white; font-size:20px;"';
echo 'Name: '.$name.'</br>Email: '.$email.'</br>Username: '.$username.'</br>Password: <u>-Check your email-</u> </br>Birthday: '.$birthday.'</br>Gender: '.$gender.'</br>Account type: '.$type.'</br>Account Creation Day: '.$today.'</br>';
include ('php/content/connect.php');
$sql = mysql_query("INSERT INTO users (name, email, username, password, /*birthday,*/ gender, accountType/*, creationDate*/)
VALUES ( '$name', '$email', '$username', '$password',/*STR_TO_DATE('$birthYear,$birthMonth,$birthDay','%Y,%m,%d'),*/ '$gender', '$type'/*, '$today'*/") or die(mysql_error());
$data = mysql_query($sql);
$termina = mysql_close($conexao);
}
}else{
$name = "";
$email = "";
$birthYear ="";
$username = "";
}echo '</font>';
?>
Problem of parenthesis at the end of the syntax, you are closing the VALUES parenthesis but not the mysql_query one:
mysql_query("INSERT INTO users (name, email, username, password, /*birthday,*/ gender, accountType/*, creationDate*/)
VALUES ( '$name', '$email', '$username', '$password',/*STR_TO_DATE('$birthYear,$birthMonth,$birthDay','%Y,%m,%d'),*/ '$gender', '$type'/*, '$today'*/ )")

How do I auto-select an option in a select field based on URL parameter?

In the form below, how do I get autoselect the various options based on the values of my URL parameters?
eg: http://example.com/?type=%28shirt%2C+tshirt%2C+t-shirt%29&length=25&width=17&expand=yes
<form name="shirty" method="get">
<select name="type" />
<option value="(shirt, tshirt, t-shirt)">T-Shirt</option>
<option value="(hoodie, sweatshirt)">Sweatshirt</option>
</select>
<select name="length" />
<option value="select">Select a length</option>
<option value="14">14 Inches</option>
<option value="15">15 Inches</option>
<option value="16">16 Inches</option>
<option value="17">17 Inches</option>
<option value="18">18 Inches</option>
<option value="19">19 Inches</option>
<option value="20">20 Inches</option>
</select>
<select name="width" />
<option value="select">Select a Width</option>
<option value="14">14 Inches</option>
<option value="15">15 Inches</option>
<option value="16">16 Inches</option>
<option value="17">17 Inches</option>
<option value="18">18 Inches</option>
<option value="19">19 Inches</option>
<option value="20">20 Inches</option>
</select>
<input type="checkbox" name="expand" value="yes"" checked><small>include ± 1 inch?</small>
<input type="submit" name="Submit" value="Search" />
</form>
Got it.
<form name="shirty" method="get">
<select name="type" />
<?php //create the select options
$options = "
<option value=\"(shirt, tshirt, t-shirt)\">T-Shirt</option>
<option value=\"(hoodie, sweatshirt)\">Sweatshirt</option>";
$saved = $type;
$saved = (!empty($saved))? $saved: false;
if ($saved)
//if there is a saved data set the option to selected
$options = str_replace('value="'.$saved.'"','value="'.$saved.'" selected="selected"',$options);
//echo out the options
echo $options; ?>
?>
</select>
<select name="length" />
<?php //create the select options
$options = "
<option value=\"14\">14 Inches</option>
<option value=\"15\">15 Inches</option>
<option value=\"16\">16 Inches</option>
<option value=\"17\">17 Inches</option>
<option value=\"18\">18 Inches</option>
<option value=\"19\">19 Inches</option>
<option value=\"20\">20 Inches</option>";
$saved = $length;
$saved = (!empty($saved))? $saved: false;
if ($saved)
//if there is a saved data set the option to selected
$options = str_replace('value="'.$saved.'"','value="'.$saved.'" selected="selected"',$options);
//echo out the options
echo $options; ?>
?>
</select>
<select name="width" />
<?php //create the select options
$options = "
<option value=\"14\">14 Inches</option>
<option value=\"15\">15 Inches</option>
<option value=\"16\">16 Inches</option>
<option value=\"17\">17 Inches</option>
<option value=\"18\">18 Inches</option>
<option value=\"19\">19 Inches</option>
<option value=\"20\">20 Inches</option>";
$saved = $width;
$saved = (!empty($saved))? $saved: false;
if ($saved)
//if there is a saved data set the option to selected
$options = str_replace('value="'.$saved.'"','value="'.$saved.'" selected="selected"',$options);
//echo out the options
echo $options; ?>
?>
</select>
<input type="checkbox" name="expand" value="yes"" checked><small>include ± 1 inch?</small>
<input type="submit" name="Submit" value="Search" />
</form>
<?php
//This example creates a select element and marks selected option using selected_id in URL
$attributesAssocArray = array(
"id"=>"someId","class"=>"someClass"
);
$optionsArray = array(
0=>"choose...",1=>"one",2=>"two",3=>"three"
);
$selectedId = (!empty($_GET['selected_id'])&&(is_numeric($_GET['selected_id'])))? intval($_GET['selected_id']):-1;
echo generate_select($attributesAssocArray,$optionsArray,$selectedId);
function generate_select($attributesAssocArray=array(),$optionsArray=array(),$selected=-1)
{
$attributes = generate_attributes($attributesAssocArray);
$html = '<select '.$attributes.'>';
foreach ($optionsArray as $value => $name)
{
$isSelected = $value==$selected ? " selected" : "";
$html.= '<option value="'.$value.'"'.$isSelected.'>'.$name.'</option>';
}
$html.='</select>';
return $html;
}
function generate_attributes($attributesAssocArray)
{
$attributes='';
foreach ($attributesAssocArray as $name => $value)
{
$attributes.= $name.'="'.$value.'" ';
}
return $attributes;
}
?>