Hi all,

Just wondering if anybody can spot the syntax error with the below.

'<button type="button" onclick="window.location=\'bookview.php?id='. $row['bookingref'].'&hn'. $row['hotelname'].'\'">Book Now</button>'

It works fine when I just append one row to the URL like this

'<button type="button" onclick="window.location=\'results.php?id='. $row['proposalid'] . '\'">Book Now</button>'

The button only stops workin when I append the second 'hotelname' row.

Think its just a syntax error but I cant manage to spot it.

Any suggestions would be much appreciated.

Recommended Answers

All 7 Replies

Hi pritaeas

Oh sorry I should have said in my post.

When I click on the button it doesnt call bookview.php, it doesnt call any page!

Thanks

Sorry can I also just mention that I made a mistake there in my original post both examples of code I gave should be pointed towards bookview.php and not results.php as I have in my second example.

Not sure, if I put this:

<button type="button" onclick="window.location='bookview.php?id=1&hn'">Book Now</button>

in a test.html file it tries to open bookview.php

Are you missing something else ? Or do you have javascript disabled ?

This works for me, this sent me to:
http://localhost/bookview.php?id=4&hn=victory

<?php 
$row['bookingref'] = "4";
$row['hotelname'] = "victory";
echo '<button type="button" onclick="window.location=\'bookview.php?id='. $row['bookingref'].'&amp;hn='. $row['hotelname'].'\'">Book Now</button>'
	  
?>

Not a window.location. It's wrong ))
window.location.href = '' or window.location.reload(URL);

Thanks for your suggestions guys.

Just resolved this.

The syntax

'<button type="button" onclick="window.location=\'bookview.php?id='. $row['bookingref'].'&hn'. $row['hotelname'].'\'">Book Now</button>'

was fine as was suggested.

The problem was that the value I was appending to the URL had a comma in it.

silly mistake

Thanks again

also, don't forget hn=

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.