energysuperstore09 Posted March 30, 2009 Share Posted March 30, 2009 When people register for a login I want the data to be stored into the database. Right now the only data stored is email, password, id, and approved. All my other columns are blank. Below is my table structure I use an INSERT command, but it is still not storing the other data submitted into the database. Can anybody help? CREATE TABLE IF NOT EXISTS `loginreg` ( `id` int(11) NOT NULL auto_increment, `repnumber` text NOT NULL, `fname` varchar(50) NOT NULL, `lname` varchar(50) NOT NULL, `cname` text NOT NULL, `phone` text NOT NULL, `email` text NOT NULL, `username` text NOT NULL, `password` text NOT NULL, `approved` tinyint(1) NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ; Quote Link to comment https://forums.phpfreaks.com/topic/151818-php-script-help-with-database/ Share on other sites More sharing options...
energysuperstore09 Posted March 30, 2009 Author Share Posted March 30, 2009 Can anybody Help me? Quote Link to comment https://forums.phpfreaks.com/topic/151818-php-script-help-with-database/#findComment-797187 Share on other sites More sharing options...
wildteen88 Posted March 30, 2009 Share Posted March 30, 2009 Post code the you're having issues with here. Posting just your table structure wont yield many helpful answers. Quote Link to comment https://forums.phpfreaks.com/topic/151818-php-script-help-with-database/#findComment-797190 Share on other sites More sharing options...
energysuperstore09 Posted March 30, 2009 Author Share Posted March 30, 2009 here is the INSERT string that I put in and I am still not getting data stored into the database. The email, password, first name (fname) is getting stored, but not the other data mysql_query("INSERT INTO `loginreg` ( `repnumber` , `fname` , `lname` , `cname` , `phone` , `email` , `username` , `password` ) VALUES ( '$email', '$password', '$fname', '$lname', '$repnumber', '$cname', '$phone', '$username' ) Quote Link to comment https://forums.phpfreaks.com/topic/151818-php-script-help-with-database/#findComment-797191 Share on other sites More sharing options...
Brian W Posted March 30, 2009 Share Posted March 30, 2009 are you using mysql_error() to debug mysql_query()? Quote Link to comment https://forums.phpfreaks.com/topic/151818-php-script-help-with-database/#findComment-797198 Share on other sites More sharing options...
wildteen88 Posted March 30, 2009 Share Posted March 30, 2009 The problem I see with your query is that your variables are not in the order of your field names $repnumber should be before $fname also $email and $password should be after $phone mysql_query("INSERT INTO `loginreg` ( `repnumber` , `fname` , `lname` , `cname` , `phone` , `email` , `username` , `password` ) VALUES ('$repnumber', '$fname', '$lname', '$cname', '$phone', '$email', '$username', '$password') Quote Link to comment https://forums.phpfreaks.com/topic/151818-php-script-help-with-database/#findComment-797203 Share on other sites More sharing options...
energysuperstore09 Posted March 30, 2009 Author Share Posted March 30, 2009 ok. I wasn't sure if they had to be in the same order. I am new to this and it def can get underneath your skin. Let me put them in order and see if they work. Also no I am not using Mysql error to debug. Could you explain? Quote Link to comment https://forums.phpfreaks.com/topic/151818-php-script-help-with-database/#findComment-797220 Share on other sites More sharing options...
Brian W Posted March 30, 2009 Share Posted March 30, 2009 are you using the function mysql_query() to execute the mysql query? if so, post your code and I'll help you out on the debuging Quote Link to comment https://forums.phpfreaks.com/topic/151818-php-script-help-with-database/#findComment-797224 Share on other sites More sharing options...
corbin Posted March 30, 2009 Share Posted March 30, 2009 Don't take this the wrong way, but errr.... How would PHP know to magically put your variables in the right order? Or how would MySQL know? Anyway, mysql_error is a function that returns the last error that has been encountered using MySQL. Example: $q = mysql_query("...."); if(!$q) { echo "Oh no! There was an error. Error: " . mysql_error(); } Or, it's commonly used with an "or die" clause (which is a bad programming practice as far as final code goes). mysql_query("....") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/151818-php-script-help-with-database/#findComment-797226 Share on other sites More sharing options...
energysuperstore09 Posted March 30, 2009 Author Share Posted March 30, 2009 Its ok. I understand. Here is the code that is on the register page for the login: <?php $email = $_POST['email']; $password = $_POST['pass']; $password2 = $_POST['pass2']; @mysql_connect("xxxx","xxx","xxx") or die("Error: unable to connect to database"); @mysql_select_db("test09"); $result = mysql_query("SELECT * FROM `loginreg` WHERE `email`='$email'"); if (mysql_num_rows($result) != 0) { die("Another account is already using that email"); } if ($password != $password2) { die("The two passwords did not match"); } $password = md5($password); mysql_query("INSERT INTO `loginreg` ( `repnumber` , `fname` , `lname` , `cname` , `phone` , `email` , `username` , `password` ) VALUES ( '$repnumber', '$fname', '$lname', '$cname', '$phone', '$email', '$username', '$password' ) ") or die(mysql_error()); echo "Your account was successfully created!"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/151818-php-script-help-with-database/#findComment-797231 Share on other sites More sharing options...
energysuperstore09 Posted March 30, 2009 Author Share Posted March 30, 2009 Here is the link to the page http://www.texasfluorescents.com/distributorlogin.html Quote Link to comment https://forums.phpfreaks.com/topic/151818-php-script-help-with-database/#findComment-797232 Share on other sites More sharing options...
corbin Posted March 30, 2009 Share Posted March 30, 2009 Errr x.x You should edit out your database details quickly ;p. Quote Link to comment https://forums.phpfreaks.com/topic/151818-php-script-help-with-database/#findComment-797246 Share on other sites More sharing options...
corbin Posted March 30, 2009 Share Posted March 30, 2009 So... do you get an error? Or what happens? Also, you should use mysql_real_escape_string on input data as to prevent weird errors and SQL injection. Quote Link to comment https://forums.phpfreaks.com/topic/151818-php-script-help-with-database/#findComment-797252 Share on other sites More sharing options...
energysuperstore09 Posted March 30, 2009 Author Share Posted March 30, 2009 sorry. I didn't even think myinfo being posted on there. No I don't the error thing. See I am getting into this php thing because my boss wanted a login for our distributors. Problem is that I didn't know a whole lot about it. So thats why I have joined this forum. The database side I am starting to get because I am taking classes in MYSQL Server 2005. But this is still difficult to learn. Quote Link to comment https://forums.phpfreaks.com/topic/151818-php-script-help-with-database/#findComment-797266 Share on other sites More sharing options...
Brian W Posted March 30, 2009 Share Posted March 30, 2009 do you plan to continue using php prior to getting the login to work? If not, consider the freelance board for this project. Quote Link to comment https://forums.phpfreaks.com/topic/151818-php-script-help-with-database/#findComment-797290 Share on other sites More sharing options...
energysuperstore09 Posted March 30, 2009 Author Share Posted March 30, 2009 I do plan to continue to use php after this project as I am getting more comfortable with the database side of things. Quote Link to comment https://forums.phpfreaks.com/topic/151818-php-script-help-with-database/#findComment-797331 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.