Reputation: 97
I have two variables declared one in cfg.php
and one is being called from mysql.
I need to join these two to create a button click link. I am stuck here :
In cfg.php
I have
$mainurl = "http://training.com/something/"
the page I am creating this button link has the include cfg.php
.
from mysql the userid is called this way:
$query1 = "SELECT * from WHERE City like 'Paris' Limit 0,50";
$query = $db->query($query1) ;
$hotel = mysql_fetch_row($query, MYSQL_ASSOC);
my button click code is Select
But the link comes up like this
<button onclick="window.location.href =http://training.com/something/106175/overview">Select</button>
and the button click does not work.
Any help will be much appreciated.
To Update..... when I Try the below
<button onclick = "window.location.href =\''.$mainURL.$hotel['userID'].'/overview">Select</button>
I get
<button onclick="window.location.href ='http://training.com/something/105560/overview">Select</button>
Regards, Jai
Upvotes: 0
Views: 169
Reputation: 4275
You need to encode the url in quotes or you can make it a function. Use the code below
<script>
function clicking(){
window.location.href='http://training.com/something/106175/overview';
}
</script>
<button onclick="clicking()">Select</button>
OR
<button onclick="window.location.href='http://training.com/something/106175/overview'">Select</button>
Update why you are closing single quote with the double quote. Use the code below
<button onclick = "window.location.href ="$mainURL.$hotel['userID']/overview">Select</button>
Hope this helps you
Upvotes: 0
Reputation: 1
in cfg.php
<?php
$mainurl = http://training.com/something/
...
?>
in yourfile.php
<?php
include './cfg.php';
...
echo '<input type="button" onclick="window.open(\''.$mainurl.$hotel['EANHotelID'].'\',\'_blank\',\'resizable=yes\')" />';
Upvotes: 0
Reputation: 528
You need to encase the URL within its own set of quotes. Modify your PHP such that it outputs something like
<button onclick="window.location.href='http://training.com/something/106175/overview'">Select</button>
Upvotes: 1