你好男孩和女孩我擁有一個RPG(一個在線角色扮演遊戲) 用戶可以捕捉怪物,並培訓他們和東西。但現在我已經來到建立一個交易腳本...Mysql插入不能在交易腳本
我顯示所有那裏的怪物和其他用戶在1頁上的怪物,但是當他們選擇他們想要什麼,並提供了什麼怪物它不會添加進入數據庫的信息...
因此,我有一個頁面,他們必須輸入他們想要交易的用戶名。
<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> </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> </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我試着解釋我能做到的最好。
和DB連接我已經編輯了.....
有強大的熟悉這一切...一些=] – 2012-02-07 09:46:31