Jump to content

Where is the error?


cvo

Recommended Posts

if ($doing == "registor") {
$password = $_POST['password'];
$password = md5($password );
$email=$_POST['email'];
$lname=$_POST['lname'];
$fname=$_POST['fname'];
$rank="cdt";
srand ((double) microtime( )*1000000);
$random_number = rand(1000000,9999999);
$date = "0000-00-00 00:00:00";
$about="Nothing Much";
$zero="0";
$query = "INSERT INTO users VALUES ('','$random_number','$rank','$fname','$lname',NOW(),'$date','$zero','$zero','$zero','$about','$email','$password')";
if (!mysql_query($query)){
$works = "0";
}else{
$works="1";
}
}

 

Ive tried fixing this, but its not telling me what the error is and is still not inserting in the database. can anyone spot any errors there.

 

Thanks in advance...

 

 

Just incase, here is a dump of the users table...

 

CREATE TABLE IF NOT EXISTS `users` (
  `id` bigint(20) NOT NULL auto_increment,
  `randomId` int(11) NOT NULL,
  `rank` text NOT NULL,
  `fname` text NOT NULL,
  `lname` text NOT NULL,
  `dateRegisored` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `lastOn` timestamp NOT NULL default '0000-00-00 00:00:00',
  `banned` bigint(20) NOT NULL default '0',
  `bannedHours` bigint(20) NOT NULL default '0',
  `banCount` bigint(20) NOT NULL default '0',
  `about` longtext NOT NULL,
  `email` text NOT NULL,
  `password` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

Link to comment
https://forums.phpfreaks.com/topic/116913-where-is-the-error/
Share on other sites

You need to specify which columns each variables is being assigned to. or else it wont know where you want them.

 

So you need to do:

 

$query = "INSERT INTO users (user_id, user_number, _user_rank, user_fname, etc etc...) VALUES ('','$random_number','$rank','$fname','$lname',NOW(),'$date','$zero','$zero','$zero','$about','$email','$password')";

 

But the number of items in the first parenthesis must be the same number in the second.

 

Link to comment
https://forums.phpfreaks.com/topic/116913-where-is-the-error/#findComment-601215
Share on other sites

Thanks dannyb785, still no luck though.

$query = "INSERT INTO users (id, randomId, rank, fname, lname, dateRegisored, lastOn, banned, bannedHours, banCount, about, email, password) VALUES ('','$random_number','$rank','$fname','$lname',NOW(),'$date','$zero','$zero','$zero','$about','$email','$password')";

 

and Pyro thats just a bad spelling habit sorry, but any how here is my form ish.

 

<form action="index.php?page=registor" method="Post"><input name="lname" type="hidden" value="<?=$_POST['lname'] ?>"><input name="fname" type="hidden" value="<?=$_POST['fname'] ?>"><input name="password"  type="hidden" value="<?=$_POST['password'] ?>"><input name="email" type="hidden" value="<?=$_POST['email'] ?>"><input type="submit" value="FINNISH"><input type="hidden" name="part" value=3><input name="doing" type="hidden" value="registor"></form>

 

 

Edit: Wrong form sorry that was an earlier one

Link to comment
https://forums.phpfreaks.com/topic/116913-where-is-the-error/#findComment-601221
Share on other sites

Im sure the form works perfictly becouse it runs the sql query, the query just fails and doesnt insert the data.

 

 

You need to add "or die(mysql_error());" after your query. Change the end part to just:

 

$result = mysql_query($query) or die(mysql_error());

 

that will help you with what is going wrong.

 

There is also a worse problem and thats you do not need to insert the literal id into your database in the user_id column. If it's set to auto_increment then just leave it alone, it'll do it on its own.

 

 

Link to comment
https://forums.phpfreaks.com/topic/116913-where-is-the-error/#findComment-601228
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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