简体   繁体   中英

Create clickable URL in PHP

Trying to create a clickable URL in PHP. If you visit www.wheels4rent.net/test00.html and input location and date clicking the 'quote' will take you to the list_car5.php page. At right of this page is a 'book now' button that does not work and the text hyperlink below this. problem is when clicking the text hyperlink instead of giving me the www.thrifty.co.uk URL it gives me www.wheels4rent.net/www.thrifty.co.uk URL which obviously does not display webpage. Please assist. Also i need to also create the text hyperlink within my 'book now' button instead. below is code

$url = (string)$car->book;

echo "<tr><td width=200px><' align='right' style='padding:1px; width:100px'><b>".$car->cartype."</b><br>".$car->carsipp."<br>".$car->transmission."</td><td><b>".$car->carexample."</b></td><td><b>&pound;".$car->price."
</b><br>Unlimited Miles</b><br><a href='$url'><input type='submit' name='Book Now' value='Book Now'><br>book now<br></a></td></tr>"; 
}
echo "</table>";

You need to add http:// to the beginning of the URL in the <a> tag. I can't even read the code you've posted, so that's the only answer I can give.

single quotes doesn't read variables. So you could either write the whole html part in echo or you can simply close the php tag and enter the html code and then continue with your php code

for ex:

    <?php
echo "<input type='submit' value='submit' onclick='<script>window.location('http://www.google.com')</script>'";
?>

or simply:

    <?php
-----//php code here
----
----
?>
<input type="submit" value="submit" onclick="<script>window.location('http://www.google.com')</script>"/>
<?php
------
------
------
?>

Instead of wrapping your in an , use the onclick attribute of the tag.

<input type='submit' name='Book Now' value='Book Now' 
   onclick="javascript:window.location('http://www.thrifty.co.uk')" />
<a href="http://www.thrifty.co.uk">Book Now</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM