4 Replies - 462 Views - Last Post: 11 June 2010 - 08:12 AM Rate Topic: -----

#1 Brewer  Icon User is offline

  • Awesome
  • member icon

Reputation: 179
  • View blog
  • Posts: 1,044
  • Joined: 14-June 10

Error With Registration

Posted 11 June 2010 - 07:18 AM

The problem I am having is that I receive the "Error: User not added to database." error when I submit. I think the error might be with $q but if it is then I can't find it.

Please help? :) I'm nub.

<?php

        // dbConfig.php is a file that contains your
        // database connection information. This
        // tutorial assumes a connection is made from
        // this existing file.
        include ("dbConfig.php");


//Input vaildation and the dbase code
        if ( $_GET["op"] == "reg" )
  {
  $bInputFlag = false;
  foreach ( $_POST as $field )
        {
        if ($field == "")
    {
    $bInputFlag = false;
    }
        else
    {
    $bInputFlag = true;
    }
        }
  // If we had problems with the input, exit with error
  if ($bInputFlag == false)
        {
        die( "Problem with your registration info. "
    ."Please go back and try again.");
        }

  // Fields are clear, add user to database
  //  Setup query
  $q = "INSERT INTO `dbUsers` (`username`,`password`,`email`,`firstname`,`lastname`,`birthmonth`,`birthday`,`birthyear`,`country`,`state`,`city`) "
        ."VALUES ('".$_POST["username"]."', "
        ."PASSWORD('".$_POST["password"]."'), "
        ."'".$_POST["email"]."'), "
		."'".$_POST["firstname"]."'), "
		."'".$_POST["lastname"]."'), "
		."'".$_POST["birthmonth"]."'), "
		."'".$_POST["birthday"]."'), "
		."'".$_POST["birthyear"]."'), "
		."'".$_POST["country"]."'), "
		."'".$_POST["state"]."'), "
		."'".$_POST["city"]."')";
  //  Run query
  $r = mysql_query($q);
  
  // Make sure query inserted user successfully
  if ( !$r )
        {
        die("Error: User not added to database.");
        }
  else
        {
        // Redirect to thank you page.
        Header("Location: register.php?op=thanks");
        }
  } // end if


//The thank you page
        elseif ( $_GET["op"] == "thanks" )
  {
  echo "<h2>Thanks for registering!</h2>";
  echo "<a href='index.php'>Return Home</a>";
  }
  
  ?>

<html>
<head>
<title>Seventh Life | Register</title>
</head>

