954,164 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Small syntax error

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.

debuitls
Newbie Poster
12 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

what is the error ?

pritaeas
Posting Expert
Moderator
5,446 posts since Jul 2006
Reputation Points: 653
Solved Threads: 873
 

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.

debuitls
Newbie Poster
12 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

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 ?

pritaeas
Posting Expert
Moderator
5,446 posts since Jul 2006
Reputation Points: 653
Solved Threads: 873
 

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>'
	  
?>
smartness
Junior Poster
103 posts since Aug 2007
Reputation Points: 7
Solved Threads: 14
 

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

SAMAEL
Newbie Poster
20 posts since Sep 2009
Reputation Points: 10
Solved Threads: 3
 

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

debuitls
Newbie Poster
12 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

also, don't forget hn=

smartness
Junior Poster
103 posts since Aug 2007
Reputation Points: 7
Solved Threads: 14
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You