用mysql数据填充html表单使用php即将出现null

时间:2016-01-25 10:34:23

标签: php html mysql database webserver

我正在尝试填充一个html表单,其数据是从我的mysql数据库中收到的。但是我无法设置表单来加载从数据库中提取的变量。我希望表单在线加载以保存最后输入到先前已添加到数据库的表单中的数据。

    $query = "SELECT FROM character_tbl WHERE character_player 

='".$_SESSION["user"]."' character_tbl";
    $result = mysql_query($query);
while($row = mysql_fetch_array($result)){  
$name = $row['character_name'];
$race = $row['character_race'];
$class = $row['character_class'];
$alignment = $row['character_alignment'];
$hp = $row['character_hp'];
$str = $row['character_str'];
$dex = $row['character_dex'];
$con = $row['character_con'];
$int = $row['character_int'];
$wis = $row['character_wis'];
$cha = $row['character_cha'];
$ac = $row['character_ac'];
$touch = $row['character_touch'];
$flat = $row['character_flat'];
$fort = $row['character_fort'];
$ref = $row['character_ref'];
$will = $row['character_will'];
}

echo $will;
mysql_close();


?>
<!DOCTYPE html>
<html>
<body>

<div id="nav">

<form action="user.php">
    <input type="submit" value="Back">
</form>
</div>

<div id="section">
<form action="update.php" method="POST">
  Character Name:<br>
  <input type="text" name="name" value="<?php echo $name;?>">
  <br>
  Race<br>
  <input type="text" name="race" value="<?php echo $race;?>">
  <br>
  Class<br>
  <input type="text" name="class" value="<?php echo $class;?>">
  <br>
  Alignment<br>
  <input type="text" name="alignment" value="<?php echo $alignment;?>">
  <br>
  HP<br>
  <input type="text" name="hp" value="<?php echo $hp;?>">
  <br>
  STR<br>
  <input type="number" name="str" value="<?php echo $str;?>">
  <br>
  DEX<br>
  <input type="number" name="dex" value="<?php echo $dex;?>">
  <br>
  CON<br>
  <input type="text" name="con" value="<?php echo $con;?>">
  <br>
  INT<br>
  <input type="text" name="int" value="<?php echo $int;?>">
  <br>
  WIS<br>
  <input type="text" name="wis" value="<?php echo $wis;?>">
  <br>
  CHA<br>
  <input type="text" name="cha" value="<?php echo $cha;?>">
  <br>
  AC<br>
  <input type="text" name="ac" value="<?php echo $ac;?>">
  <br>
  Touch AC<br>
  <input type="text" name="touch" value="<?php echo $touch;?>">
  <br>
  Flat-Footed AC<br>
  <input type="text" name="flat" value="<?php echo $flat;?>">
  <br>
  Fortitude<br>
  <input type="text" name="fort" value="<?php echo $fort;?>">
  <br>
  Reflex<br>
  <input type="text" name="ref" value="<?php echo $ref;?>">
  <br>
  Will<br>
  <input type="text" name="will" value="<?php echo $will;?>">
  </br>
  <input type="submit" value="Update">

</form>

2 个答案:

答案 0 :(得分:1)

您的mysql查询中存在语法错误。您没有为要提取的所有列放置字段或列名称或(*)。

试试这样..

$query = "SELECT * FROM character_tbl WHERE character_player ='".$_SESSION['user']."'";

答案 1 :(得分:1)

我认为SQL有错误:

SELECT FROM character_tbl WHERE character_player

尝试:

SELECT * FROM character_tbl WHERE character_player