无法从ECHO中的数据库获取数据

时间:2015-06-09 16:31:02

标签: php mysql mysqli

我的edit.php代码如下所示,结果如下:http://i.imgur.com/lt89Wi8.png

但它应该做的是,从用户名--loggin_session获取信息,并显示他们的服务器详细信息,因此他们不必重写所有内容。 见:http://i.imgur.com/fGEsXPq.png

<?php
    $query = "SELECT id, username, name, url, banner, description, sponsor, votes  FROM websites WHERE username = '$login_session'";
    $result = mysql_query($query) OR die($mysql_error());
    $num = mysql_num_rows($result);

    if ($num < 1) {
    $n = FALSE;
    echo '<font color="red">You have no servers to edit, You can add one <a href="add-site.php">here</a></font><br />';
    die();
    } ?>

    <form action="" method="post" name="join_form" class="form-horizontal" role="form" enctype="multipart/form-data" onSubmit="return checkform(this);">
    <div class="form-group ">
    <label for="join_email" class="col-md-1 control-label"><span class="required">*</span>Server Title</label>
    <div class="col-md-5">
      <input name="name" value="<?php echo $_POST['name']; ?>" class="form-control" placeholder="<?php echo ''.$row['name'].''?>" required>
    </div>
    </div>
    <div class="form-group ">
    <label for="join_password" class="col-md-1 control-label"><span class="required">*</span>Website URL</label>
    <div class="col-md-5">
    <input name="url" value="<?php if (isset($_POST['url'])) echo $_POST['url']; ?>" class="form-control" placeholder="<?php echo ''.$row['url'].''?>" required>
    </div>
    </div>
    <div class="form-group ">
    <label for="join_url" class="col-md-1 control-label"><span class="required">*</span>Banner URL</label>
    <div class="col-md-5">
    <input name="banner" value="<?php if (isset($_POST['banner'])) echo $_POST['banner']; ?>" class="form-control" type="text" placeholder="<?php echo ''.$row['banner'].''?>" required>
    </div>
    </div>
    <div class="form-group ">
    <label for="join_title" class="col-md-1 control-label"></label>
    <div class="col-md-5"></div>
    </div>
    <div class="form-group ">
    <label for="join_description" class="col-md-1 control-label"><span class="required">*</span>Descr..</label>
    <div class="col-md-5">
    <textarea cols="50" rows="5" value="<?php if(isset($_POST['description'])) echo $_POST['description']; ?>" name="description" id="description_size" class="form-control" placeholder="<?php echo ''.$row['description'].''?>" required></textarea>
    </div>
    </div>
    <input type="submit" name="submit" value="Add" />
    <input type="hidden" name="submitted" value="TRUE" />
    </form>

1 个答案:

答案 0 :(得分:1)

您的代码中未定义

$row。它必须是

$row=mysql_fetch_assoc($result); // fetch it from the result set

possibly costly calls to GetValues

在每一个回声中,那些无用的东西是什么?

echo ''.$row['name'].''
     ^^              ^^

这就够了

echo $row['name'];