簡體   English   中英

phpmyadmin和mysql顯示錯誤結果

[英]Phpmyadmin and mysql showing wrong results

我想為我的rpg買一個物品商店,我有一個名為itemslist的表,其中有3列itemname,itemprice,image,

因此,目前我在其中有1個條目,條目名稱為Potion itemprice,其價格為1000,圖片僅供參考。

我遇到問題的圖像列。 由於某種原因,它回顯了1而不是嘿。 甚至在phpmyadmin中也是如此。 除價格外,所有列均為var。

問題是,如果我將價格更改為99,它將回顯出他的圖像具有9,如果我將itemprice更改為10,則將顯出具有0的列圖像。即使在db中,列圖像也是嘿,價格為10,會回顯他的價格為10,而圖像在頁面上為0,由於某種原因,它獲取了價格的最后一個數字,並認為這是圖像列

include_once('config.php');
$item = $_POST['item'];
$item = mysql_real_escape_string($_POST['item']);
$item2 = preg_replace('/[^a-z]/i', null, $item);

/// Get the item price 
$sql55 = "SELECT * FROM itemslist WHERE itemname='$item2'";
$result55 = mysql_query($sql55) or die(mysql_error());
$itemprice = mysql_fetch_array($result55);


$sql555 = "SELECT * FROM users WHERE username='".$_SESSION['username']." '";
$result555 = mysql_query($sql555) or die(mysql_error());
$usermoney = mysql_fetch_array($result555);

$itemname = $itemprice['itemname'] ;
$itemprice = $itemprice['itemprice'] ;
$itemimage = $itemprice['image'] ;


echo  $itemimage ;


if ($usermoney['money']  > $itemprice['itemprice']) {
  echo "You have just bought a ";
  echo $itemname ;




    mysql_query("INSERT INTO `items` (`item`, `belongsto`, `itemimage`) VALUES ('$itemname','".$_SESSION['username']."','$itemimage')") or die(mysql_error());  


   $result23123 = mysql_query("UPDATE users SET money=money-$itemprice WHERE username = '{$_SESSION['username']}'")
or die(mysql_error());
}else{
echo"Your to poor to buy this item";
die;
}

在側面config.php中,我有會話啟動和mysql連接。

表結構

itemslist

itemname, itemprice, image

然后為項目表其項目,屬於,itemimage

從itemslist和它的名稱,然后將其插入thens表中。 但是問題是如果itemprice中有一個數字,比如說12,那么我會回顯它旁邊的一列,即image,並且image將顯示數字2(從priceprice末尾的2開始)

頁面上沒有顯示錯誤。 但是我是否已經說過它的回聲,即在db中,圖像為2嘿。 圖像的列是var,所以不知道為什么它的回顯為2

嘗試使用print_r可以更好地了解$ itemprice變量中的內容。

echo  $itemimage ;
// becomes
print_r $itemimage ;

您正在使用字符串$itemprice['itemprice']覆蓋數組$itemprice 將變量名稱更改為$ iteminfo,它將正常工作。

$iteminfo = mysql_fetch_array($result55);
//...
$itemname = $iteminfo['itemname'] ;
$itemprice = $iteminfo['itemprice'];
$itemimage = $iteminfo['image'] ;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM