942,526 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 1016
  • MySQL RSS
Feb 26th, 2010
0

INSERT INTO will not insert

Expand Post »
I created a user login/registration system and the login works fine. But I can not seem to get the registration to insert the info into the database. It returns no errors and says the record is there but when you check from phpMyAdmin, the record is not there.

Here is the register.php page:
MySQL Syntax (Toggle Plain Text)
  1. <?php
  2. // STARTING a session
  3. session_start();
  4. // Checks if there IS SET a session
  5. if (!isset($_SESSION['user']))
  6. {
  7. // if a session has NOT SET, THEN don't give access
  8. } else {
  9. // if a session has been set, then give access.
  10. echo "<meta http-equiv=\"refresh\" content=\"0;url=index2.php\" />";
  11. }
  12. ?>
  13.  
  14. <?php require_once("includes/connection.php"); ?>
  15. <?php require_once("includes/functions.php"); ?>
  16. <?php include("includes/header.php"); ?>
  17. <?php include("includes/nav.php"); ?>
  18. <?php include("includes/upper_content.php"); ?>
  19. <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
  20. <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
  21.  
  22.  
  23. <div id="main_body">
  24. <table width="936" align="center" cellpadding="10">
  25. <tr>
  26. <td align="center"><!-- ########## START MAIN CONTENT HERE ########## -->
  27. <fieldset>
  28. <legend>Create a Free Account</legend>
  29. <form action="newreg.php" method="post" >
  30. <p>Choose A Username:<br />
  31. <span id="spry_first_name">
  32. <input type="text" name="username" value="" size="36" /><br />
  33. <span class="textfieldRequiredMsg">A value is required.</span>
  34. </span>
  35. </p>
  36.  
  37. <p>First Name:<br />
  38. <span id="spry_first_name"><span id="sprytextfield7">
  39. <input type="text" name="first_name" value="" size="36" />
  40. <span class="textfieldRequiredMsg">A value is required.</span> <span class="textfieldMinCharsMsg">Minimum number of characters not met.(6)</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.(30)</span></span>
  41. </p>
  42.  
  43. <p>Last Name:<br />
  44. <span id="spry_last_name">
  45. <input type="text" name="last_name" value="" size="36" /><br />
  46. <span class="textfieldRequiredMsg">A value is required.</span>
  47. </span>
  48. </p>
  49.  
  50. <p>Email:<br />
  51. <span id="spry_email">
  52. <input type="text" name="email" value="" size="36" /><br />
  53. <span class="textfieldRequiredMsg">A value is required.</span><br />
  54. <span class="textfieldInvalidFormatMsg">Invalid format.</span>
  55. </span>
  56. </p>
  57. <span id="spry_password">
  58.  
  59. <label>Password:<br />
  60. <input type="password" name="password2" id="password" size="36" /><br />
  61. </label>
  62. <span class="passwordRequiredMsg">A value is required.</span><br />
  63. <br />
  64. <span class="passwordMinCharsMsg">Minimum number of characters not met. (6)</span><br />
  65. <span class="passwordMaxCharsMsg">Exceeded maximum number of characters. (30)</span>
  66. </span>
  67.  
  68. <p>Confirm Password:<br />
  69. <span id="spry_password_confirm">
  70. <input type="password" name="password3" value="" size="36" /><br />
  71. <span class="confirmRequiredMsg">A value is required.</span><br />
  72. <span class="confirmInvalidMsg">The values don't MATCH.</span>
  73. </span>
  74. </p>
  75.  
  76. <p>Street Address:<br />
  77. <span id="spry_street_address">
  78. <input type="text" name="street_address" value="" size="36" /><br />
  79. <span class="textfieldRequiredMsg">A value IS required.</span></span></p>
  80.  
  81. <p>Apartment Number:<br />
  82. <input type="text" name="apt_number" value="" size="36" />
  83. </p>
  84.  
  85. <p>City:<br />
  86. <span id="spry_city">
  87. <input type="text" name="city" value="" size="36" /><br />
  88. <span class="textfieldRequiredMsg">A value IS required.</span></span></p>
  89.  
  90. <p>State:<br />
  91. <span id="spry_state">
  92. <select name="state" id="state">
  93. <option selected="selected">Select...</option>
  94. <option value="AL">Alabama</option>
  95. <option value="AK">Alaska</option>
  96. <option value="AZ">Arizona</option>
  97. <option value="AR">Arkansas</option>
  98. <option value="CA">California</option>
  99. <option value="CO">Colorado</option>
  100. <option value="CT">Connecticut</option>
  101. <option value="DE">Delaware</option>
  102. <option value="DC">District Of Columbia</option>
  103. <option value="FL">Florida</option>
  104. <option value="GA">Georgia</option>
  105. <option value="HI">Hawaii</option>
  106. <option value="ID">Idaho</option>
  107. <option value="IL">Illinois</option>
  108. <option value="IN">Indiana</option>
  109. <option value="IA">Iowa</option>
  110. <option value="KS">Kansas</option>
  111. <option value="KY">Kentucky</option>
  112. <option value="LA">Louisiana</option>
  113. <option value="ME">Maine</option>
  114. <option value="MD">Maryland</option>
  115. <option value="MA">Massachusetts</option>
  116. <option value="MI">Michigan</option>
  117. <option value="MN">Minnesota</option>
  118. <option value="MS">Mississippi</option>
  119. <option value="MO">Missouri</option>
  120. <option value="MT">Montana</option>
  121. <option value="NE">Nebraska</option>
  122. <option value="NV">Nevada</option>
  123. <option value="NH">New Hampshire</option>
  124. <option value="NJ">New Jersey</option>
  125. <option value="NM">New Mexico</option>
  126. <option value="NY">New York</option>
  127. <option value="NC">North Carolina</option>
  128. <option value="ND">North Dakota</option>
  129. <option value="OH">Ohio</option>
  130. <option value="OK">Oklahoma</option>
  131. <option value="OR">Oregon</option>
  132. <option value="PA">Pennsylvania</option>
  133. <option value="RI">Rhode Island</option>
  134. <option value="SC">South Carolina</option>
  135. <option value="SD">South Dakota</option>
  136. <option value="TN">Tennessee</option>
  137. <option value="TX">Texas</option>
  138. <option value="UT">Utah</option>
  139. <option value="VT">Vermont</option>
  140. <option value="VA">Virginia</option>
  141. <option value="WA">Washington</option>
  142. <option value="WV">West Virginia</option>
  143. <option value="WI">Wisconsin</option>
  144. <option value="WY">Wyoming</option>
  145. </select><br />
  146. <span class="selectRequiredMsg">Please SELECT an item.</span></span></p>
  147.  
  148. <p>Zip Code:<br />
  149. <span id="spry_zip_code">
  150. <input type="text" name="zip_code" value="" size="36" maxlength="10" /><br />
  151. <span class="textfieldRequiredMsg">A value IS required.</span><br />
  152. <span class="textfieldInvalidFormatMsg">Invalid FORMAT.</span></span></p>
  153.  
  154. <p>Date of Birth (Must be at least 18):<br />
  155. <br />Format: MM/DD/YYYY<br />
  156. <span id="spry_birthday">
  157. <input type="text" name="birthday" value="" size="36" /><br />
  158. <span class="textfieldRequiredMsg">A value IS required.</span><br />
  159. <span class="textfieldInvalidFormatMsg">Invalid FORMAT.</span></span></p>
  160.  
  161. <p>
  162. <input type="submit" value="Submit Registration" />
  163. </p>
  164.  
  165. </form>
  166.  
  167. <script type="text/javascript">
  168. <!--
  169. var sprytextfield1 = new Spry.Widget.ValidationTextField("spry_first_name", "none", {validateOn:["blur"], minChars:6, maxChars:30});
  170. var sprytextfield2 = new Spry.Widget.ValidationTextField("spry_last_name", "none", {validateOn:["blur"]});
  171. var sprytextfield3 = new Spry.Widget.ValidationTextField("spry_email", "email", {validateOn:["blur"], hint:"username@server.tld"});
  172. var sprypassword1 = new Spry.Widget.ValidationPassword("spry_password", {validateOn:["blur"], minChars:6, maxChars:30});
  173. var spryconfirm1 = new Spry.Widget.ValidationConfirm("spry_password_confirm", "password", {validateOn:["blur"]});
  174. var sprytextfield4 = new Spry.Widget.ValidationTextField("spry_street_address", "none", {validateOn:["blur"], hint:"Your home address."});
  175. var sprytextfield5 = new Spry.Widget.ValidationTextField("spry_city", "none", {validateOn:["blur"], hint:"The city you live in."});
  176. var spryselect1 = new Spry.Widget.ValidationSelect("spry_state", {validateOn:["blur"]});
  177. var sprytextfield6 = new Spry.Widget.ValidationTextField("spry_zip_code", "zip_code", {validateOn:["blur"], hint:"Your 5 digit zip code."});
  178. var sprytextfield8 = new Spry.Widget.ValidationTextField("spry_birthday", "custom", {validateOn:["blur"]});
  179. //-->
  180. </script>
  181. </fieldset>
  182. <!-- ########## END MAIN CONTENT HERE ########## --></td>
  183. </tr>
  184. </table>
  185. <?php include("includes/footer.php"); ?>
  186. <?php ob_flush(); ?>
  187. <script type="text/javascript">
  188. <!--
  189. var sprytextfield7 = new Spry.Widget.ValidationTextField("sprytextfield7", "none", {validateOn:["blur"]});
  190. //-->
  191. </script>


Here is the newreg.php page:
MySQL Syntax (Toggle Plain Text)
  1. <?php
  2. require_once("includes/connection.php");
  3. require_once("includes/functions.php");
  4.  
  5. $username = $_POST['username'];
  6. $first_name = $_POST['first_name'];
  7. $last_name = $_POST['last_name'];
  8. $email = $_POST['email'];
  9. $birthday = $_POST['birthday'];
  10. $street_address = $_POST['street_address'];
  11. $apt_number = $_POST['apt_number'];
  12. $city = $_POST['city'];
  13. $state = $_POST['state'];
  14. $zip_code = $_POST['zip_code'];
  15. $password = $_POST['password'];
  16.  
  17. $result = mysql_num_rows(mysql_query("SELECT * FROM iin_users WHERE username='$username'"));
  18.  
  19. if($result == 1)
  20. {
  21. echo "<center><h1>ERROR!</h1>The username you have chosen already exists!<br /><br /><a href=\"register.php\">Go Back</a></center>";
  22. }
  23. ELSE
  24. {
  25.  
  26. //Get MD5 HASH of password
  27. $password = MD5($password);
  28.  
  29. mysql_query("INSERT INTO iin_users (username, first_name, last_name, email, birthday, street_address, apt_number, city, state, zip_code, password)
  30. VALUES ( '$username', '$first_name, '$last_name', '$email', '$birthday', '$street_address', '$apt_number', '$city', '$state', '$zip_code', '$password')");
  31.  
  32. echo "<p>Congratulations! You have successfully registered!</p><p>Click <a href=\"login.php\">here</a> to login.</p>";
  33. }
  34. ?>

Like I said, no errors unless the username is the one that is the default entry I made which is wickidgrafx. Then it tells me the username is taken. But if I use a different username, it says everything is ok and tells me to login.

Please help me. Thanks, Jason.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
WickidGRAFX is offline Offline
24 posts
since Feb 2010
Mar 9th, 2010
0

reserved word?

The same thing happened to me about a year ago. I'm fairly certain my problem was that I was using a reserved mysql word as a field name in my table. Even though the field name didn't show up in the insert code, so no error was thrown. I was using a field named 'order' and of course I nearly pulled my hair out before I realized it! Check out this reserved word list and see if you are using any. If you are change the field name and see if your problem is fixed. Keep us posted.

-Level
Reputation Points: 10
Solved Threads: 1
Newbie Poster
AOlevel1 is offline Offline
5 posts
since Nov 2007
Mar 9th, 2010
0
Re: INSERT INTO will not insert
The likeliest reason you see no error is because you are not asking to see any errors...

so alter the end of your query code
MySQL Syntax (Toggle Plain Text)
  1.  
  2. mysql_query("INSERT INTO iin_users (username, first_name, last_name, email, birthday, street_address, apt_number, city, state, zip_code, password)
  3.  
  4. VALUES ( '$username', '$first_name, '$last_name', '$email', '$birthday', '$street_address', '$apt_number', '$city', '$state', '$zip_code', '$password')") OR die ("This bit didn't work"). mysql_error();
When you get it working it is often suggested you should remove any error reprots as it might help hackers.
Reputation Points: 76
Solved Threads: 77
Posting Pro in Training
drjohn is offline Offline
422 posts
since Mar 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: How can I get my content to my APache without cPanel?
Next Thread in MySQL Forum Timeline: You have an error in your SQL syntax





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC