mikebyrne Posted April 7, 2008 Share Posted April 7, 2008 A couple of my variables are not passing to the db and I cant see why?? They are: Brthday, Birthmonth, Bithyear, password2, name & country The sql for db is: CREATE TABLE `adminusers` ( `name` varchar(255) collate latin1_general_ci default NULL, `address` varchar(255) collate latin1_general_ci default NULL, `address1` varchar(255) collate latin1_general_ci default NULL, `address2` varchar(255) collate latin1_general_ci default NULL, `address3` varchar(255) collate latin1_general_ci default NULL, `address4` varchar(255) collate latin1_general_ci default NULL, `county` varchar(255) collate latin1_general_ci default NULL, `country` varchar(255) collate latin1_general_ci default NULL, `birthday` varchar(2) collate latin1_general_ci default NULL, `birthmonth` varchar(4) collate latin1_general_ci default NULL, `birthyear` varchar(4) collate latin1_general_ci default NULL, `zip` varchar(255) collate latin1_general_ci default NULL, `telephone` decimal(10,0) default NULL, `email` varchar(255) collate latin1_general_ci default NULL, `username` varchar(255) collate latin1_general_ci default NULL, `password` varchar(255) collate latin1_general_ci default NULL, `password2` varchar(255) collate latin1_general_ci default NULL, `usertype` decimal(10,0) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; My code is: <?php require_once("adminconnect.php"); $tbl_name="adminusers"; echo $_POST['name']; echo $_POST['address']; echo $_POST['address1']; echo $_POST['address2']; echo $_POST['address3']; echo $_POST['county']; echo $_POST['zip']; echo $_POST['telephone']; echo $_POST['motelephone']; echo $_POST['password']; echo $_POST['password2']; echo $_POST['username']; echo $_POST['email']; echo $_POST['birthdate']; echo $_POST['birthmonth']; echo $_POST['birthyear']; echo $_POST['country']; echo $_POST['sex']; $name = mysql_real_escape_string(trim($_POST['name'])); $address = mysql_real_escape_string(trim($_POST['address'])); $address1 = mysql_real_escape_string(trim($_POST['address1'])); $address2 = mysql_real_escape_string(trim($_POST['address2'])); $address3 = mysql_real_escape_string(trim($_POST['address3'])); $county = mysql_real_escape_string(trim($_POST['county'])); $zip = mysql_real_escape_string(trim($_POST['zip'])); $telephone = mysql_real_escape_string(trim($_POST['telephone'])); $motelephone = mysql_real_escape_string(trim($_POST['motelephone'])); $email = mysql_real_escape_string(trim($_POST['email'])); $password =mysql_real_escape_string(trim($_POST['password'])); $username = mysql_real_escape_string(trim($_POST['username'])); $user = mysql_real_escape_string(htmlspecialchars($_POST['username'])); $sql = "SELECT name FROM adminusers WHERE username ='$user'"; $result = mysql_query($sql) or die("Error in SQL: ".mysql_error()); $row = mysql_fetch_array($result); $count = mysql_num_rows($result); $test = $row['name']; $sql="INSERT INTO $tbl_name(name, address, address1, address2, address3, county, country, birthday, birthmonth, birthyear, zip, telephone, email, username, password, password2, usertype)VALUES('$name', '$address', '$address1', '$address2','$address3', '$county' , '$country','$birthday', '$birthmonth', '$birthyear','$zip', '$telephone', '$email', '$username', '$password' , '$password2', 1)"; mysql_query($sql) or die(mysql_error().'<br /> Query was:'.$sql); ?> <form name = "form" method="POST" action="register.php"> <tr> <td align="right" width="50%"><span class="t11br">*</span> Name:</td> <td> <input class="byp" type="text" name="name" size="30" maxlength="30" value="<?php $name; ?>"> </td> </tr> <tr> <td align="right"><span class="t11br">*</span> Address line 1:</td> <td> <input class="byp" type="text" name="address" size="30" maxlength="30" value="<?php $address; ?>"> </td> </tr> <tr> <td align="right">Address line 2:</td> <td> <input class="byp" type="text" name="address1" size="30" maxlength="30" value="<?php $address1; ?>"> </td> </tr> <tr> <td align="right">Address line 3:</td> <td> <input class="byp" type="text" name="address2" size="30" maxlength="30" value="<?php $address2 ;?>"> </td> </tr> <tr> <td align="right">Address line 4:</td> <td> <input class="byp" type="text" name="address3" size="30" maxlength="30" value="<?php $address3; ?>"> </td> </tr> <tr> <td align="right"><span class="t11br">*</span> County / State:</td> <td> <input class="byp" type="text" name="county" size="30" maxlength="30" value="<?php $county; ?>"> </td> </tr> <tr> <td align="right"><span class="t11br">*</span> Post/Zip Code:</td> <td> <input class="byp" type="text" name="zip" size="20" maxlength="20" value="<?php $zip; ?>"> </td> </tr> <tr> <td align="right"><span class="t11br">*</span> Country:</td> <td> <select class="byp" name="country"> <option value="country" selected></option><option value="GB">United Kingdom</option><option value="US">United States of America</option><option value="AG">Antigua and Barbuda</option><option value="AR">Argentina</option><option value="AU">Australia</option><option value="AT">Austria</option><option value="BS">Bahamas</option><option value="BB">Barbados</option><option value="BE">Belgium</option><option value="BM">Bermuda</option><option value="CA">Canada</option><option value="KY">Cayman Islands</option><option value="TD">Chad</option><option value="CL">Chile</option><option value="CN">China</option><option value="CU">Cuba</option><option value="CY">Cyprus</option><option value="CZ">Czech Republic</option><option value="DK">Denmark</option><option value="EG">Egypt</option><option value="FK">Falkland Islands</option><option value="FO">Faroe Islands</option><option value="FI">Finland</option><option value="FR">France</option><option value="DE">Germany</option><option value="GI">Gibraltar</option><option value="GL">Greenland</option><option value="GD">Grenada</option><option value="VA">Holy See (Vatican City State)</option><option value="HK">Hong Kong</option><option value="IS">Iceland</option><option value="IN">India</option><option value="IE">Ireland</option><option value="IT">Italy</option><option value="JM">Jamaica</option><option value="JP">Japan</option><option value="JO">Jordan</option><option value="KE">Kenya</option><option value="KW">Kuwait</option><option value="LR">Liberia</option><option value="LI">Liechtenstein</option><option value="LU">Luxembourg</option><option value="MS">Montserrat</option><option value="MO">Macau</option><option value="MY">Malaysia</option><option value="MQ">Martinique</option><option value="MR">Mauritania</option><option value="MX">Mexico</option><option value="MC">Monaco</option><option value="NL">Netherlands</option><option value="AN">Netherlands Antilles</option><option value="NZ">New Zealand</option><option value="KP">North Korea</option><option value="NO">Norway</option><option value="OM">Oman</option><option value="PK">Pakistan</option><option value="PA">Panama</option><option value="PY">Paraguay</option><option value="PH">Philippines</option><option value="PL">Poland</option><option value="PT">Portugal</option><option value="PR">Puerto Rico</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 Grenadin</option><option value="SM">San Marino</option><option value="SC">Seychelles</option><option value="SG">Singapore</option><option value="ZA">South Africa</option><option value="KR">South Korea</option><option value="ES">Spain</option><option value="LK">Sri Lanka</option><option value="SE">Sweden</option><option value="CH">Switzerland</option><option value="TW">Taiwan</option><option value="TH">Thailand</option><option value="TT">Trinidad and Tobago</option><option value="TN">Tunisia</option><option value="TR">Turkey</option><option value="TC">Turks and Caicos Islands</option><option value="UM">United States Minor Outlying I</option><option value="UY">Uruguay</option><option value="VE">Venezuela</option><option value="VN">Vietnam</option><option value="VG">Virgin Islands (British)</option><option value="VI">Virgin Islands (US)</option> </select> </td> </tr> <tr> <td align="right"><span class="t11br">*</span> Contact Telephone no:</td> <td> <input class="byp" type="text" name="telephone" size="30" maxlength="30" value="<?php $telephone; ?>"> </td> </tr> <tr> <td align="right">Mobile Telephone no:</td> <td> <input class="byp" type="text" name="mobile" size="30" maxlength="30" value="<?php $motelephone; ?>"> </td> </tr> <tr> <td align="right"><span class="t11br">*</span> Birthdate:</td> <td> <select class="byp" name="birthdate"> <option value="<?php $birthdate; ?>"> <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> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">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 class="byp" name="birthmonth"> <option value="" selected ></option> <option value="Jan">January</option> <option value="Feb">Febuary</option> <option value="March">March</option> <option value="April">April</option> <option value="May">May</option> <option value="June">June</option> <option value="July">July</option> <option value="Aug">August</option> <option value="Sept">September</option> <option value="Oct">October</option> <option value="Nov">November</option> <option value="Dec">December</option> </select> <input class="byp" type="text" name="birthyear" size="4" maxlength="4" value="<?php $birthday; ?>"> <br> (Year Optional eg. 1977 not 77) </td> </tr> <tr> <td align="right">I am:</td> <td> <select class="byp" name="sex"> <option value="sex"></option> <option value="M">A gentleman</option> <option value="F">A lady</option> </select> </td> </tr> <tr> <td colspan="2"><img src="http://images-cache.cd-wow.com/images/bluepix.gif" width="100%" height="1"></td> </tr> <tr> <td colspan="2" class="genericside><span class="t11bw">Your email address and password will be used to logon as a WOW! Member.</span></td> </tr> <tr> <td align="right"><span class="t11br">*</span> Email Address: (this will also be used as your username)</td> <td> <input class="byp" type="text" name="email" size="30" maxlength="50" value="<?php $email;?>"> </td> </tr> <tr> <td align="right"><span class="t11br">*</span> Password: (must be at least 5 characters long)</td> <td> <input class="byp" type="password" name="password" size="20" maxlength="20" value="<?php $password;?>"> </td> </tr> <tr> <td align="right"><span class="t11br">*</span> Password Retyped: (To ensure correct typed entry)</td> <td> <input class="byp" type="password" name="password2" size="20" maxlength="20" value="<?php $password2;?>"> </td> </tr> <tr> <td colspan="2"><input type="hidden" name="register" value="true"></td> </tr> <tr> <td colspan="2"><img src="http://images-cache.cd-wow.com/images/bluepix.gif" width="100%" height="1"></td> </tr> <tr><td> </td> <td><input type="submit" type="submit" value="Sign Me Up! »"></td> </tr> </form> Quote Link to comment https://forums.phpfreaks.com/topic/99933-solved-variables-not-passing-to-database/ Share on other sites More sharing options...
zenag Posted April 7, 2008 Share Posted April 7, 2008 u have not assigned $Brthday, $Birthmonth, $Bithyear, $password2, $name & $country values ..checkout that... Quote Link to comment https://forums.phpfreaks.com/topic/99933-solved-variables-not-passing-to-database/#findComment-510988 Share on other sites More sharing options...
mikebyrne Posted April 7, 2008 Author Share Posted April 7, 2008 u have not assigned $Brthday, $Birthmonth, $Bithyear, $password2, $name & $country values ..checkout that... I cant see how they are not assigned??? Quote Link to comment https://forums.phpfreaks.com/topic/99933-solved-variables-not-passing-to-database/#findComment-511031 Share on other sites More sharing options...
Cep Posted April 7, 2008 Share Posted April 7, 2008 This line, $sql="INSERT INTO $tbl_name(name, address, address1, address2, address3, county, country, birthday, birthmonth, birthyear, zip, telephone, email, username, password, password2, usertype)VALUES('$name', '$address', '$address1', '$address2','$address3', '$county' , '$country','$birthday', '$birthmonth', '$birthyear','$zip', '$telephone', '$email', '$username', '$password' , '$password2', 1)"; Refers to variables that you have not set, PHP cannot understand what they are. Quote Link to comment https://forums.phpfreaks.com/topic/99933-solved-variables-not-passing-to-database/#findComment-511036 Share on other sites More sharing options...
mikebyrne Posted April 7, 2008 Author Share Posted April 7, 2008 Sorry think im missing something here ??? They ALL post apart from $Brthday, $Birthmonth, $Bithyear, $password2, $name & $country They echo on the screen too so cant see why they wont go into the db?? Quote Link to comment https://forums.phpfreaks.com/topic/99933-solved-variables-not-passing-to-database/#findComment-511039 Share on other sites More sharing options...
Cep Posted April 7, 2008 Share Posted April 7, 2008 This, $birthday is not $_POST['birthday'] they are two separate entities. Quote Link to comment https://forums.phpfreaks.com/topic/99933-solved-variables-not-passing-to-database/#findComment-511041 Share on other sites More sharing options...
mikebyrne Posted April 7, 2008 Author Share Posted April 7, 2008 Ah ok. So what should I do to get birthday to post to the database? Quote Link to comment https://forums.phpfreaks.com/topic/99933-solved-variables-not-passing-to-database/#findComment-511042 Share on other sites More sharing options...
Cep Posted April 7, 2008 Share Posted April 7, 2008 You have to assign it, $birthday = "something"; This goes for all the other variables you have not assigned. Looking at your code they are going to be something like this, $birthday = mysql_real_escape_string(trim($_POST['birthday'])); Quote Link to comment https://forums.phpfreaks.com/topic/99933-solved-variables-not-passing-to-database/#findComment-511044 Share on other sites More sharing options...
mikebyrne Posted April 7, 2008 Author Share Posted April 7, 2008 Ive used: $birthday = mysql_real_escape_string(trim($_POST['birthday'])); $birthmonth = mysql_real_escape_string(trim($_POST['birthmonth'])); $birthyear = mysql_real_escape_string(trim($_POST['birthyear'])); Everything posts apart from from birthday!! Quote Link to comment https://forums.phpfreaks.com/topic/99933-solved-variables-not-passing-to-database/#findComment-511047 Share on other sites More sharing options...
New Coder Posted April 7, 2008 Share Posted April 7, 2008 You are using birthdate further up your code which you are then refering to as birthday... Syntax?? change $birthday = mysql_real_escape_string(trim($_POST['birthday'])); to $birthday = mysql_real_escape_string(trim($_POST['birthdate'])); Quote Link to comment https://forums.phpfreaks.com/topic/99933-solved-variables-not-passing-to-database/#findComment-511048 Share on other sites More sharing options...
mikebyrne Posted April 7, 2008 Author Share Posted April 7, 2008 Thats fixed it. Thanks alot!! Quote Link to comment https://forums.phpfreaks.com/topic/99933-solved-variables-not-passing-to-database/#findComment-511186 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.