Chew Chew - 5 months ago 14
PHP Question

How do i solve echo a tag URL

How do i solve the URL ?

i was using echo to call out the a tag. and it run well but the URL include something that are i no understand how do i solve it? and can anyone explain to me? why no URL will have thoes %20%20%

Here is the URL that i echo out

http://localhost/pme/main/directMessageRoom.php?directMessageRoomID=1></a>%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cform%20method=


here is my code

<div class ="direct-message-btn-container ">
<?php

include '../config.php';
if(isset($_SESSION['id'])){
$target = $_GET['user'];
$id = $_SESSION['id'];

$targetusername = mysqli_query($connection,"SELECT username FROM user WHERE id='$target' ")or die(mysqli_error($connection));
$username= mysqli_query($connection,"SELECT username FROM user WHERE id='$id'") or die(mysqli_error($connection));

$dm_sql="SELECT * FROM direct_message_room WHERE user_1_id ='$id' AND user_2_id='$target' OR user_1_id='$target' AND user_2_id='$id'";
$check_direct_message_room = mysqli_query($connection, $dm_sql) or die(mysqli_error($connection));

$check= mysqli_num_rows($check_direct_message_room);

if($check == 0){

$rowUserName=mysqli_fetch_array($username);
$rowTargetUserName=mysqli_fetch_array($targetusername);
$room_name=$rowUserName['username']. ' and ' . $rowTargetUserName['username'];

$direct_message_room_name ="INSERT INTO direct_message_room(`direct_message_room_name`,`user_1_id`,`user_2_id`) VALUES ('$room_name','$id','$target')";

$newDirectMessageRoom = mysqli_query($connection,$direct_message_room_name)or die(mysqli_error($connection));
$direct_message_room_id = mysqli_insert_id($connection);

echo '<a href="directMessageRoom.php?directMessageRoomID='.$direct_message_room_id.'></a>';
}
else{
while($row3 = mysqli_fetch_array($check_direct_message_room)){
echo '<a href="directMessageRoom.php?directMessageRoomID='.$row3['id'].'></a>';
}
}
?>

<form method="post" action="" role="form">
<div class="form-group ">
<input type = "submit" class="btn content-btn btn-direct-message" value="message" name="chat">
</div>
</form>
</div>

Answer

You forgot to close the href attribute (double-quotes):

echo '<a href="directMessageRoom.php?directMessageRoomID='.$row3['id'].'"></a>';
                                                          right here ---^
Comments