Drezard Posted March 13, 2007 Share Posted March 13, 2007 Hello, I have a number of scripts (too many to post) but in the other scripts they connect to the database, they also use this class and the functions within. Now... <?php error_reporting(E_ALL); include('core/main.inc.php'); class class_users { function user_signup() { if (!isset($_POST['submit'])) { echo "<form action='' method='post'> Username: <input name='username' type='text' maxvalue='32'> <hr> Password: <input name='password' type='password' maxvalue='32'> <hr> Confirm Password: <input name='password2' type='password' maxvalue='32'> <hr> Email: <input name='email' type='email' maxvalue='128'> <hr> Race: <select name='race'> <option value='human'>Human</option> <option value='vampire'>Vampire</option> <option value='shade'>Shade</option> </select> <hr> Class: <select name='class'> <option value='warrior'>Warrior</option> <option value='defender'>Defender</option> <option value='assasin'>Assasin</option> <option value='mage'>Mage</option> <option value='priest'>Priest</option> </select> <hr> <input type = 'submit' name = 'submit'><hr>"; } if (isset($_POST['submit'])) { if (!isset($_POST['username']) || trim($_POST['username']) == '') { die('Please insert username'); } if (!isset($_POST['password']) || trim($_POST['password']) == '') { die('Please enter a password'); } if (!isset($_POST['password2']) || trim($_POST['password2']) == '') { die('Please confirm your password'); } if (!isset($_POST['email']) || trim($_POST['email']) == '') { die('Please enter your email address'); } if (!isset($_POST['race']) || trim($_POST['race']) == '') { die('Please choose a race'); } if (!isset($_POST['class']) || trim($_POST['class']) == '') { die('Please choose a class'); } if ($_POST['password'] != $_POST['password2']) { die('Passwords do not match'); } $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; $race = $_POST['race']; $class = $_POST['class']; $timestamp = date('YmdGi'); $ip = $_SERVER['REMOTE_ADDR']; $priv = 1; $query = "SELECT * FROM user_ids WHERE username='$username'"; $result = mysql_query($query); $count = mysql_num_rows($result); if ($count == 1) { echo "Username already exists"; } if ($count == 0) { $query = "INSERT INTO user_ids (user, password, priv, timestamp, ip) VALUES ('$username', '$password', '$priv', '$timestamp', '$ip')"; $result = mysql_query($query); $this->user_charcreate($username, $race, $class); echo "Account created"; } } } function user_charcreate($username, $race, $class) { if ($race == 'human') { $strength = 10; $dexerity = 10; $constitution = 10; $intelligence = 10; } if ($race == 'vampire') { $strength = 12; $dexerity = 8; $constitution = 12; $intelligence = 8; } if ($race == 'shade') { $strength = 12; $dexerity = 12; $constitution = 8; $intelligence = 8; } if ($class == 'warrior') { $strength = $strength + 2; $dexerity = $dexerity + 2; $constitution = $constitution - 2; $intelligence = $intelligence - 2; } if ($class == 'defender') { $strength = $strength + 2; $dexerity = $dexerity - 2; $constitution = $constitution + 4; $intelligence = $intelligence - 4; } if ($class == 'assasin') { $strength = $strength + 2; $dexerity = $dexerity + 2; $constitution = $constitution - 2; $intelligence = $intelligence - 2; } if ($class == 'mage') { $strength = $strength - 2; $dexerity = $dexerity + 2; $constitution = $constitution - 4; $intelligence = $intelligence + 4; } if ($class == 'healer') { $strength = $strength - 2; $dexerity = $dexerity - 4; $constitution = $constitution + 2; $intelligence = $intelligence + 4; } $query = "INSERT INTO user_charinfo (username, strength, dexerity, constitution, intelligence) VALUES ('$username', '$strength', ' '$dexerity', '$constitution', '$intelligence')"; $result = mysql_query($query); } } ?> Thats my code... But when I run it, insert stuff into the form and such it says "Account created" but it doesn't insert it into the database. The database just stays blank. What could be wrong? - Cheers, Daniel (This script is running on www.wintersword.com/register) Quote Link to comment Share on other sites More sharing options...
papaface Posted March 13, 2007 Share Posted March 13, 2007 $query = "INSERT INTO user_charinfo (username, strength, dexerity, constitution, intelligence) VALUES ('$username', '$strength', ' '$dexerity', '$constitution', '$intelligence')"; should be: $query = "INSERT INTO user_charinfo (username, strength, dexerity, constitution, intelligence) VALUES ('$username', '$strength', ' $dexerity', '$constitution', '$intelligence')"; Also you should also put your variables in SQL like this: $query = "INSERT INTO user_charinfo (username, strength, dexerity, constitution, intelligence) VALUES ('{$username}', '{$strength}', ' {$dexerity}', '{$constitution}', '{$intelligence}')"; Quote Link to comment Share on other sites More sharing options...
jaikar Posted March 13, 2007 Share Posted March 13, 2007 is there any specific reason to put the code like '{$varuable}' Quote Link to comment Share on other sites More sharing options...
only one Posted March 13, 2007 Share Posted March 13, 2007 depends on your php version... Quote Link to comment 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.