gpt4 book ai didi

php - Mysql 插入不适用于交易脚本

转载 作者:行者123 更新时间:2023-11-29 08:58:55 25 4
gpt4 key购买 nike

大家好,我有一个角色扮演游戏(在线角色扮演游戏)用户可以捕捉怪物并训练它们等等。但现在我开始构建一个交易脚本......

我在第一页上显示了所有怪物和其他用户的怪物,但是当他们选择他们想要的东西以及为怪物提供的东西时,它不会将信息添加到数据库中......

所以我有一个页面,他们必须输入他们想要进行交易的用户用户名。

    <form name="input" action="tradedo.php" method="get">
Username: <input type="text" name="username_trade" />
<input type="submit" value="Submit" />
</form>

然后在 tradedo.php 上显示怪物,其他用户怪物被捕获,他们可以选择他们想要的东西以及为他们提供的东西......

    session_start();

mysql_connect("localhost", "blah", "");
mysql_select_db("");



$username_trade = $_POST['username_trade'];



$_SESSION['username_trade'] = $username_trade ;

echo "You put in id ". $username_trade . ".<br />";



?>
</p>
<p>&nbsp;</p>
<p><span class="mid_box">
<?php
// get and display userbox
$q = "SELECT id,pokemon,exp,level FROM user_pokemon WHERE belongsto='". $_SESSION['username_trade']."'";
$r = mysql_query($q);

if (mysql_num_rows($r) <= 0) {
echo "You have no current pokemon stored";

}
?>

</span></p>
<p>&nbsp;</p>

<p>
<?php
echo "<form action='tradestore.php' method='POST'>";
while ( $v = mysql_fetch_object( $r ) )
{
echo "<label><input type='checkbox' name='pokemon[]' value='$v->dbid'/> They have a $v->pokemon </label><br/>";
echo "<label> Level $v->level </label><br/>";
}
echo "<input type='hidden' name='user' value='$username_trade'/>";
echo "<input type='submit' value='Check!!'/>";
?>
</p>
<p><strong>Pick what you want two offer for the pokemon </strong></p>
<p>
<?php
// get and display userbox
$q = "SELECT id,pokemon,exp,level FROM user_pokemon WHERE belongsto='". $_SESSION['username']."'";
$t = mysql_query($q);

if (mysql_num_rows($t) <= 0) {
echo "You have no current pokemon stored";

}
?>
</p>
<p>


<?php
echo "<form action='test_process.php' method='POST'>";
while ( $v = mysql_fetch_object( $t ) )
{
echo "<label><input type='checkbox' name='pokemonin[]' value='$v->dbid'/> I have a $v->pokemon</label><br/>";
echo "<label> Level $v->level </label><br/>";
}
echo "<input type='hidden' name='userin' value='$username'/>";
echo "</form>";

这很好用......它显示了所有怪物,一切都很棒,但现在我需要插入它们,这是插入页面

    session_start();

mysql_connect("localhost", "blahhhhhhhhhhh", "");
mysql_select_db("");



$pokemon = $_POST['pokemon'];
$pokemonin = $_POST['pokemonin'];
$meid = $_SESSION['username'];
$toid = $_POST['user'];
$dbid = array();
$dbid2 = array();

foreach ( $pokemon as $poke )
{ $dbid['pokemon'][] = $poke;

}

foreach ( $pokemonin as $poke2 )
{ $dbid2['pokemonin'][] = $poke2;


}




srand ((double) microtime( )*1000000);
$random_number = rand( );
echo "$random_number";


mysql_query("INSERT INTO trade (trade_id, trade_to, trade_from, trade_pokeid, trade_mypokeid)
VALUES ('$random_number','".$toid."', '".$meid."', '".$dbid['pokemon']."', '".$dbid2['pokemonin']."');") or die("Error: ". mysql_error());



echo"Done";

在我的数据库中,我得到了

trade_id = 1977949793(works)
trade_to =
trade_from = admin (works)
trade_pokeid = Array ( no monster ids ???)
trade_mypokeid = Array( no monster ids ???)

用于插入怪物ID的脚本有1,4,5,7,然后ID抓取它们并将它们显示在交易接受页面上..但不是它只是添加数组,甚至没有抓取我尝试过的trade_to尽我所能解释。

我已经编辑了数据库连接......

最佳答案

在 INSERT 语句中:

 ... '".$dbid['pokemon']."'

这是一个与字符串连接的数组,不起作用。

您可以序列化或循环它并创建一些表示,但最好重新设计数据库方案,这样您就不会在一个字段中存储多个值...

关于php - Mysql 插入不适用于交易脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9163525/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com