bluethundr Posted December 11, 2009 Share Posted December 11, 2009 Hello again. I am doing yet another example from the O'Reilly book "PHP and MySQL" that isn't rendering. I have removed all of the error suppressing '@' symbols in the script and my php.ini file has the following set: error_reporting = E_ALL display_errors = 1 Other scripts work and are able to access my MySQL database. My phpinfo().php script looks to be okay. But this script for some reason renders as blank. <?php require 'db.inc'; require_once "HTML/Template/ITX.php"; function formerror(&$template, $message, &$errors) { $errors = true; $template->setCurrentBlock("error"); $template->setVariable("ERROR", $message); $template->parseCurrentBlock("error"); } if (!($connection = mysql_connect("localhost", "thatguy", "yahright?"))) die("Could not connect to database"); $firstname = mysqlclean($_POST, "firstname", 50, $connection); $surname = mysqlclean($_POST, "surname", 50, $connection); $phone = mysqlclean($_POST, "phone", 20, $connection); $template = new HTML_Template_ITX("./templates"); $template->loadTemplatefile("example.8-10.tpl", true, true); $errors = false; if (empty($firstname)) formerror($template, "The first name field cannot be blank.", $errors); if (empty($surname)) formerror($template, "The surname field cannot be blank.", $errors); if (empty($phone)) formerror($template, "The phone field cannot be blank", $errors); // Now the script has finished the validation, show any errors if ($errors) { $template->show(); exit; } // If we made it here, then the data is valid if (!mysql_select_db("telephone", $connection)) showerror(); // Lock the table $query = "LOCK TABLES phonebook WRITE"; if (!( mysql_query ($query, $connection))) showerror(); // Find the maximum phonebook_id value that's in use $query = "SELECT max(phonebook_id) FROM phonebook"; if (!($result = mysql_query ($query, $connection))) showerror(); $row = mysql_fetch_array($result); // Set the new value for the primary key $phonebook_id = $row["max(phonebook_id)"] + 1; // Insert the new phonebook entry $query = "INSERT INTO phonebook VALUES ({$phonebook_id}, '{$surname}', '{$firstname}', '{$phone}')"; if (!(@ mysql_query ($query, $connection))) showerror(); // Unlock the table $query = "UNLOCK TABLES"; if (!( mysql_query ($query, $connection))) showerror(); // Show the phonebook receipt header("Location: example.8-5.php?status=T&phonebook_id={$phonebook_id}"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/184799-php-script-will-not-render/ Share on other sites More sharing options...
cags Posted December 11, 2009 Share Posted December 11, 2009 And what do you expect it to display? There is nothing (that I can see) directly in the script you actually provided that outputs. Quote Link to comment https://forums.phpfreaks.com/topic/184799-php-script-will-not-render/#findComment-975606 Share on other sites More sharing options...
PFMaBiSmAd Posted December 11, 2009 Share Posted December 11, 2009 bluethundr, as mentioned in one of the other threads concerning the book/tutorials you are trying to use, the approach of processing information on one page, then redirecting to another page to display the results is a poor one, both for displaying errors and displaying normal expected output. I seriously would not waste any more time with the book, i.e. you need to already have some experience troubleshoot code (or have someone at hand who does) just so that you can get the code to output the expected results. That's not how tutorials are supposed to work. Quote Link to comment https://forums.phpfreaks.com/topic/184799-php-script-will-not-render/#findComment-975623 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.