dsc6517 2012-02-21 11:43
浏览 10
已采纳

Phpmyadmin和mysql显示错误的结果

I'm trying to make a item shop for my rpg I have a table called itemslist with 3 columns itemname, itemprice, image,

So at the moment i have 1 entry in there itemname is Potion itemprice is 1000 and image is hey just to test with.

The image column I'm having problems with. For some reason it is echoing out has 1 and not hey. Even tho in phpmyadmin its hey. All columns are var except for the price.

The problem is if I change the price to 99 it will echo out he image has 9 if i change itemprice to 10 it will echo out the column image has 0. Even tho in the db the column image is hey and the price is 10 it will echo out he price has 10 and the image has 0 on the page for some reason its getting the last number of the price and thinking that is the image column

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;
}

In side config.php I have the session start and mysql connect.

Table structure

itemslist table

itemname, itemprice, image

Then for items table its item ,belongsto,itemimage

from itemslist and the name of it and insert it into then items table. But the problem is if the itemprice has a number in it lets say 12 then i echo out the column next to it which is image and image will show the number 2 ( the 2 from the end of the itemprice)

There are no errors showing on page. But has i have said its echoign out that the image is 2 when in the db its hey. The column for the image is var so do not know why its echoing out has 2

  • 写回答

2条回答 默认 最新

  • douba4824 2012-02-24 18:51
    关注

    You're overwriting the array $itemprice with the string $itemprice['itemprice']. Change the variable name to $iteminfo and it'll work fine.

    $iteminfo = mysql_fetch_array($result55);
    //...
    $itemname = $iteminfo['itemname'] ;
    $itemprice = $iteminfo['itemprice'];
    $itemimage = $iteminfo['image'] ;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码