Can not get data from database in ECHO

60 Views Asked by At

My edit.php code is stated below, and this is what the outcome is: https://i.stack.imgur.com/TAKoN.png

But what it is supposed to do is, get the information from the username - loggin_session, and show their server details , so they dont have to re-write everything. see: https://i.stack.imgur.com/nOkLa.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

There are 1 best solutions below

4
On BEST ANSWER

$row is undefined in your code. It has to be

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

How can I prevent SQL injection in PHP?

And what's up with that useless '' in every echo?

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

This is enough

echo $row['name'];