Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding data to table on registration
    text
    copied!<p>Ok so im in the middle of making a pokemon browser based game, and im having trouble making it so when a user registers to my site, they gain a starter pokemon that they choose. I have it all working except for the part where it gives the user the pokemon, right now it enters the pokemon into the database but it does not give the pokemon to the user who registers it leaves the belongsto field empty. kinda hard for me to explain.</p> <p>Here is the part of my code that enters the data to the table that stores all users pokemon.</p> <pre><code>&lt;?php if ($_POST['starter'] == '1' ) { mysql_query("INSERT INTO user_pokemon (pokemon, belongsto, exp, time_stamp, slot, level,type) VALUES('Bulbasaur','".$_SESSION['username']."', 100,'".time()."','1' ,'5','Normal' ) ") or die(mysql_error()); } if ($_POST['starter'] == '2' ) { mysql_query("INSERT INTO user_pokemon (pokemon, belongsto, exp, time_stamp, slot, level,type) VALUES('Charmander','".$_SESSION['username']."', 100,'".time()."','1' ,'5','Normal' ) ") or die(mysql_error()); } if ($_POST['starter'] == '3' ) { mysql_query("INSERT INTO user_pokemon (pokemon, belongsto, exp, time_stamp, slot, level,type) VALUES('Squirtle','".$_SESSION['username']."', 100,'".time()."','1' ,'5','Normal' ) ") or die(mysql_error()); } if ($_POST['starter'] == '4' ) { mysql_query("INSERT INTO user_pokemon (pokemon, belongsto, exp, time_stamp, slot, level,type) VALUES('Chikorita','".$_SESSION['username']."', 100,'".time()."','1' ,'5','Normal' ) ") or die(mysql_error()); } if ($_POST['starter'] == '5' ) { mysql_query("INSERT INTO user_pokemon (pokemon, belongsto, exp, time_stamp, slot, level,type) VALUES('Cyndaquil','".$_SESSION['username']."', 100,'".time()."','1' ,'5','Normal' ) ") or die(mysql_error()); } if ($_POST['starter'] == '6' ) { mysql_query("INSERT INTO user_pokemon (pokemon, belongsto, exp, time_stamp, slot, level,type) VALUES('Totodile','".$_SESSION['username']."', 100,'".time()."','1' ,'5','Normal' ) ") or die(mysql_error()); } if ($_POST['starter'] == '7' ) { mysql_query("INSERT INTO user_pokemon (pokemon, belongsto, exp, time_stamp, slot, level,type) VALUES('Treecko','".$_SESSION['username']."', 100,'".time()."','1' ,'5','Normal' ) ") or die(mysql_error()); } if ($_POST['starter'] == '8' ) { mysql_query("INSERT INTO user_pokemon (pokemon, belongsto, exp, time_stamp, slot, level,type) VALUES('Torchic','".$_SESSION['username']."', 100,'".time()."','1' ,'5','Normal' ) ") or die(mysql_error()); } if ($_POST['starter'] == '9' ) { mysql_query("INSERT INTO user_pokemon (pokemon, belongsto, exp, time_stamp, slot, level,type) VALUES('Mudkip','".$_SESSION['username']."', 100,'".time()."','1' ,'5','Normal' ) ") or die(mysql_error()); } if ($_POST['starter'] == '10' ) { mysql_query("INSERT INTO user_pokemon (pokemon, belongsto, exp, time_stamp, slot, level,type) VALUES('Turtwig','".$_SESSION['username']."', 100,'".time()."','1' ,'5','Normal' ) ") or die(mysql_error()); } if ($_POST['starter'] == '11' ) { mysql_query("INSERT INTO user_pokemon (pokemon, belongsto, exp, time_stamp, slot, level,type) VALUES('Chimchar','".$_SESSION['username']."', 100,'".time()."','1' ,'5','Normal' ) ") or die(mysql_error()); } if ($_POST['starter'] == '12' ) { mysql_query("INSERT INTO user_pokemon (pokemon, belongsto, exp, time_stamp, slot, level,type) VALUES('Piplup','".$_SESSION['username']."', 100,'".time()."','1' ,'5','Normal' ) ") or die(mysql_error()); } ?&gt; </code></pre> <p>The thing that I can't figure out is how to make it so it takes the name that the user is registering with and puts it in place of .$_SESSION['username']. I know that won't work because the person isn't signed in yet because they are still registering.</p> <p>Here is my form.</p> <pre><code>&lt;form action="" method="post"&gt; &lt;div align="center"&gt; &lt;ul&gt; &lt;p&gt;&lt;/p&gt; Username* &lt;br&gt; &lt;input type="text" name="username"&gt; &lt;p&gt;&lt;/p&gt; Password*&lt;br&gt; &lt;input type="password" name="password"&gt; &lt;p&gt;&lt;/p&gt; Password again*&lt;br&gt; &lt;input type="password" name="password_again"&gt; &lt;p&gt;&lt;/p&gt; First name&lt;br&gt; &lt;input type="text" name="first_name"&gt; &lt;p&gt;&lt;/p&gt; Last name&lt;br&gt; &lt;input type="text" name="last_name"&gt; &lt;p&gt;&lt;/p&gt; Email*&lt;br&gt; &lt;input type="text" name="email"&gt; &lt;p&gt;&lt;/p&gt; Starter*&lt;br&gt; &lt;select name="starter" id="" &gt; &lt;option value="1"&gt;Bulbasaur&lt;/option&gt; &lt;option value="2"&gt;Charmander&lt;/option&gt; &lt;option value="3"&gt;Squirtle&lt;/option&gt; &lt;option value="4"&gt;Chikorita&lt;/option&gt; &lt;option value="5"&gt;Cyndaquil&lt;/option&gt; &lt;option value="6"&gt;Totodile&lt;/option&gt; &lt;option value="7"&gt;Treecko&lt;/option&gt; &lt;option value="8"&gt;Torchic&lt;/option&gt; &lt;option value="9"&gt;Mudkip&lt;/option&gt; &lt;option value="10"&gt;Turtwig&lt;/option&gt; &lt;option value="11"&gt;Chimchar&lt;/option&gt; &lt;option value="12"&gt;Piplup&lt;/option&gt; &lt;/select&gt; &lt;p&gt;&lt;/p&gt; &lt;input type="submit" value="Register"&gt; &lt;/ul&gt; &lt;/div&gt; &lt;ul&gt; &lt;/ul&gt; &lt;/form&gt; </code></pre> <p>Im sorry for the giant question but any help would be greatly appreciated :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload