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
________________________

CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`last_name` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`address` varchar(60) COLLATE utf8_unicode_ci NOT NULL,
`city` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`state` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`zip_code` int(10) NOT NULL,
`birth_month` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`birth_day` varchar(2) COLLATE utf8_unicode_ci NOT NULL,
`birth_year` varchar(4) COLLATE utf8_unicode_ci NOT NULL,
`phone` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(75) COLLATE utf8_unicode_ci NOT NULL,
`username` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
`password` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
`security_question` varchar(60) COLLATE utf8_unicode_ci NOT NULL,
`security_answer` varchar(60) COLLATE utf8_unicode_ci NOT NULL,
`stage_name` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`ad_phone` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`ad_phone2` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`gender` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`sexuality` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`age` int(3) NOT NULL,
`height` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
`weight` varchar(8) COLLATE utf8_unicode_ci NOT NULL,
`hair` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`eye` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`ethnicity` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`available` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`ad_location` varchar(60) COLLATE utf8_unicode_ci NOT NULL,
`ad_type` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`call_type` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
`website` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`introduction` longtext COLLATE utf8_unicode_ci NOT NULL,
`comments` longtext COLLATE utf8_unicode_ci NOT NULL,
`date` date NOT NULL,
`random` int(20) NOT NULL,
`activated` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2 ;

_______________________
My REGISTRATION PAGE
_______________________

<?php
echo "<h1>Register</h1>";

$submit = $_POST['submit'];

//form data
$firstname = strip_tags($_POST['first_name']);
$lastname = strip_tags($_POST['last_name']);
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zip_code'];
$birthmonth = $_POST['birth_month'];
$birthday = $_POST['birth_day'];
$birthyear = $_POST['birth_year'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$username = strtolower(strip_tags($_POST['username']));
$password = strip_tags($_POST['password']);
$repeatpassword = strip_tags($_POST['repeatpassword']);
$securityquestion = $_POST['security_question'];
$securityanswer = $_POST['security_answer'];
$stagename = strip_tags($_POST['stage_name']);
$adphone = $_POST['ad_phone'];
$adphone2 = $_POST['ad_phone2'];
$gender = $_POST['gender'];
$sexuality = $_POST['sexuality'];
$age = $_POST['age'];
$height = $_POST['height'];
$weight = $_POST['weight'];
$hair = $_POST['hair'];
$eye = $_POST['eye'];
$ethnicity = $_POST['ethnicity'];
$available = $_POST['available'];
$adlocation = $_POST['ad_location'];
$adtype = $_POST['ad_type'];
$calltype = $_POST['call_type'];
$website = $_POST['website'];
$introduction = strip_tags($_POST['introduction']);
$comments = strip_tags($_POST['comments']);
$date = date("Y-m-d");

if ($submit)
{

//open database
$connect = mysql_connect("localhost","un","pass");
mysql_select_db("db"); //select database

$namecheck = mysql_query("SELECT username FROM users WHERE username='$username'");
$count = mysql_num_rows($namecheck);

if ($count!=0)
{
die("Username already taken!");
}

//check for existance
if ($firstname&&$lastname&&$address&&$city&&$state&&$zip_code&&$birthmonth&&
$birthday&&$birthyear&&$phone&&$email&&$username&&$password&&$repeatpassword&&
$securityquestion&&$security_answer&&$stagename&&$adphone&&$adphone2&&$gender&&
$sexuality&&$age&&$height&&$weight&&$hair&&$eye&&$ethnicity&&$available&&
$adlocation&&$adtype&&$calltype&&$website&&$introduction)
{

if ($password==$repeatpassword)
{

//check char length of username
if (strlen($username)>25)
{
echo "Length of username is too long!";
}
else
{

//check password length
if (strlen($password)>25¦¦strlen($password)<6)
{
echo "Password must be between 6 and 25 characters";
}
else
{
//register the user!

// encrypt password
$password = md5($password);
$repeatpassword = md5($repeatpassword);

//generate random number for activation process
$random = rand(23456789,98765432);

$queryreg = mysql_query("INSERT INTO users VALUES ('','$firstname','$lastname','$address','$city','$state','$zipcode','$birthmonth',
'$birthday','$birthyear','$phone','$email','$username','$password',
'$securityquestion','$securityanswer','$stagename','$adphone','$adphone2',
'$gender','$sexuality','$age','$height','$weight','$hair','$eye','$ethnicity',
'$available','$adlocation','$adtype','$calltype','$website','$introduction',
'$comments','$date','$random','0')");

$lastid = mysql_insert_id();

//send activation email
$to = $email;
$subject = "Activate your account!";
$headers = "From: [email]support@mysite.net[/email]";
$server = "mail.mysite.net";

ini_set("SMTP",$server);

$body = "

Hello $first_name $last_name,\n\n

You need to activate your account with the link below:
http://www.mysite.net/register/activate.php?id=$lastid&code=$random\n\n

Thanks!

";

//function to send email
mail($to, $subject, $body, $headers);

die("You have been registered! Check your email to activate your account!");

}

}

}
else
echo "Your passwords do not match!";

}
else
echo "Please fill in <b>all</b> fields!";

}

?>

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

<?php

$connect = mysql_connect("localhost","un","pass") or die("Couldn't connect!");
mysql_select_db("db") or die("Couldn't find db");

$id = $_GET['id'];
$code = $_GET['code'];

if ($id&&$code)
{

$check = mysql_query("SELECT * FROM users WHERE id='$id' AND random='$code'");
$checknum = mysql_num_rows($check);

if ($checknum==1)
{

//run a query to activate the account
$acti = mysql_query("UPDATE users SET activated='1' WHERE id='$id'");
die("Your account is activated. You may now log in.");

}
else
die("Invalid ID or Activation code.");

}
else
die("Data missing!");

?>

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.

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.:

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...

hi this is nathen,

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 (
'$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())
commented: 18 posts and still no code tags???? -1

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.