Filling html forms with mysql data using php coming up null

旧街凉风 提交于 2019-12-20 07:51:16

问题


I am trying to fill a html form with data being received out of my mysql database. However I cannot set the forms to display on-load the variables being extracted from the database. I would like the form on-load to hold the data last entered into the forms which have been added to the database previously.

    $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>

回答1:


You have syntax error in your mysql query. You have not place field or columns name or (*) for all columns to extract.

Try like this..

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



回答2:


I think the SQL has error:

SELECT FROM character_tbl WHERE character_player

try:

SELECT * FROM character_tbl WHERE character_player


来源:https://stackoverflow.com/questions/34990420/filling-html-forms-with-mysql-data-using-php-coming-up-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!