好的,我正在制作一个基于浏览器的口袋妖怪游戏,但我在制作它时遇到了麻烦,所以当用户注册到我的网站时,他们会获得一个他们选择的入门口袋妖怪。除了它为用户提供口袋妖怪的部分外,我已经完成了所有工作,现在它会将口袋妖怪输入数据库,但它不会将口袋妖怪提供给注册它的用户,因此将 belongsto 字段留空。我有点难以解释。
这是我的代码的一部分,它将数据输入到存储所有用户口袋妖怪的表中。
<?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());
}
?>
我想不通的是如何制作它,因此它采用用户注册的名称并将其替换为 .$_SESSION['username']。我知道这行不通,因为此人尚未登录,因为他们仍在注册。
这是我的表格。
<form action="" method="post">
<div align="center">
<ul>
<p></p>
Username* <br>
<input type="text" name="username">
<p></p>
Password*<br>
<input type="password" name="password">
<p></p>
Password again*<br>
<input type="password" name="password_again">
<p></p>
First name<br>
<input type="text" name="first_name">
<p></p>
Last name<br>
<input type="text" name="last_name">
<p></p>
Email*<br>
<input type="text" name="email">
<p></p>
Starter*<br>
<select name="starter" id="" >
<option value="1">Bulbasaur</option>
<option value="2">Charmander</option>
<option value="3">Squirtle</option>
<option value="4">Chikorita</option>
<option value="5">Cyndaquil</option>
<option value="6">Totodile</option>
<option value="7">Treecko</option>
<option value="8">Torchic</option>
<option value="9">Mudkip</option>
<option value="10">Turtwig</option>
<option value="11">Chimchar</option>
<option value="12">Piplup</option>
</select>
<p></p>
<input type="submit" value="Register">
</ul>
</div>
<ul>
</ul>
</form>
我很抱歉这个巨大的问题,但任何帮助将不胜感激:)