Registration: Part 6 - Image Upload Series. [SOLVED]

The place to be if you need help with any phpacademy tutorials.

Registration: Part 6 - Image Upload Series. [SOLVED]

Postby BlakeRey » Thu Jul 29, 2010 9:18 am

Hey!

I am a little confused as to why this isn't working, everything seems to be okay, I can connect to the database, but it won't insert the data into the database.

Here is my code:
  1.  
  2. <?php
  3. session_start();
  4.  
  5. require("connect.php");
  6.  
  7. if($_POST['submit'])
  8. {
  9.  
  10.     $firstname =        $_POST['firstname'];
  11.     $lastname =         $_POST['lastname'];
  12.     $username =         $_POST['username'];
  13.     $password =         $_POST['password'];
  14.     $conf_password =    $_POST['conf_password'];
  15.     $dob_year =         $_POST['dob_year'];
  16.     $dob_month =        $_POST['dob_month'];
  17.     $dob_day =          $_POST['dob_day'];
  18.     $gender =           $_POST['gender'];
  19.     $email =            $_POST['email'];
  20.    
  21.     if(
  22.     $firstname&&
  23.     $lastname&&
  24.     $username&&
  25.     $password&&
  26.     $conf_password&&
  27.     $dob_year&&
  28.     $dob_month&&
  29.     $dob_day&&
  30.     $gender&&
  31.     $email)
  32.     {
  33.        
  34.         if(strlen($firstname)>25 || strlen($lastname)>25 || strlen($username)>25 ) {
  35.             echo "<center><div class='errorreg'>Firstname, Lastname and username must be no more than 25 charatcers.</div></center>";
  36.         }
  37.         else {
  38.        
  39.             if(strlen($password)>25||strlen($password)<6)
  40.             echo "<center><div class='errorreg'>Password must be between 6 and 25 characters</div></center><br />";
  41.             else
  42.             {
  43.            
  44.                 if(is_numeric($dob_year)&&is_numeric($dob_month)&&is_numeric($dob_day))
  45.                 {
  46.                    
  47.                     if(strlen($dob_year)>4||strlen($dob_month)<2||strlen($dob_year)<2){
  48.                         echo "<center><div class='errorreg'>Date of birth year must be 4 characters, month and day must be 2</div></center><br />";
  49.                     }
  50.                     else {
  51.                    
  52.                         if ($gender=="Male"||$gender="Female")
  53.                         {
  54.                            
  55.                             if($password==$conf_password){
  56.                                
  57.                                 if($dob_month>12||$dob_day>31)
  58.                                 echo "<center><div class='errorreg'>Date of birth is incorrect value!</div></center>";
  59.                                
  60.                                 $query = mysql_query("SELECT * from users WHERE username='$username'");
  61.                                 if (mysql_num_rows($query)>=1)
  62.                                 echo "<center><div class='errorreg'>Sorry, the username, ".$username." is already taken.</div></center><br />";
  63.                                 else {
  64.                                     $dob_db = "$dob_year-$dob_month-$dob_day";
  65.                                     $password_db = md5($password);
  66.                                     $register = mysql_query("INSERT INTO users VALUES ('','$firstname','$lastname','$username','$password_db','$email','$dob_db','$gender')");
  67.                                     echo "<center><div class='comreg'>
  68.                                     Thank you for registering. You may now log into your account.</div></center><br />";
  69.                                 }
  70.                                
  71.                             }
  72.                             else {
  73.                                 echo "<center><div class='errorreg'>Passwords do not match</div></center>";
  74.                             }
  75.                            
  76.                         }
  77.                         else {
  78.                             echo "<center><div class='errorreg'>Gender must be Male or Female</div></center>";                         
  79.                         }
  80.                        
  81.                     }
  82.                 }
  83.                 else {
  84.                     echo "<center><div class='errorreg'>Date of birth must be in number form.</div></center>"
  85.                 }
  86.                
  87.             }
  88.         }
  89.        
  90.        
  91.     } else {
  92.         echo "<center><div class='errorreg'>Oops! Something went wrong, please make sure you filled in all the fields.</div></center><br />";
  93.     }
  94.            
  95. }
  96.  
  97. ?>
  98.  
  99.  


I'd appreciate some help on this, thanks! :)
Last edited by BlakeRey on Fri Jul 30, 2010 2:26 pm, edited 2 times in total.
BlakeRey
 
Posts: 3
Joined: Mon Jul 26, 2010 2:40 am
Online: 45m 16s
Karma: 0

Re: Registration: Part 6 - Image Upload Series. [SOLVED]

