AnAmericanGunner Posted April 11, 2010 Share Posted April 11, 2010 My register page is this: <? session_name('usersession'); session_start(); include('includes/database.php'); include('inclues/header.php'); ?> <? $username = $_POST['user']; $password = md5($_POST['pass']); $result = mysql_query("SELECT * FROM user WHERE username='$username'") or die(mysql_error()); $num_rows = mysql_num_rows($result); if($num_rows !== 0){ echo "Username already taken, please choose another one!"; } else{ mysql_query("INSERT INTO user (username, passwd) VALUES('$username', '$password' ) ") or die(mysql_error()); echo "Welcome to ER, you may now login!"; } ?> <a href="index.php">Return Home</a> </body> </html> My question is this: Can I wrote another INSERT INTO query to insert the username into a table called BALANCE? The username would be going into the column 'description' and '5' would have to go into a column called 'credits'. Quote Link to comment Share on other sites More sharing options...
Jax2 Posted April 11, 2010 Share Posted April 11, 2010 You can put two queries in a row if you like ... $sql=" first query, put X into table Y"; $result=mysql_query($sql, $db); $sql=" second query, put A into table B"; $result=mysql_query($sql, $db); ... or however you write your queries ... Quote Link to comment Share on other sites More sharing options...
the182guy Posted April 11, 2010 Share Posted April 11, 2010 Of course you can use another INSERT INTO query. Example <?php session_name('usersession'); session_start(); include('includes/database.php'); include('inclues/header.php'); ?> <? $username = $_POST['user']; $password = md5($_POST['pass']); $result = mysql_query("SELECT * FROM user WHERE username='$username'") or die(mysql_error()); $num_rows = mysql_num_rows($result); if($num_rows !== 0){ echo "Username already taken, please choose another one!"; } else{ $username = mysql_real_escape_string($username); // important! see SQL Injection $resultUser = mysql_query("INSERT INTO user (username, passwd) VALUES('$username', '$password' ) ") or die(mysql_error()); // now insert into the user_credits table $resultCredits = mysql_query("INSERT INTO user_credits (description, credits) VALUES ('$username', 5)"); echo "Welcome to ER, you may now login!"; } ?> <a href="index.php">Return Home</a> </body> </html> Quote Link to comment Share on other sites More sharing options...
AnAmericanGunner Posted April 11, 2010 Author Share Posted April 11, 2010 Thanks for the replies! I shall try them out soon. Quote Link to comment Share on other sites More sharing options...
AnAmericanGunner Posted April 11, 2010 Author Share Posted April 11, 2010 Thanks the182guy. Your code worked perfectly 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.