Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

3 Neutral

About HenryCan

  • Rank

Profile Information

  • Gender
    Not Telling
  1. Thank you, mac_gyver and ginerjm. I imitated the approach you suggested and everything is working fine now.
  2. I want the checkboxes to be INITIALLY checked but if the user unchecks some of them before pressing Submit and then I have to redisplay the form to show error messages in other fields, I need to display the ones he unchecked as unchecked when I display the errors. If I just hard-code "checked" in the checkbox description, I don't see how I'm going to uncheck them programmatically and keep them unchecked on the form.
  3. How do I turn a checkbox on or off programatically? My form has several checkboxes that are grouped together and I want them to be turned on initially when the user first sees the form.I can do that very easily by just including "checked" in the HTML for the checkbox. But if the user turns off the checkbox before he presses Submit, I want to make sure I show the ones that are off as off when I redisplay the form as a result of errors in other fields, like textareas. How do I turn the checkbox off or on within my PHP code?
  4. This sample program, which I use as a quick test of my database functionality, may be of some help to you. (I hope my esteemed colleagues on this forum will tell us if they find any major shortcomings to this code; it may not be the best style but it gets the job done.) <?php /* A standalone test file to see if we can connect to the database and read and display a table. */ /* Connect to the database. */ try { $db = new PDO('mysql:host=localhost;dbname=id1556139_topics;charset=utf8', 'id1556139_henry', 'password'); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); } catch (PDOException $excp) { echo "Error getting database connection: " . $excp->getMessage(); die(); } /* Read a simple table and store the data in an array. Display each row as it is fetched. */ $debug = 0; echo "<p>This report lists all members who choose to appear in the fake member directory.\n</p>"; echo "<p>Dashes in the table represent values that are unknown or not applicable. For example, if a comment of a member is not provided, a dash is used to stand in for the unknown value.</p>\n"; echo "<table class='generated'>\n"; echo "<tr class='heading'><th>ID</th><th>Name</th><th>Email</th><th>Phone</th><th>Comment</th></tr>\n"; try { /* Display table loop */ $stmt = $db->query("select id, name, email, phone, ifnull(comment,'-') as comment from Contact_Info_Fake order by id"); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $id = $row['id']; //store the ID from the current row of the Contact_Info table $name = $row['name']; //store the member name from the current row of the Contact_Info table $phone = $row['phone']; //store the phone number from the current row of the Contact_Info table $email = $row['email']; //store the email address from the current row of the Contact_Info table $comment = $row['comment']; //store the comment from the current row of the Contact_Info table if ($debug) { echo "Fetch<br/>"; echo " ID: $id<br/>"; echo " Name: $name<br/>"; echo " Phone: $phone<br/>"; echo " Email: $email<br/>"; echo " Comment: $comment<br/>"; } Write_One_Member($id, $name, $phone, $email, $comment); //write the information for a single meeting } } catch (PDOException $excp) { echo "Error reading table Contact_Info_Fake: " . $excp->getMessage(); } echo "</table>"; exit(0); function Write_One_Member($id, $name, $phone, $email, $comment) { global $debug; if ($debug) { echo "<p>Write_One_Member:<br/>"; echo " ID: $id<br/>"; echo " Name: $name<br/>"; echo " Phone: $phone<br/>"; echo " Email: $email<br/>"; echo " Comment: $comment<br/>"; } echo "<tr><td>$id</td><td>$name</td><td>$phone</td><td>$email</td><td>$comment</td></tr>\n"; } ?> I was going to provide the SQL to create my little test table, Contact_Info_Fake, but it seems phpMyAdmin has dropped the ability to export that information to an external file so I'm going to have to leave that part to your imagination. Ask here if you need more information about that or any aspect of my PHP code.
  5. I've just ported a system I wrote a few years back into PHP into a new environment that has PHP 7.1.4 instead of PHP 5.x. My programs used to work perfectly but are now throwing errors, many of which I've never seen before. I am not a fluent PHP programmer although I have programmed in a variety of languages, including Java, so I'm not new to programming by any means. I was reading a short tutorial about PHP error handling and they suggested writing an error-handling function and invoking it as follows: //Error handler function function customError($errno, $errstr, $errfile, $errline, $errcontext) { echo "<b>Error:</b> [$errno] $errstr<br>"; echo "<b>File/Line:</b> $errfile/$errline<br>"; //echo "<b>Error context:</b><br>"; //print_r($errcontext); echo "....Ending Program"; die(); } //Set error handler set_error_handler("customError",E_ALL); I did that and got this: Error: [8] Undefined index: report_layout File/Line: /storage/h13/139/1556139/public_html/SideTrekkedContributions.php/28 In the first line of that, am I correct in assuming that the [8] denotes the severity level of the error, specifically E_NOTICE, which is defined as "Run-time notices. The script found something that might be an error, but could also happen when running a script normally."? Or is the 8 uniquely associated with an "Undefined index" error in a world where every distinct error has a specific number associated with it, like 37 for division by zero and 412 for array index out of bounds? I think it must be the former and that there will be all kinds of errors that have the number 8 but my knowledge of PHP is sketchy so I want to be sure. Now, assuming I'm right and that 8 is the severity of the error, what should one normally do with E_NOTICE errors? Ideally, I'd like PHP not to display this message and I'd like to get rid of the message by doing whatever I need to do to prevent PHP from thinking there's anything wrong (as opposed to telling it not to show me errors below a certain severity). In this particular case, the line of code identified as the source of the error is this: switch($_POST['report_layout']) { I'm darned if I can see what's wrong with this. I never got an error of any kind about this code on the old system. But maybe the old system wanted to show me messages like this but had minor errors suppressed; I really don't know. I tried initializing that variable to null $report_layout = null; but that did NOT keep the error from appearing. I'm at a loss how to satisfy PHP that the variable has been appropriately initialized so it doesn't have to tell me that there's an undefined index. Can anyone enlighten me on the points I've raised?
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.