Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy does the error message not show up?
    primarykey
    data
    text
    <p>I am very new to PHP (only been doing it since September so I apologise if this seems like a silly question, I'm very stuck and can't work out the answer!) and cannot work out why my error message does not display when a user submits the form when it is empty.</p> <p>This is my code:</p> <pre><code> &lt;?php $salonid = ""; if (!$db_server){ die("Unable to connect to MySQL: " . mysqli_connect_error($db_server)); $db_status = "not connected"; }else{ //Capture form data, if anything was submitted if (isset($_GET['salonid']) and ($_GET['salonid'] != '')){ $salonid = clean_string($db_server, $_GET['salonid']); //If connected, get Salons from database and write out mysqli_select_db($db_server, $db_database); $query = "SELECT ID, salon_name, address, postcode, telephone, email, website FROM salon WHERE ID=$salonid"; $result = mysqli_query($db_server, $query); if (!$result) die("Query failed: " . mysqli_error($db_server)); while($row = mysqli_fetch_array($result)){ $str_result .= "&lt;h2&gt;" . $row[ 'salon_name'] . "&lt;/h2&gt;"; $str_result .= "&lt;p&gt;" . $row['address'] . "&lt;/p&gt;"; $str_result .= "&lt;p&gt;" . $row['postcode'] . "&lt;/p&gt;"; $str_result .= "&lt;p&gt;" . $row['telephone'] . "&lt;/p&gt;"; $str_result .= "&lt;p&gt;" . $row['email'] . "&lt;/p&gt;"; $str_result .= "&lt;p&gt;" . $row['website'] . "&lt;/p&gt;"; } mysqli_free_result($result); }else{ $str_result = "&lt;h2&gt;No salon selected&lt;/h2&gt;"; } } echo $str_result; ?&gt; &lt;?php if(trim($_POST['submit']) == "Submit comment"){ //Get any submitted comments and insert $comment = clean_string($db_server, $_POST['comment']); if ($comment != '') { $name=$_FILES['photo']['name']; if ($name = "") $error .= "&lt;p class='error'&gt;You must upload an image!&lt;/p&gt;"; $originalname=$_FILES['photo']['name']; $type=$_FILES['photo']['type']; if ($type=="image/jpeg") $type=".jpeg"; //if true change else if ($type=="image/jpg") $type=".jpg";// if not true check this one else if ($type=="image/png") $type=".png"; $name=uniqid() . $type; $path="images/" . $name; $tempname=$_FILES['photo']['tmp_name']; $size=$_FILES['photo']['size']; //Error checking if ($size &gt;1000000) $error .= "&lt;p class='error'&gt;Your image file is to big, it have to be less than 200 mb&lt;/p&gt;"; if ($error=="") { if (move_uploaded_file($tempname, $path)){ $uploadquery="INSERT INTO comments (comment, imagename, salonID, userID) VALUES ('$comment', '$path', $salonid, ". $_SESSION['userID'].")"; mysqli_query($db_server,$uploadquery) or die ("Insert failed " . mysqli_error($db_server) . " " . $uploadquery); $message= "&lt;h2&gt;Thanks for your comment!&lt;/h2&gt;&lt;p&gt;Your upload was succesful&lt;/p&gt;"; } } } } //Print out existing comment $query = "SELECT * FROM comments JOIN users ON comments.userID = users.ID WHERE salonID=$salonid"; $result = mysqli_query($db_server, $query); if (!$result) die("Database access failed: " . mysqli_error($db_server)); while ($row = mysqli_fetch_array($result)){ $str_comments .="&lt;h2&gt;" . $row['Username'] ."&lt;/h2&gt;"; $str_comments .= "&lt;p&gt;" . $row['comment'] . "&lt;/p&gt;"; $str_comments .="&lt;img src='" . $row['imagename'] ."' /&gt;"; } mysqli_free_result($result); ?&gt; &lt;div id="form"&gt; &lt;table&gt;&lt;form id='review' action='salonpage.php?salonid=&lt;?php echo $salonid; ?&gt;' method='post' enctype='multipart/form-data'&gt; &lt;th&gt;&lt;h2&gt; Do you want to review the service you recieved?&lt;/h2&gt;&lt;/th&gt; &lt;tr&gt;&lt;td&gt;&lt;textarea name="comment" rows="6" cols="40"&gt;Write something here!&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;input type='file' name='photo' accept='image/jpg, image/jpeg, image/png'/&gt;&lt;/td&gt;&lt;/tr&gt; &lt;br/&gt; &lt;tr&gt;&lt;td&gt;&lt;input type='submit' id='submit' name='submit' value='Submit comment' /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/form&gt;&lt;/table&gt; &lt;?php echo $message; echo $str_comments; ?&gt; &lt;/div&gt; &lt;?php mysqli_close($db_server); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload