Jump to content

PHP script help with database


Recommended Posts

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 ;

 

Link to comment
Share on other sites

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'
)

Link to comment
Share on other sites

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')

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

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!";

?>

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.