Closed ghost closed 6 years ago
seems you have to watch the next video and when he is over with the pages if you have that issue then post it here
Please post code so I can see where the issue may be :-)
Now i have exactly same problem. Can't figure out where is mistake. Here is my code:
` function data_user($dbc, $id){
if (is_numeric($id)){
$cond = "WHERE id = '$id'";
} else {
$cond = "WHERE email = '$id'";
}
$q = "SELECT * FROM users $cond";
$r = mysqli_query($dbc, $q);
$data = mysqli_fetch_assoc($r);
$data['fullname'] = $data['first'].' '.$data['last'];
$data['fullname_reverse'] = $data['last'].', '.$data['first'];
return $data;
} `
`
<div class="col-md-9">
<?php if(isset($message)){
echo $message;
}?>
<form action="index.php" method="post" role="form">
<div class="form-group">
<label for="title">Title:</label>
<input class="form-control" type="text" name="title" id="title" placeholder="Page Title"/>
</div>
<div class="form-group">
<label for="user">User:</label>
<select class="form-control" name="user" id="user">
<option value="0">No user</option>
<?php
$q = "SELECT id FROM users ORDER BY first ASC";
$r = mysqli_query($dbc, $q);
while($user_list = mysqli_fetch_assoc($r)){
$user_data = $data_user($dbc, $user_list['id']);
?>
<!-- <option value="0"><?php echo $user_data['fullname']; ?></option> -->
<option value="<?php echo $user_data['id']; ?>"><?php echo $user_data['fullname']; ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label for="label">Label:</label>
<input class="form-control" type="text" name="label" id="label" placeholder="Page Label"/>
</div>
<div class="form-group">
<label for="header">Header:</label>
<input class="form-control" type="text" name="header" id="header" placeholder="Page Header"/>
</div>
<div class="form-group">
<label for="body">Body:</label>
<textarea class="form-control" name="body" id="body" rows="8" placeholder="Page Body"/></textarea>
</div>
<button type="submit" class="btn btn-default">Save</button>
<input type="hidden" name="submitted" value="1">
</form>
</div> <!-- End of col-md-9 -->
</div> <!-- End of row -->`
@artur2729
Your code is missing the function for the $_GET
parameters, for the page to work you must make it so it redirects to the ID of the page you want to edit, and with that you can get the actual user that had edited it....
URL = http//yoursite.com/admin?page=pages&id=1
will output:
$_GET -> {"page": "pages" , "id": "1"} // It's on Json syntax which is simple. BTW, they're the parameters PHP will interpret in '$_GET'
With that you can easily fetch the page information and then populate the table with it....
And to make the user display the actual user create something like this:
<select class="form-control" name="user" id="user">
<option>No user</option>
<?php
$q = "SELECT id FROM users ORDER BY first ASC";
$r = mysqli_query($dbc, $q);
// '$opened' will be the variable where I'll save the page information fetch from the database thanks to the '$_GET' variable.
if(isset($opened)&&$opened['user']!=null){
$page_u=$opened['user'];
}else{
$page_u=null;
}
while($list_u = mysqli_fetch_assoc($r)){
$data = data_user($dbc, $list_u['id']);
// IMPORTANT -> to call a function you don't have to add a '$' before the name of it, or it will return an error.
?>
<option value="<?php echo $data['id'];?>"<?php ($data['id']==$page_u)?' selected':'';?>><?php echo $data['fullname'];?></option>
<?php } ?>
</select>
IMPORTANT -> to call a function you don't have to add a '$' before the name of it, or it will return an error.
Needed to compress the code for it to fit, sorry if it looks messy.
Noted when creating that code that you call the function with a $
, that's not how you call a function, just use the name.
It should be:
data_user()
Thanks for your reply. It solved the problem.
I am logged in my admin dashboard but but the option "No User" Loads automatically. It used to work but today I cant. I can't access options such us Label, Header and Body.
Please help