-2

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>
  • You never bother fetching a row from the database, therefore `$row` is undefined. – Marc B Jun 09 '15 at 16:33
  • and this `OR die($mysql_error()` that will fail. That function is a "function", not a variable. Plus, make sure this isn't failing you `$login_session`. Your query is dependant on that one variable. – Funk Forty Niner Jun 09 '15 at 16:38

1 Answers1

1

$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'];
Community
  • 1
  • 1
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
  • Wondering if they even saw [my comment](http://stackoverflow.com/questions/30737837/can-not-get-data-from-database-in-echo#comment49531922_30737837) under their question. Oh, and you too Hanky ;-) did you spot that? – Funk Forty Niner Jun 09 '15 at 16:42
  • Oneproblem, the decription field isnt being printed out `` – Lauren Taylor Jun 09 '15 at 16:44
  • will print out in palceholder, but NOT in the value – Lauren Taylor Jun 09 '15 at 16:52
  • 1
    Yes Fred is right about that `mysql_error()` issue he points out in his comment. And you don't see a value for textarea because textareas don't have a `value`. Whatever you want in them has to go like `HERE` and not under `value='NOTHERE'` – Hanky Panky Jun 10 '15 at 03:45