FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Quick problem i think its a easy fix

 


darkjoker
Ok heres the problem. I have a user database that works fine when they register thier username and password it is getting same in my database.
Now i want the user to have stats. This is the idea when they sign up it saves thier username and password but in the database it it has 6 rows one for ID,Username,Password,Power,Attacks,Money. Now the power,attacks and money are all defualts wich start thier profile off with.
i.e(ID=1 Username=me Password=w/e Power=0 Attacks=0 Money=0)
But when i put the power,attacks, and money fields in thier and test the registery it tells me the row vaule and coulm value do not match. Here is the code for the register.php that inserts the registered info into the database

Code:
<?php
include("connect.php");
include("config.php");

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

// check if the username is taken
$check = "select id from $table where username = '".$_POST['username']."';";
$qry = mysql_query($check)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
echo "Sorry, there the username $username is already taken.<br>";
echo "<a href=register.html>Try again</a>";
exit;
} else {

// insert the data
$insert = mysql_query("insert into $table values ('NULL','".$_POST['username']."', '".$_POST['password']."')")
or die("Could not insert data because ".mysql_error());

// print a success message
echo "Your user account has been created!<br>";
echo "Now you can <a href=index.html>log in</a>";
}

?>
Any help would be great thanks.
mathiaus
Try the below. If you're using auto_increment on ID don't use NULL, either use a blank space '' or dont mention it. For the deafults for the power, money and attacks, chnage the db in phpmyadmin and set the default value for those columns as what you want them to be.
Code:
$insert = mysql_query("INSERT INTO $table(username, password) VALUES ('".$_POST['username']."', '".$_POST['password']."')")
darkjoker
Thanks alot man its all fixed now much coodoughs to you.lol Razz
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.