PHP echo anchor link not working - php

I'm trying to echo a link on a page. It should be a bootstrap button, but it's just coming out as plain text.
This is my code. What am I doing wrong?
echo '<a class="btn btn-info" href='.$url.'>Video Link</a>';

Try this. I have checked it in my localhost and it is working perfectly.
$url = 'https://www.facebook.com/';
echo '<a class="btn btn-info" href='.$url.'>Video Link</a>';
Please let me know if you have any further questions or any problem occurs.

You should wrap the string you are contencating in double quotes, like this
echo '<a class="btn btn-info" href="'.$url.'">Video Link</a>';

href need to be wrapped up with href=""
try -----> href="'.$url.'"

Change this:
echo '<a class="btn btn-info" href='.$url.'>Video Link</a>';
To this:
echo '<a class="btn btn-info" href="'.$url.'">Video Link</a>';

You should not use single quotes inside single quotes so you have to change your code to something like this
echo '<a class="btn btn-info" href="'.$url.'">Video Link</a>';

Related

Syntax error for variable in the php code

I am make a variable to show the display:none; in the php echo code. But my code function cannot work when I've clicked the Delete button. I think this code is errored to put variable style='.$show_display.', maybe the syntax error. Hope anyone can point out which part I am getting error in the code.
if ($is_delete == "1"){
$show_display = "";
}
if ($is_delete == "0"){
$show_display = "display:none;";
}
echo '<a style='.$show_display.' onclick="delete_folder(\'' . md5($rs_wtp['id'].$md5) . '\',1)" class="btn btn-sm btn-primary" data-color-format="hex">Delete</a>';
I've tried to console the error. The error show me like below the picture:
Issue here is with the missing quotes for style attribute. So the echo statement would look like below:
echo '<a style="'.$show_display.'" onclick="delete_folder(\'' . md5($rs_wtp['id'].$md5) . '\',1)" class="btn btn-sm btn-primary" data-color-format="hex">Delete</a>';

Need help passing two php variables through a url to the next page

I'm new to Php but what I need this php code to do is to pass two variables through the URL like this
<td align="center"><a class="btn btn-danger" href="reserve.php?distroid=<?php echo $row["distroid"] echo $row['orderid']; ?>">Place Order</a></td>
When we try and do it with just distroid, it works completely fine. But I'm unsure how to pass both values.
Any help would be appreciated.
EDIT: SOLVED IT THANK YOU FOR THE HELP ALL
Try to add more key for the query string like this :
<td align="center">
<a class="btn btn-danger"
href="reserve.php?distroid=<?php echo $row["distroid"]; ?>&orderid=<?php echo $row['orderid']; ?>">
Place Order
</a>
</td>
Then you can get both distroid and orderid
Try this query string like this :
<td align="center">
<a class="btn btn-danger"
href="reserve.php?distroid=<?php echo $row["distroid"]."&orderid=".$row['orderid']; ?>">
Place Order
</a>
</td>
Then you can get both variable distroid and orderid
Hi you can try this anchor tag, it will work for you:
<a class="btn btn-danger" href="reserve.php?distroid=<?php echo $row['distroid'];
?>&orderid=<?php echo $row['orderid']; ?>">
Place Order
</a>

handling with single quotes in php codeigniter

I want to use html syntax in php and i want to use . instead of <?php ?> my code ig given below ,
$delete='<a class="confirm" onclick="return delete_event(<?php echo $value->id; ?>, '<?php echo base_url() . 'webtv/delete_channels' ?>', '<?php echo current_full_url(); ?>');" href="" ><i class="glyphicon glyphicon-trash text-red del" title="Delete"></i></a>';
Please help me.
<?php
$value = "value_1"; //$value->id;
$baseurl = "base_url"."/webtv/delete_channels"; //base_url()."/webtv/delete_channels";
$fullurl = "current_url"; //current_full_url();
$delete="<a href='#' class='confirm' onclick=\"return delete_event('".$value."','".$baseurl."','".$fullurl."')\" >Click me</a>";
echo $delete;
?>
<script>
function delete_event(var1,var2,var3){
alert(var1+" -- "+var2+" -- "+var3);
}
</script>
You can use sprintf function to solve this issue.
Solution is:
$delete = sprintf('<a class="confirm" onclick="return delete_event(%d, \'%s\',\'%s\');" href="" ><i class="glyphicon glyphicon-trash text-red del" title="Delete"></i>jkhklh</a>', $value->id, base_url() . 'webtv/delete_channels', current_full_url());
I cleaned up your php syntax. I don't quite understand what you're trying to do, but the declaration below should give you an a tag containing what you want (a confirm delete button):
$delete='<a class="confirm" onclick="return delete_event($value->id, '.base_url().'webtv/delete_channels, '.current_full_url().');" href="" ><i class="glyphicon glyphicon-trash text-red del" title="Delete"></i></a>';
If you echo this on your webpage, assuming all of your other links are correct, it should work.

error in embeding html tags in php

<?php
$id=16;
echo '<td><a class="btn btn-primary" href="edit_news.php?id=$id"><i class="fa fa-pencil fa-fw"></i> Edit</a></td>';
?>
I have a search program that performs search via ajaX,whwre i need to embed html tag with php. Search works fine but when i click on edit button the id cant pass on another page. It shows thathttp://localhost/web/edit_news.php?id=$id. But i cant get the id=16. And error shows Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\web\edit_news.php on line 9. what is the error in my code?
Can any one help me to solve this?
you have change "edit_news.php?id=$id" to "edit_news.php?id='.$id.'". Because data in double quotes treated it like string. or you can use single quotes '. like href='edit_news.php?id=$id'.
<?php
$id=16;
echo '<td><a class="btn btn-primary" href="edit_news.php?id='.$id.'"><i class="fa fa-pencil fa-fw"></i> Edit</a></td>';
?>
just change it quote like ' to " and " to '
<?php
$id=16;
echo "<td><a class='btn btn-primary' href='edit_news.php?id=$id'><i class='fa fa-pencil fa-fw'></i> Edit</a></td>";
?>
OR
<?php
$id=16;
echo '<td><a class="btn btn-primary" href="edit_news.php?id='.$id.'"><i class="fa fa-pencil fa-fw"></i> Edit</a></td>';
?>
Change the single quote with double and double with single Like this :
<?php
$id=16;
echo "<td><a class='btn btn-primary' href='edit_news.php?id=$id'><i class='fa fa-pencil fa-fw'></i> Edit</a></td>";
?>

how to use a variable value in anchor's href

<a href="uploads/templates'.$row[0].'/index.php?id=<?php echo $row[0];?>"
class="btn btn-warning">
View
</a>
above is the button and in this button i want to give a path in which folder named templates should be like templates1 ,templates2, templates3. So the numeric value is a variable and 0to be attached with templates so that the folder can open and the index file can be run..so can any one help me with this
<a href="uploads/templates/<?php echo $row[0]; ?>/index.php?id=<?php echo
$row[0];?>" class="btn btn-warning">
View</a>
OR
<?php
echo '<a href="uploads/templates/'.$row[0].'/index.php?id='.$row[0].'"
class="btn btn-warning">
View</a>';
?>
<a href="uploads/templates<?php echo $row[0];?>/index.php?id=<?php echo $row[0];?>" class="btn btn-warning">
View
</a>
If you are writing PHP code inside HTML, you need to wrap your code in <?php ?>.
Your code should be:
<a href="uploads/templates<?php echo $row[0]; ?>/index.php?id=<?php echo $row[0];?>" class="btn btn-warning">
View
</a>

Categories