Note that there are some explanatory texts on larger screens.

plurals
  1. PO$str_result showing up before form is submitted
    primarykey
    data
    text
    <p>I am new to PHP and HTML coding so I'm sorry if this seems very obvious.</p> <p>My problem is: Once a user has logged in and goes to the homepage of my website, before they click submit on the form, the <code>$str_result</code> and <code>$str_comments</code> are showing up.</p> <p>This is my code: </p> <pre><code>&lt;?php //If connected to the database get services names from database and write out DropDownMenu mysqli_select_db($db_server, $db_database); $query = "SELECT ID, Name FROM categories ORDER BY Name"; $result = mysqli_query($db_server, $query); if (!$result) die("Query failed: " . mysqli_error($db_server)); while($row = mysqli_fetch_array($result)){ $str_options .= "&lt;option value= '" . $row[ 'ID'] . "'&gt;"; $str_options .= $row['Name']; $str_options .= "&lt;/option&gt;"; } mysqli_free_result($result); // Your code here to handle a successful verification $str_result = "&lt;h2&gt;Thanks for your search! Services avaliable are:" . $category = clean_string($db_server, $_POST["categories"]) . "&lt;/h2&gt;"; ?&gt; &lt;!--form--&gt; &lt;form method="post" action="nihome.php"&gt;&lt;p&gt;I am searching for&lt;/p&gt; &lt;select name="categories"&gt;&lt;?php echo $str_options; ?&gt;&lt;/select&gt; &lt;br /&gt; &lt;input type="submit" id="submit" name="submit" value="Submit" /&gt; &lt;/form&gt; &lt;?php //Capture form data, if anything was submitted if (isset($_POST['categories']) and ($_POST['categories'] != '')){ $category = clean_string($db_server, $_POST['categories']); // create the SQL query $query = "SELECT salon.ID AS ID, categories.Name as Category, salon.salon_name AS Salon, services.name AS Service, servicesoffered.price AS price FROM services JOIN categories ON services.cID = categories.ID JOIN servicesoffered ON servicesoffered.serviceID = services.ID JOIN salon ON servicesoffered.salonID = salon.ID WHERE categories.ID=$category"; // query the database mysqli_select_db($db_server, $db_database); $result = mysqli_query($db_server, $query); if (!$result) die("Database access failed: " . mysqli_error($db_server)); // if there are any rows, print out the contents while ($row = mysqli_fetch_array($result)) { $str_result .= '&lt;h3&gt;' . $row['Salon'] . ',&lt;/h3&gt;&lt;p&gt;' . $row['Service'] . ", £" . $row['price'] .'&lt;/p&gt;' .&lt;a href="salonpage.php?salonid=' . $row['ID'] .'"&gt;Click here to view or add to salon reviews&lt;/a&gt;'; } if($str_result == "") $str_result = "&lt;h2&gt;No services found&lt;/h2&gt;"; } else { $str_result = '&lt;h2&gt;No service was requested&lt;/h2&gt;'; } mysqli_close($db_server); echo $str_result; echo $str_comments; ?&gt; </code></pre>
    singulars
    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