PHP - Any Obvious Corrections?
I think this code was working before I updated MySQLi coding. Now I am receiving an error: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in....
I haven't gone through all my code, but are there any obvious symptoms to note from the following segment:
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { //do this } }
All else style to be functioning as specified. Thanks
Similar TutorialsHi all - It's gotta be something obvious, but I can't for the life of me how I'm sending output in this file before I send a header redirect. Can anyone see it? <?php //Initialize securimage captcha session_start(); require_once('dbconnect.php'); // initialize db connection to populate email address include_once('../securimage/securimage.php'); $language = $_POST['lang']; include($language . ".php"); //Load language file for feedback. TODO: Maintain separate file for this so the script doesn't need to load so many unused variables? $securimage = new Securimage(); if ($securimage->check($_POST['captcha_code']) == false) { die($contact_bad_captcha); } // pump post vars into local vars and clean them up, assign to session to display on contact completion function lang($language) { //Give hidden post var for language a human name switch ($language) { case en: return "English"; break; case es: return "Español"; break; default: return "Español"; } } $reason = htmlentities($_POST['reason'], ENT_QUOTES); $name = htmlentities($_POST['name'], ENT_QUOTES); $email = htmlentities($_POST['email'], ENT_QUOTES); $phone = htmlentities($_POST['phone'], ENT_QUOTES); $cell = htmlentities($_POST['cell'], ENT_QUOTES); $method = htmlentities($_POST['method'], ENT_QUOTES); $comments = htmlentities($_POST['comments'], ENT_QUOTES); $lang = lang($language); // Query for email addresses $query = "SELECT `description`,`email` FROM contact WHERE `code` = \"" . $reason . "\" AND `language` = \"" . $language . "\""; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $to = $row['email']; $reason = $row['description']; } $subject = "ELP Contact Form Submission From " . $name; $_SESSION['name'] = $name; $_SESSION['email'] = $email; $_SESSION['phone'] = $phone; $_SESSION['cell'] = $cell; $_SESSION['method'] = $method; $_SESSION['comments'] = $comments; // Build the mail object $header = "From: " . $email . "\r\n"; $header .= "Reply-To: " . $email . "\r\n"; $header .= "Bcc: email@address.com\r\n"; $header .= "Content-type: text/html; charset=iso-8859-1\r\n"; $message = "Reason: " . $reason . "<br>"; $message .= "Name: " . $name . "<br>"; $message .= "Email: " . $email . "<br>"; $message .= "Phone: " . $phone . "<br>"; $message .= "Cell: " . $cell . "<br>"; $message .= "Method to contact: " . $method . "<br>"; $message .= "Comments/Questions: " . nl2br($comments) . "<br>"; $message .= "Language: " . lang($language); // Send it after checking that variables are set correctly if (isset($name) && isset($email) && isset($method) && isset($comments) && isset($header) && isset($message)) { mail($to, $subject, $message, $header); header("Location: ../contactcomplete.php?lang=" . $language); // Forward to completion page which displays what was sent } else { echo $contact_general_error; //Unknown error } ?> Code: [Select] Warning: Cannot modify header information - headers already sent by (output started at /home1/supresen/public_html/configs/es.php:1) in /home1/supresen/public_html/configs/email.php on line 67 Thanks for the help! I wish to have a page that will display a form if there aren't already enough registrations in the database. The following it an outline of how it will be: <?php require_once "../scripts/connect_to_mysql.php"; //this works fine // Count how many records in the database (1) $sqlCommand = "SELECT * FROM teams"; (2) $sqlCommand = "SELECT COUNT (*) FROM teams"; (3) $sqlCommand = "SELECT COUNT (id) FROM teams"; $query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); (1) $numRegistrations = mysql_num_rows($query); //Count how many rows are returned from the query above (2) $numRegistrations = $query (3) $numRegistrations = mysql_num_rows($query); mysqli_free_result($query); ?> (Some HTML code, like DOCTYPE, head, start of body tags) <?php if($numRegistrations > 35){ echo "Sorry, registrations for this event is at it's maximum."; }else{ ?> <form blah blah blah> </form> <?php } ?> (end of body and html tag) You'll see above there is (1), (2), (3). These are the main 3 that I've been trying, and they match up the $sqlCommand to the $numRegistrations. What would be the problem with this code? I use wamp server to test, have been using it for ages. Chrome browser to test in. If I remove the database query, the rest of the page will load. With the query in there, only the HTML code up until the database query is parsed, so therefore nothing is display on the page. Please help. Thanks Denno |