Data not going into my database??! plz help

Reply

Join Date: Mar 2009
Posts: 2
Reputation: lildaddyha is an unknown quantity at this point 
Solved Threads: 0
lildaddyha lildaddyha is offline Offline
Newbie Poster

Data not going into my database??! plz help

 
0
  #1
Mar 25th, 2009
Hello,

I have a login/registration script thats altered to correspond with my database. It includes the login, logout, change password, email validation, etc. I have it setup pretty well however, when I hit submit, the information doesn't go into my database. I get the error message "Data Missing" which comes the activate.php. I check my query line over and over but I have been stuck for 3 days now. Can someone help me please? Heres the code/information:

________________________
My MYSQL DATABASE
________________________

  1. CREATE TABLE IF NOT EXISTS `users` (
  2. `id` INT(11) NOT NULL AUTO_INCREMENT,
  3. `first_name` VARCHAR(20) COLLATE utf8_unicode_ci NOT NULL,
  4. `last_name` VARCHAR(20) COLLATE utf8_unicode_ci NOT NULL,
  5. `address` VARCHAR(60) COLLATE utf8_unicode_ci NOT NULL,
  6. `city` VARCHAR(30) COLLATE utf8_unicode_ci NOT NULL,
  7. `state` VARCHAR(30) COLLATE utf8_unicode_ci NOT NULL,
  8. `zip_code` INT(10) NOT NULL,
  9. `birth_month` VARCHAR(20) COLLATE utf8_unicode_ci NOT NULL,
  10. `birth_day` VARCHAR(2) COLLATE utf8_unicode_ci NOT NULL,
  11. `birth_year` VARCHAR(4) COLLATE utf8_unicode_ci NOT NULL,
  12. `phone` VARCHAR(20) COLLATE utf8_unicode_ci NOT NULL,
  13. `email` VARCHAR(75) COLLATE utf8_unicode_ci NOT NULL,
  14. `username` VARCHAR(25) COLLATE utf8_unicode_ci NOT NULL,
  15. `password` VARCHAR(25) COLLATE utf8_unicode_ci NOT NULL,
  16. `security_question` VARCHAR(60) COLLATE utf8_unicode_ci NOT NULL,
  17. `security_answer` VARCHAR(60) COLLATE utf8_unicode_ci NOT NULL,
  18. `stage_name` VARCHAR(30) COLLATE utf8_unicode_ci NOT NULL,
  19. `ad_phone` VARCHAR(20) COLLATE utf8_unicode_ci NOT NULL,
  20. `ad_phone2` VARCHAR(20) COLLATE utf8_unicode_ci NOT NULL,
  21. `gender` VARCHAR(20) COLLATE utf8_unicode_ci NOT NULL,
  22. `sexuality` VARCHAR(30) COLLATE utf8_unicode_ci NOT NULL,
  23. `age` INT(3) NOT NULL,
  24. `height` VARCHAR(5) COLLATE utf8_unicode_ci NOT NULL,
  25. `weight` VARCHAR(8) COLLATE utf8_unicode_ci NOT NULL,
  26. `hair` VARCHAR(10) COLLATE utf8_unicode_ci NOT NULL,
  27. `eye` VARCHAR(10) COLLATE utf8_unicode_ci NOT NULL,
  28. `ethnicity` VARCHAR(30) COLLATE utf8_unicode_ci NOT NULL,
  29. `available` VARCHAR(30) COLLATE utf8_unicode_ci NOT NULL,
  30. `ad_location` VARCHAR(60) COLLATE utf8_unicode_ci NOT NULL,
  31. `ad_type` VARCHAR(20) COLLATE utf8_unicode_ci NOT NULL,
  32. `call_type` VARCHAR(40) COLLATE utf8_unicode_ci NOT NULL,
  33. `website` VARCHAR(50) COLLATE utf8_unicode_ci NOT NULL,
  34. `introduction` LONGTEXT COLLATE utf8_unicode_ci NOT NULL,
  35. `comments` LONGTEXT COLLATE utf8_unicode_ci NOT NULL,
  36. `DATE` DATE NOT NULL,
  37. `random` INT(20) NOT NULL,
  38. `activated` TINYINT(1) NOT NULL DEFAULT '0',
  39. PRIMARY KEY (`id`)
  40. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2 ;

_______________________
My REGISTRATION PAGE
_______________________

  1. <?php
  2. echo "<h1>Register</h1>";
  3.  
  4. $submit = $_POST['submit'];
  5.  
  6. //form data
  7. $firstname = strip_tags($_POST['first_name']);
  8. $lastname = strip_tags($_POST['last_name']);
  9. $address = $_POST['address'];
  10. $city = $_POST['city'];
  11. $state = $_POST['state'];
  12. $zipcode = $_POST['zip_code'];
  13. $birthmonth = $_POST['birth_month'];
  14. $birthday = $_POST['birth_day'];
  15. $birthyear = $_POST['birth_year'];
  16. $phone = $_POST['phone'];
  17. $email = $_POST['email'];
  18. $username = strtolower(strip_tags($_POST['username']));
  19. $password = strip_tags($_POST['password']);
  20. $repeatpassword = strip_tags($_POST['repeatpassword']);
  21. $securityquestion = $_POST['security_question'];
  22. $securityanswer = $_POST['security_answer'];
  23. $stagename = strip_tags($_POST['stage_name']);
  24. $adphone = $_POST['ad_phone'];
  25. $adphone2 = $_POST['ad_phone2'];
  26. $gender = $_POST['gender'];
  27. $sexuality = $_POST['sexuality'];
  28. $age = $_POST['age'];
  29. $height = $_POST['height'];
  30. $weight = $_POST['weight'];
  31. $hair = $_POST['hair'];
  32. $eye = $_POST['eye'];
  33. $ethnicity = $_POST['ethnicity'];
  34. $available = $_POST['available'];
  35. $adlocation = $_POST['ad_location'];
  36. $adtype = $_POST['ad_type'];
  37. $calltype = $_POST['call_type'];
  38. $website = $_POST['website'];
  39. $introduction = strip_tags($_POST['introduction']);
  40. $comments = strip_tags($_POST['comments']);
  41. $date = date("Y-m-d");
  42.  
  43. if ($submit)
  44. {
  45.  
  46. //open database
  47. $connect = mysql_connect("localhost","un","pass");
  48. mysql_select_db("db"); //select database
  49.  
  50. $namecheck = mysql_query("SELECT username FROM users WHERE username='$username'");
  51. $count = mysql_num_rows($namecheck);
  52.  
  53. if ($count!=0)
  54. {
  55. die("Username already taken!");
  56. }
  57.  
  58. //check for existance
  59. if ($firstname&&$lastname&&$address&&$city&&$state&&$zip_code&&$birthmonth&&
  60. $birthday&&$birthyear&&$phone&&$email&&$username&&$password&&$repeatpassword&&
  61. $securityquestion&&$security_answer&&$stagename&&$adphone&&$adphone2&&$gender&&
  62. $sexuality&&$age&&$height&&$weight&&$hair&&$eye&&$ethnicity&&$available&&
  63. $adlocation&&$adtype&&$calltype&&$website&&$introduction)
  64. {
  65.  
  66. if ($password==$repeatpassword)
  67. {
  68.  
  69. //check char length of username
  70. if (strlen($username)>25)
  71. {
  72. echo "Length of username is too long!";
  73. }
  74. else
  75. {
  76.  
  77. //check password length
  78. if (strlen($password)>25¦¦strlen($password)<6)
  79. {
  80. echo "Password must be between 6 and 25 characters";
  81. }
  82. else
  83. {
  84. //register the user!
  85.  
  86. // encrypt password
  87. $password = md5($password);
  88. $repeatpassword = md5($repeatpassword);
  89.  
  90. //generate random number for activation process
  91. $random = rand(23456789,98765432);
  92.  
  93. $queryreg = mysql_query("INSERT INTO users VALUES ('','$firstname','$lastname','$address','$city','$state','$zipcode','$birthmonth',
  94. '$birthday','$birthyear','$phone','$email','$username','$password',
  95. '$securityquestion','$securityanswer','$stagename','$adphone','$adphone2',
  96. '$gender','$sexuality','$age','$height','$weight','$hair','$eye','$ethnicity',
  97. '$available','$adlocation','$adtype','$calltype','$website','$introduction',
  98. '$comments','$date','$random','0')");
  99.  
  100. $lastid = mysql_insert_id();
  101.  
  102. //send activation email
  103. $to = $email;
  104. $subject = "Activate your account!";
  105. $headers = "From: [email]support@mysite.net[/email]";
  106. $server = "mail.mysite.net";
  107.  
  108. ini_set("SMTP",$server);
  109.  
  110. $body = "
  111.  
  112. Hello $first_name $last_name,\n\n
  113.  
  114. You need to activate your account with the link below:
  115. http://www.mysite.net/register/activate.php?id=$lastid&code=$random\n\n
  116.  
  117. Thanks!
  118.  
  119. ";
  120.  
  121. //function to send email
  122. mail($to, $subject, $body, $headers);
  123.  
  124. die("You have been registered! Check your email to activate your account!");
  125.  
  126. }
  127.  
  128. }
  129.  
  130. }
  131. else
  132. echo "Your passwords do not match!";
  133.  
  134. }
  135. else
  136. echo "Please fill in <b>all</b> fields!";
  137.  
  138. }
  139.  
  140. ?>

________________________________________
MY EMAIL ACTIVATION PAGE - activate.php that corresponds with the confirmation:
________________________________________

  1. <?php
  2.  
  3. $connect = mysql_connect("localhost","un","pass") or die("Couldn't connect!");
  4. mysql_select_db("db") or die("Couldn't find db");
  5.  
  6. $id = $_GET['id'];
  7. $code = $_GET['code'];
  8.  
  9. if ($id&&$code)
  10. {
  11.  
  12. $check = mysql_query("SELECT * FROM users WHERE id='$id' AND random='$code'");
  13. $checknum = mysql_num_rows($check);
  14.  
  15. if ($checknum==1)
  16. {
  17.  
  18. //run a query to activate the account
  19. $acti = mysql_query("UPDATE users SET activated='1' WHERE id='$id'");
  20. die("Your account is activated. You may now log in.");
  21.  
  22. }
  23. else
  24. die("Invalid ID or Activation code.");
  25.  
  26. }
  27. else
  28. die("Data missing!");
  29.  
  30. ?>
Last edited by peter_budo; Mar 26th, 2009 at 11:26 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 12
Reputation: freakin_chris is an unknown quantity at this point 
Solved Threads: 0
freakin_chris's Avatar
freakin_chris freakin_chris is offline Offline
Newbie Poster

Re: Data not going into my database??! plz help

 
0
  #2
Mar 25th, 2009
I''d suggest you store the query that you hit in a string and echo it out. check if the insert query works in the backend. Coz sometimes in php you might not get the values properly.
and for pimary key pass null if it has auto increment in dB. dont pass '' instead pass null widout quotes.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 94
Reputation: sikka_varun is an unknown quantity at this point 
Solved Threads: 11
sikka_varun's Avatar
sikka_varun sikka_varun is offline Offline
Junior Poster in Training

Re: Data not going into my database??! plz help

 
0
  #3
Mar 25th, 2009
Hi,

I agree with Chris... Use echo $sql_query to display if the query is working... If you are still unsure, try to use it through phpmyadmin and echo the query with values...

Secondly, when you run mysql_query, use or die with it..
E.g.:

  1. mysql_query($sql) or die("Query failed: ".mysql_error());

It gives u more detail why query failed...

Thirdly, when you using auto_increment on a field, just put 0 in that filed value... mysql automatically assigns an id value to it..

Also, make sure your $id and $random values are coming correctly in the url that you giving in the activation email...
Last edited by sikka_varun; Mar 25th, 2009 at 3:45 pm.
VâRûN
---Happy to Help---
sikka_varun@yahoo.com
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 28
Reputation: nathenastle is an unknown quantity at this point 
Solved Threads: 2
nathenastle's Avatar
nathenastle nathenastle is offline Offline
Light Poster

Re: Data not going into my database??! plz help

 
-1
  #4
Mar 26th, 2009
hi this is nathen,

  1. insert into cfair_deals (deal_affid, deal_storeid, deal_catid, subcat_id, deal_type, deal_title, deal_url, deal_coupon_code,deal_coupon_file,deal_start_date,deal_expire_date,deal_promotion,deal_expire,deal_barcode,deal_price,deal_oldprice,deal_discount, deal_pricecurrency,deal_oldcurrency,deal_image, deal_shortdesc,deal_fulldesc,deal_topcoupon,deal_hotweek,deal_status,added_on) VALUES (
  2. '$aff_id', '$store_id', '$cat_id', '$categoryname', '$deal_type', '$deal_title', '$deal_url', '$coupon_code','$couponfilename','$sdate', '$edate','$promotion','$expdate','$bar_code','$price','$old_price','$discount','$price_currency','$oldprice_currency','$filename','$short_desc', '$long_desc','$top_coupon','$hot_coupon', '$status',now())
Last edited by peter_budo; Mar 26th, 2009 at 11:26 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 2
Reputation: lildaddyha is an unknown quantity at this point 
Solved Threads: 0
lildaddyha lildaddyha is offline Offline
Newbie Poster

Re: Data not going into my database??! plz help

 
0
  #5
Mar 26th, 2009
ok I got it. I tried to query it without the quotes. my values for height had apostrohpes in then which interferred with my query line. thanks for much for the fast response on my thread. have a good day to all!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC