Eamon Spillane Eamon Spillane - 4 months ago 7x
PHP Question

Javascript error message not showing in php

First time posting here so be kind!
For some reason when my php script reaches the
if ($beds == 'nopref')
the only way I can get the message to display is with echo $message.
The following line with javascript won't display it like my other pages.
Any ideas?

$beds = $_POST['beds'];
$orientation = $_POST['orientation'];
$checkin = $_POST['checkin'];
$checkout = $_POST['checkout'];
$conn = mysqli_connect("localhost", "user", "password", "name");
die("Connection failed: " . mysqli_connect_error());
if ($beds == 'nopref')
$message = "Please select how many beds you'd like";
echo $message;
echo "<script type='text/javascript'>alert('$message');</script>";


You have broken text because of ' in you'd. Try this:

$message = htmlspecialchars("Please select how many beds you'd like", ENT_QUOTES);