Advertisment

Advertisment
 

Re: Registration: Part 6 - Image Upload Series.

Postby wide_load » Thu Jul 29, 2010 9:53 am

if you add



after the offending query, does it show anything up ?
Image
User avatar
wide_load
Top Contributor
 
Posts: 5375
Joined: Thu Aug 13, 2009 1:04 pm
Online: 12d 14h 21m 3s
Karma: 43

Re: Registration: Part 6 - Image Upload Series.

Postby libeco » Thu Jul 29, 2010 9:54 am

Add...
  1. or die(mysql_error())

behind your queries to see if they throw an error.
Common PHP/MySQL errors | How to display code on the forum
"It always seems impossible until its done." - Nelson Mandela
User avatar
libeco
Moderator
 
Posts: 2456
Joined: Fri Apr 24, 2009 9:03 pm
Location: Netherlands
Online: 5d 7h 42m 55s
Karma: 25

Re: Registration: Part 6 - Image Upload Series.

Postby wide_load » Thu Jul 29, 2010 9:57 am

libeco wrote:Add...
  1. or die(mysql_error())

behind your queries to see if they throw an error.

wide_load wrote:if you add



after the offending query, does it show anything up ?


looks like we are on the same track...
Image
User avatar
wide_load
Top Contributor
 
Posts: 5375
Joined: Thu Aug 13, 2009 1:04 pm
Online: 12d 14h 21m 3s
Karma: 43

Re: Registration: Part 6 - Image Upload Series.

Postby libeco » Thu Jul 29, 2010 10:00 am

LOL :lol:

I find for debugging I like die better because it will not go further with the rest of the script. But ofcourse it's a matter of preference. :mrgreen:
Common PHP/MySQL errors | How to display code on the forum
"It always seems impossible until its done." - Nelson Mandela
User avatar
libeco
Moderator
 
Posts: 2456
Joined: Fri Apr 24, 2009 9:03 pm
Location: Netherlands
Online: 5d 7h 42m 55s
Karma: 25

Re: Registration: Part 6 - Image Upload Series.

Postby wide_load » Thu Jul 29, 2010 10:02 am

the only reason that i don't do that is that in the past dropping the rest of the page has broken the layout so much that the error has been hidden :lol:
Image
User avatar
wide_load
Top Contributor
 
Posts: 5375
Joined: Thu Aug 13, 2009 1:04 pm
Online: 12d 14h 21m 3s
Karma: 43

Re: Registration: Part 6 - Image Upload Series.

Postby BlakeRey » Fri Jul 30, 2010 2:32 am

Hey guys, thanks for the help, didn't even realise to echo out the SQL error.

It returns
  1.  
  2. Column count doesn't match value count at row 1
  3.  


I changed my query from
  1. $register = mysql_query("INSERT INTO users VALUES ('id','$firstname','$lastname','$username','$password_db','$email','$dob_db','$gender')");

to
  1. mysql_query("INSERT into users (id, firstname, lastname, username, password, email, dob, gender, admin)
  2.                                     VALUES ('id','$firstname','$lastname','$username','$password_db','$email','$dob_db','$gender','0')");


and it worked fine :)
BlakeRey
 
Posts: 3
Joined: Mon Jul 26, 2010 2:40 am
Online: 45m 16s
Karma: 0

Re: Registration: Part 6 - Image Upload Series.

Postby bowersbros » Fri Jul 30, 2010 7:58 am

can i mention inserting 'id' into your id field really wont be helpful, if its autoincrement leave it blank '' that way it will do it automatically :P
The early bird catches the worm but the second mouse gets the cheese!

If you look like your passport picture, you probably need the trip.

---

IM contact details:
Example doesnt work, requires a href
bowersbros
Top Contributor
 
Posts: 2006
Joined: Tue Apr 21, 2009 7:55 pm
Location: United Kingdom
Online: 4d 3h 12m 20s
Karma: 6

Re: Registration: Part 6 - Image Upload Series.

Postby BlakeRey » Fri Jul 30, 2010 2:25 pm

bowersbros wrote:can i mention inserting 'id' into your id field really wont be helpful, if its autoincrement leave it blank '' that way it will do it automatically :P


Okie dokie! :) - I thought I left it blank, obviously not! Yeah, my id field is set to Auto Increment. :)

Thanks for the help guys!

- Blake!
BlakeRey
 
Posts: 3
Joined: Mon Jul 26, 2010 2:40 am
Online: 45m 16s
Karma: 0


Return to Tutorial Help

Who's online?

Users browsing this forum: No registered users and 1 guest