aşağıdaki sütunları olan user_bio
adında bir tabloya sahip:değişken iki değeri verilmesi
id; 1
age: 30
studying: test
relationship_status: single
username: conor
about_me: test
:
id
age
studying
relationship_status
username
about_me
Şu anda, bu tablo kullanıcıya conor
için bir satır vardır
Conor
olarak oturum açıp bio.php/conor
adresine giderseniz, conor biyografisi düzgün görüntülenecektir. Ancak, Alice
olarak oturum açıp bio.php/alice
'a gidersem, doğru dışında (her kullanıcı için doğru değerle) yaş dışında tanımlanmamış değişken hatalar alıyorum. İşte
<?php
/****************************************/
// Getting data to display on bio page for user
$get_bio = mysqli_query($connect, "SELECT * FROM user_bio WHERE username ='$user'");
$row_returned = mysqli_num_rows($get_bio);
if ($row_returned == 1){
while ($get_bio_data = mysqli_fetch_assoc($get_bio)){
$about_me = $get_bio_data['about_me'];
$age = $get_bio_data['age'];
$studying = $get_bio_data['studying'];
$lang = $get_bio_data['language'];
$rel_status = $get_bio_data['relationship_status'];
/*****************************************/
// change data held by vars
// if no bio for the user exists in the db (no rows in db)s
if ($row_returned == 0){
if ($about_me == ""){
$about_me = "None set..";
} else {
$about_me = $get_bio_data['about_me'];
} // else closed
} // if closed
} // while closed
} // if closed
/*********************************************/
?>
<div id="userposts_panel">
<div class="bio_here">
<p> <b> About me: </b> <?php echo $about_me; ?> </p>
<p> <b> Age: </b> <?php echo $age; ?> </p>
<p> <b> Studying: </b> <?php echo $studying; ?> </p>
<p> <b> Language(s): </b> <?php echo $lang; ?> </p>
<p> <b> Relationship Status: </b> <?php echo $rel_status; ?> </p>
</div>
</div>
username
Alice tekabül veritabanında hiçbir satır olduğu için sanırım, bu hataya neden oluyor. Bu durumda, seçili dizgimi yeniden tanımlamak istiyorum, örneğin, kullanıcı için about_me
varsa, sonra görüntüle, $ about_me eşittir none set
. Ama hala tanımlanmamış hatalar alıyorum?