<body>
<form action="?op=reg" method="POST">
Username: <input name="username" MAXLENGTH="16"><br />
Password: <input type="password" name="password" MAXLENGTH="16"><br />
E-mail Address: <input name="email" MAXLENGTH="50"><br />
<br />
First Name: <input name="firstname" MAXLENGTH="30"><br />
Last Name: <input name="lastname" MAXLENGTH="30"><br />
Birthday: <select name="birthmonth">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="birthday">
<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 name="birthyear"><br />
<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>
<option value="1930">1930</option>
<option value="1929">1929</option>
<option value="1928">1928</option>
<option value="1927">1927</option>
<option value="1926">1926</option>
<option value="1925">1925</option>
<option value="1924">1924</option>
<option value="1923">1923</option>
<option value="1922">1922</option>
<option value="1921">1921</option>
<option value="1920">1920</option>
<option value="1919">1919</option>
<option value="1918">1918</option>
<option value="1917">1917</option>
<option value="1916">1916</option>
<option value="1915">1915</option>
<option value="1914">1914</option>
<option value="1913">1913</option>
<option value="1912">1912</option>
<option value="1911">1911</option>
<option value="1910">1910</option>
<option value="1909">1909</option>
<option value="1908">1908</option>
<option value="1907">1907</option>
<option value="1906">1906</option>
<option value="1905">1905</option>
<option value="1904">1904</option>
<option value="1903">1903</option>
<option value="1902">1902</option>
<option value="1901">1901</option>
<option value="1900">1900</option>
</select><br /><br />
Country: <select name="country">
           <option value="Afghanistan" selected="selected">Afghanistan</option>
           <option value="Albania">Albania</option>
           <option value="Algeria">Algeria</option>
           <option value="Andorra">Andorra</option>
           <option value="Angola">Angola</option>
           <option value="Antigua & Deps">Antigua & Deps</option>
           <option value="Argentina">Argentina</option>
           <option value="Armenia">Armenia</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="Bhutan">Bhutan</option>
           <option value="Bolivia">Bolivia</option>
           <option value="Bosnia">Bosnia</option>
           <option value="Herzegovina">Herzegovina</option>
           <option value="Botswana">Botswana</option>
           <option value="Brazil">Brazil</option>
           <option value="Brunei">Brunei</option>
           <option value="Bulgaria">Bulgaria</option>
           <option value="Burkina">Burkina</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 Central">Cape Verde Central</option>
           <option value="African Rep">African Rep</option>
           <option value="Chad">Chad</option>
           <option value="Chile">Chile</option>
           <option value="China">China</option>
           <option value="Colombia">Colombia</option>
           <option value="Comoros Congo">Comoros Congo</option>
           <option value="Congo {Democratic Rep}">Congo {Democratic Rep}</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="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="Fiji">Fiji</option>
           <option value="Finland">Finland</option>
           <option value="France">France</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="Greece">Greece</option>
           <option value="Grenada">Grenada</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="Hait">Hait</option>
           <option value="Honduras"> Honduras</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 {Republic}">Ireland {Republic}</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="Korea">Korea</option>
           <option value="North Korea">North Korea</option>
           <option value="South Kosovo">South Kosovo</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="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 Marshall Islands">Malta Marshall Islands</option>
           <option value="Mauritania">Mauritania</option>
           <option value="Mauritius">Mauritius</option>
           <option value="Mexico">Mexico</option>
           <option value="Micronesia">Micronesia</option>
           <option value="Moldova">Moldova</option>
           <option value="Monaco">Monaco</option>
           <option value="Mongolia">Mongolia</option>
           <option value="Montenegro">Montenegro</option>
           <option value="Morocco">Morocco</option>
           <option value="Mozambique">Mozambique</option>
           <option value="Myanmar, {Burma}">Myanmar, {Burma}</option>
           <option value="Namibia">Namibia</option>
           <option value="Nauru">Nauru</option>
           <option value="Nepal">Nepal</option>
           <option value="Netherlands">Netherlands</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="Norway">Norway</option>
           <option value="Oman">Oman</option>
           <option value="Pakistan">Pakistan</option>
           <option value="Palau">Palau</option>
           <option value="Panama">Panama</option>
           <option value="Papua">Papua</option>
           <option value="New Guinea">New Guinea</option>
           <option value="Paraguay">Paraguay</option>
           <option value="Peru">Peru</option>
           <option value="Philippines">Philippines</option>
           <option value="Poland">Poland</option>
           <option value="Portugal">Portugal</option>
           <option value="Qatar">Qatar</option>
           <option value="Romania">Romania</option>
           <option value="Russian Federation">Russian Federation</option>
           <option value="Rwanda">Rwanda</option>
           <option value="St Kitts & Nevis">St Kitts & Nevis</option>
           <option value="St Lucia">St Lucia</option>
           <option value="Saint Vincent & the Grenadines Samoa">Saint Vincent & the Grenadines Samoa</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 Sudan">Sri Lanka 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="TaiwanTajikistan">TaiwanTajikistan</option>
           <option value="Tanzania">Tanzania</option>
           <option value="Thailand">Thailand</option>
           <option value="Togo">Togo</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="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="Uruguay">Uruguay</option>
           <option value="Uzbekistan">Uzbekistan</option>
           <option value="Vanuatu">Vanuatu</option>
           <option value="Vatican City">Vatican City</option>
           <option value="Venezuela">Venezuela</option>
           <option value="Vietnam">Vietnam</option>
           <option value="Yemen">Yemen</option>
           <option value="Zambia">Zambia</option>
           <option value="Zimbabwe">Zimbabwe</option>
         </select><br />
State/Province: <input name="state" MAXLENGTH="30"><br />
City: <input name="city" MAXLENGTH="30"><br /><br />
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>


Is This A Good Question/Topic? 0
  • +

Replies To: Error With Registration

#2 Denis1  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 102
  • Joined: 29-July 09

Re: Error With Registration

Posted 11 June 2010 - 07:32 AM

Make sure you have all the mysql fields. in your database check to see if you have all the
(`username`,`password`,`email`,`firstname`,`lastname`,`birthmonth`,`birthday`,`birthyear`,`country`,`state`,`city`) 
fields. If you dont have them add them.

Your are getting the error because the users details isnt added to the mysql database.
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6052
  • View blog
  • Posts: 23,487
  • Joined: 23-August 08

Re: Error With Registration

Posted 11 June 2010 - 07:32 AM

Well you might try printing mysql_error().

Also, have you heard of SQL injection? You should read about it, and be doing something about it while you're still getting started.
Was This Post Helpful? 1
  • +
  • -

#4 mahcuz  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 143
  • View blog
  • Posts: 213
  • Joined: 03-June 10

Re: Error With Registration

Posted 11 June 2010 - 07:33 AM

Check out the mysql_error() function for more details on *why* your query failed.

http://php.net/mysql_error

Edit: too late ><

This post has been edited by mahcuz: 11 June 2010 - 07:33 AM

Was This Post Helpful? 1
  • +
  • -

#5 Brewer  Icon User is offline

  • Awesome
  • member icon

Reputation: 179
  • View blog
  • Posts: 1,044
  • Joined: 14-June 10

Re: Error With Registration

Posted 11 June 2010 - 08:12 AM

Thanks for the mysql_error() link! It took me two seconds to figure out the problem! I had a bunch of ")" that shouldn't have been there!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1