Jump to content
Larry Ullman's Book Forums

wesmith4

Members
  • Posts

    36
  • Joined

  • Last visited

Everything posted by wesmith4

  1. I have not been able to download style.css to place within the includes folder. Needed for use in chapter 9 for modifying the template. I would appreciate your help. Wes Smith.
  2. This is the parse error message I get when I execute the code from the book. This is from using form.html and <?php # Script 2.4 - handle_form.php #3. I have checked the code several times with the code in the book. I don't know what is wrong. The code in the book must work. What should I do next? Parse error: syntax error, unexpected 'error' (T_STRING) in /srv/disk3/1536036/www/learningpreferences.org/handle_form.php on line 51
  3. www.learningpreferences.org/handle_form.php Can anyone tell me what is wrong with my script? Wes Smith
  4. This link will display by request. I hope this way of sharing is helpful. https://drive.google.com/file/d/0B_8gkRs7wT66VDNqRmtfQWlfdU0/view?usp=sharing Wes Smith
  5. Thanks Larry. MySQL has multiple tables. One table has a column named "GradeEarned". Whoever is doing this is deleting nearly all the data in the column named "GradeEarned". Here is the connection script that is stored in the "includes" folder of the webroot. it is named mysqli_connect.php. I have replaced the password in this script with '???????????????". ===================== <?php # Script: mysqli_connect.php // This file contains the database access information. // This file also establishes a connection to MySQL // and selects the database. // Set the database access information as constants: DEFINE ('DB_USER', '???????????????'); DEFINE ('DB_PASSWORD', '???????????????'); DEFINE ('DB_HOST', '???????????????'); DEFINE ('DB_NAME', '???????????????'); // Make the connection: $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // If no connection could be made, trigger an error: if (!$dbc) { trigger_error ('Could not connect to MySQL: ' . mysqli_connect_error() ); } else { // Otherwise, set the encoding: mysqli_set_charset($dbc, 'utf8'); } ============================== I have not been able to store this connection script outside of the Web documents directory as you suggest in your MySQL and PHP for Dynamic Websites. GoDaddy says they can not grant me acess to such a location. I have removed all user accounts for this site except for my user account. I am not sure that anything can be done? Thank you for considering my issue. Wes smith
  6. I have a MySQL database on www.StylesOfLearning.net that is working well. But a single column in one table of the database is being edited by a non-user. Can anyone suggest how I can make the database secure. It is being hosted on godaddy. Wes
  7. Yes, and it worked just fine. Here is the script to test if running a query to directly insert into the table: ========================== <?php require ('includes/mysqli_connect.php'); // Check to see if the connection failed. if (mysqli_connect_errno()) { echo "Failed to connect to MySQ:" . mysqli_connect_error(); die(); } mysqli_query($dbc, "INSERT INTO 20140420Attend(person_id) VALUES(199)"); ?> ============= The result was exactly one record was inserted for person_id = 199. Thank you for looking into this with me.
  8. You can see how the script operates for the next several hours by clicking here. This link will not work for very long. Wes Smith
  9. Let me share a little more informatiom: Let me provide a little more information: I find the following six records in the table 20140420Attend after running the script and selecting only three records. Why are the additional three records with person_id being inserted into the table? Everytime I run the script, there is inserted into the table three additional records with person_id=0. Can anyone help me understand why the three additional records with id of zero are added? Any help would be apprecialted. Wes Smith
  10. I have a php script that uses <select> to display all people in a MySQL table, and then want to insert the id of all persons selected into another MySQL table. One use of this would be a way to "select" those people present. The script works, storing record ids into a seperate table. But it also records an id of "0" in addition to the record id. So every selected record is recorded with its unique id, but another record is recorded in the table with = zero! So if 4 records are selected, there will be 4 records inserted with the correct id, and 4 addition records created with id of zero. I have included the php script below, and request assistance to determine what I am doing wrong. Thank you. Wes Smith ============================================= <?php if ($_POST) { $myoptions=$_POST['options']; $selecteditems=count($myoptions); echo '<pre>'; echo htmlspecialchars(print_r($_POST,true)); echo '<pre>'; echo "Number in attendance is " . $selecteditems ; } require ('includes/mysqli_connect.php'); // Check to see if the connection failed. if (mysqli_connect_errno()) { echo "Failed to connect to MySQ:" . mysqli_connect_error(); die(); } ?> <form action="" method="post"> <select multiple name="options[]" size="20"> <?php $query = "SELECT person_id,CONCAT(last_name, ', ',first_name) AS full_name FROM Persons"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) { ?> <option value = "<?php echo $row['person_id'];?>"><?php echo $row['full_name']?></option> <?php } ?> </select> <input type="submit" value="submit me!" /> <?php mysqli_query($dbc, "INSERT INTO 20140420Attend(person_id) VALUES('$myoptions[0])')"); mysqli_query($dbc, "INSERT INTO 20140420Attend(person_id) VALUES('$myoptions[1])')"); mysqli_query($dbc, "INSERT INTO 20140420Attend(person_id) VALUES('$myoptions[2])')"); mysqli_query($dbc, "INSERT INTO 20140420Attend(person_id) VALUES('$myoptions[3])')"); ?> </form> ===========================
  11. Thanks Larry! You said it well. I am seeking a plan that both displays and handles a form, but use a database as the source. I will keep reading, but I am not sure about reading from ?????. Again, Thank you. wes
  12. I am using the structure of Script 3.5 (Calculator.php) to tackle the issue of recording attendance for persons listed in a MySQL database. I am using this structure because I am attempting to create a web page that will handle a form and then display it again. Larry mentions this function on page 86. I plan to use input type="checkbox" name="checkbox[]" value="full_name". The value part is where I am having trouble. I want to select a person's name from a table in the database so that the name will appear on the form on the same line with the checkbox. The page is in two parts, the first part being for php code, and the second part being for the html form. To place on the form a checkbox I need to list a person's name with that input. I can query the database in the php section and fetch from the array of results each person's name. Can anyone suggest where in the code I can fetch the names and then use them in the input for checkboxes? I hope this makes sense. I want to record attendance for all persons in a table who are present at a meeting. I want to list the names of all persons in the table along with a checkbox that can be checked to indicate they were present. I will appreciate any guidance that can be shared to help me in designing a plan to accomplish this. Thank you. Wes (wesmith4@gmail.com)
  13. I am attempting to develop a PHP script to record presence at an event for those persons in a mysql table Persons. I am attempting to use checkboxes to indicate who was present. Here is the script as currently written: <?php # Script require ('includes/mysqli_connect.php'); if(isset($_POST['checkbox'])) {$checkbox = $_POST['checkbox']; if(isset($_POST['activate'])?$activate = $_POST["activate"]:$deactivate = $_POST["deactivate"]); $id = "('" . implode( "','", $checkbox ) . "');" ; echo $id; $q="UPDATE Persons SET present = '".(isset($activate)?'Y':'N')."' WHERE id IN $id" ; $r = mysqli_query($dbc,$q) or die(mysqli_error()); } $q = "SELECT * FROM Persons"; $r = @mysqli_query ($dbc,$q); $count=mysqli_num_rows($r); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns=?http="//www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset="utf-8"" /> <title>Update multiple rows in mysql with checkbox</title> <script type="text/javascript"> <!-- function un_check(){ for (var i = 0; i < document.frmactive.elements.length; i++) { var e = document.frmactive.elements; if ((e.name != 'allbox') && (e.type == 'checkbox')) { e.checked = document.frmactive.allbox.checked; }}} //--> </script> </head> <body> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="frmactive" method="post" action="checkboxes.php"> <table width="400" border="0" cellpadding="3" cellspacing="1"> <tr> <td colspan="5"><input name="activate" type="submit" id="activate" value="Activate" /> <input name="deactivate" type="submit" id="deactivate" value="Deactivate" /></td> </tr> <tr> <td> </td> <td colspan="4"><strong>Update multiple rows in mysql with checkbox</strong> </td> </tr><tr> <td align="center"><input type="checkbox" name="allbox" title="Select or Deselect ALL" style="background-color:#ccc;"/></td> <td align="center"><strong>id</strong></td> <td align="center"><strong>first_name</strong></td> <td align="center"><strong>last_name</strong></td> <td align="center"><strong>present</strong></td> </tr> <?php while ($row = mysqli_fetch_array($r)) { ?> <tr> <td align="center"><input name="checkbox[]" type="checkbox" id="checkbox" id="checkbox[]" value="<? echo $rows['person_id']; ?>"></td> <td><? echo $row['person_id']; ?></td> <td><? echo $row['first_name']; ?></td> <td><? echo $row['last_name']; ?></td> <td><? echo $row['present']; ?></td> </tr> <?php } ?> <tr> <td colspan="5" align="center"> </td> </tr> </table> </form> </td> </tr> </table> </body> </html> The table Persons contains these columns: person_id, first_name,last_name,present. I inserted the echo line after the line defining $id which is copied below: $id = "('" . implode( "','", $checkbox ) . "');" ; echo $id; But $id only contains empty strings. Can anyone help me understand what I am doing wrong? Is $checkbox always ending up empty? Any direction will be appreciated. Wes Smith
  14. Can anyone tell me how to use select tags for drop down lists in PHP? I understand the selection is sent to the server, but I don't know how to access what was selected? Thanks.
  15. Margaux: I tried the INSERT INT0 query both ways: $q = "INSERT INTO Attendance (dateofattendance,fkhh_id,attendees,event,note) VALUES ('$da','$id', '$a','$e','$n')"; $q = "INSERT INTO Attendance (dateofattendance,fkhh_id,attendees,event,note) VALUES ('$da',$id, '$a','$e','$n')"; and also as: $q = "INSERT INTO Attendance (dateofattendance,fkhh_id,attendees,event,note) VALUES ('$da',id, '$a','$e','$n')"; All three assign the number zero to the record row from the Household table. This is the problem. To check on that, I added a few lines of code very early in "register_attendance.php" as follows: // Check for a valid user ID, through GET: if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // From view_households.php $id = $_GET['id']; echo '<p>The household id is <b>' . $id . '</b></p>'; } echo '<p>The household id is <b>' . $id . '</b></p>'; These echo statements do display $id or $_GET['id'] correctly. I have checked this since I do know the number sent from view_households.php. BUT THE INSERT INTO query always inserts a zero for that column. AGH! I have been searching for a solution now for 4 days! It is important that the user NOW PROVIDE the household table id, but will select the household id when they click the "register_attendance.php?id"...... Please know how much I appreciate and value your input! God Bless! Wes
  16. I have confirmed that the correct id is sent to register_attendance.php. But still the INSERT query does not put this number in the attendance table, but does put everthing else. I am including the code here so maybe you can determine what I am doing wrong. ----------------------- <?php # Script 9.5 - register_attendance.php #2 // Check for a valid user ID, through GET: if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // From view_households.php $id = $_GET['id']; echo '<p>The household id is <b>' . $id . '</b></p>'; } echo '<p>The household id is <b>' . $id . '</b></p>'; $page_title = 'Register Attendance'; include ('includes/header.html'); // Check for form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); // Initialize an error array. $da = $_POST['dateofattendance']; // Check for attendees: if (empty($_POST['attendees'])) { $errors[] = 'You forgot to enter the attendees.'; } else { $a = trim($_POST['attendees']); } // check for event: if (empty($_POST['event'])) { $errors[] = 'You forgot to enter the event.'; } else { $e = trim($_POST['event']); } // check for note: if (empty($_POST['note'])) { $errors[] = 'You forgot to enter a note.'; } else { $n = trim($_POST['note']); } if (empty($errors)) { // If everything is OK. // Record the attendance in the table. require ('includes/mysqli_connect.php'); // Make the query: $q = "INSERT INTO Attendance (dateofattendance,fkhh_id,attendees,event,note) VALUES ('$da','$id', '$a','$e','$n')"; $r = @mysqli_query ($dbc, $q); // Run the query. if ($r) { // if it ran OK. //Print a message: echo '<h2>Attendance is recorded.</h2> <p><br /></p>'; echo "hh_id=" . $_SESSION['household']; } else { // If it did not run OK. //Public message: echo '<h2>Attendance was not recorded.</h2> <p><br /></p>'; // Debugging message: echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } // End of if ($r) IF. mysqli_close($dbc); // Close the database connection. // Include the footer and quit the script: include ('includes/footer.html'); exit(); } else { // Report the errors. echo '<h2>Error!</h2> <p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />"; } echo '</p><p>Please try again.</p><p><br /></p>'; }// End of if (empty($errors)) IF. } // End of the main Submit conditional. ?> <h1>Register Attendance</h1> <form action="register_attendance.php" method="post"> <p>Date Of Attendance: <input type="date" name="dateofattendance" size="15" maxlength="20" value="<?php if (isset($_POST['dateofattendance'])) echo $_POST['dateofattendance']; ?>" /></p> <p>Attendees: <input type="text" name="attendees" size="50" maxlength="75" value="<?php if (isset($_POST['attendees'])) echo $_POST['attendees']; ?>" /></p> <p>Event: <input type="text" name="event" size="25" maxlength="25" value="<?php if (isset($_POST['event'])) echo $_POST['event']; ?>" /></p> <p>Note: <input type="text" name="note" size="25" maxlength="25" value="<?php if (isset($_POST['note'])) echo $_POST['note']; ?>" /></p> <p><input type="submit" name="submit" value="register_attendance" /></p> </form> <?php include ('includes/footer.html'); ?> ----------------------------------------------------------- I am making an error in handling the information in the code! But I am at a lost on how to proceed. If you can identify my error, I will be eternally grateful! Wes
  17. Thanks for the recommendation. I tried the following: // Make the query: $q = "INSERT INTO Attendance (dateofattendance,fkhh_id,attendees,event,note) VALUES ('$da','$_GET['hh_id']', '$a','$e','$n')"; $r = @mysqli_query ($dbc, $q); // Run the query. if ($r) { // if it ran OK. //Print a message: echo '<h2>Attendance is recorded.</h2> When I do this all the columns in Attendance are written to a new record in the table, but fkhh_id always received a zero. I don't know what I am doing wrong. Thanks. Wes
  18. I am trying to learn how to use a number sent in a URL from a page on my site. I run a script that allows me go to "register_attendance.php?hh_id=". "hh_id" is the primary key for a record in a database table named household. Then I want to insert a new record in a table named attendance that would contain this number (hh_id) in a column named fkhh_id. But I obviously don't know how to use the INSERT INTO query so that new record will appear in the attendance table with the number (hh_id) in the column named fkhh_id. If anyone can help me understand how to insert the number sent in the URL into a newrecord in another table, WOW! I will appreciate it. I trust you can understand my question, but it is hard to write down in words. Thanks to all Wes Smith
  19. The code based on chapter ten is available through this link. I am attempting to INSERT INTO a database table a record that would contain such items as a date and the key from another table in the MySQL database. In fact, one table is a table of households. The key of a record in the household table is passed to a script to record attendance information of this household in the attendance table. So one column in the attendance table is to contain a key from the household table. The edit_user.php script in Larry's book sends such a key to a script that contains a "select query". I can get that one to work very well. But then I am trying to use the same ideas to send such a unique key to a script that contains a "INSERT INTO" query. I can not get it to work. If anyone has a suggestion about what I am doing wrong, please know that I need your assistance. Thank you. Wes Smith
  20. WOW! Thanks Larry! You will never know how helpful a comment like "be sure that display_errors is enabled" is to a newbie like me! It took me a while to find how to do that. My site is hosted by awardspace.net. He it was not too difficult to find how to edit php.nin. After several attempts to run, I was able to identify my mistake. Thank you! I hope that within a few days I will be running my website with its MySQL database to be used by schools and churches. Again, that you for both your assistance and FOR YOUR BOOK! Wes Smith
  21. I am using material from Chapter 10 to design scripts for recording attendance data for persons listed in a Household table in an additiona table called Attendance. I have two scripts. The first is "view_households.php" and is listed here: <?php # Script 10.1 - view_households.php #3 // This script retrieves all the records from the household table. // This new version links to edit and delete pages. $page_title = 'View the Current Households'; include ('includes/header.html'); echo '<h1>Registered Households</h1>'; require_once ('includes/mysqli_connect.php'); // Define the query: $q = "SELECT last_name,first_name,hh_id FROM Households ORDER BY last_name ASC"; $r = @mysqli_query ($dbc, $q); // Count the number of returned rows: $num = mysqli_num_rows($r); if ($num > 0) { // If it ran OK, display the records. // Print how many Households there are: echo "<p>There are currently $num registered households.</p>\n"; // Table header: echo '<table align="center" cellspacing="3" cellpadding="3" width="75%"> <tr> <td align="left"><b>Register_Attend</b></td> <td align="left"><b>Delete</b></td> <td align="left"><b>Last Name</b></td> <td align="left"><b>First Name</b></td> <td align="left"><b>hh_id</b></td> </tr> '; // Fetch and print all the records: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo '<tr> <td align="left"><a href="register_attendance.php?id=' . $row['hh_id'] . '">Register_Attend</a></td> <td align="left"><a href="delete_user.php?id=' . $row['hh_id'] . '">Delete</a></td> <td align="left">' . $row['last_name'] . '</td> <td align="left">' . $row['first_name'] . '</td> <td align="left">' . $row['hh_id'] . '</td> </tr> '; } echo '</table>'; mysqli_free_result ($r); } else { // If no records were returned. echo '<p class="error">There are currently no registered households.</p>'; } mysqli_close($dbc); include ('includes/footer.html'); ?> Records from Household are displayed from this script. If one clicks the "register_attendance" from the display, a spript "register_attendance.php is called and the records id is passed through the URL. Here is the script for "register_attendance.php": <?php # Script 9.5 - register_attendance.php #2 // This script performs an INSERT query to add a record to the users table. $page_title = 'Register Attendance'; // Check for a valid household ID, through GET or POST: if ( (isset($GET['id'])) && (is_numeric ($_GET['id'])) ) { // From view_households.php $id = $GET['id']; echo '<p>We have the value of $id </p>'; } else {// No valid ID, kill the script. echo '<p class="error">This page has been accessed in error.</p>'; include ('includes/footer.html'); // exit(); } require_once ('includes/mysqli_connect.php'); if (empty($errors)) { // If everything's OK. // Register the user in the database... echo <p>Now on line 11. </p>; // Make the query: $q = "INSERT INTO Attendance (dateofattendance,fkhh_id,attendees,event,note) VALUES ('2013-11-24','$id','NULL','NULL','NULL');" $r = @mysqli_query ($dbc, $q); // Run the query. if ($r) { // If it ran OK. echo '<p> Attendance is recorded on line 18.</p><p><br /></p>'; } else { // If it did not run OK. // Public message: echo '<h1>System Error</h1> <p class="error">You could not record attendance.</p>'; // Debugging message: echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } // End of if ($r) IF. mysqli_close($dbc); // Close the database connection. // Include the footer and quit the script: include ('includes/footer.html'); exit(); } else { // Report the errors. echo '<h1>Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } // End of if (empty($errors)) IF. mysqli_close($dbc); // Close the database connection. ?> <?php include ('includes/footer.html'); ?> ====================== When I click a record displayed from view_households.php, I get a blank screen. In fact, if I attempt to view the "scource" for the page, that is blank also. Can anyone identify what I am doing wrong? One can test this for yourself by putting the following in your browser: "learningpreferences.org/view_households.php" Thank you for your assistance. Again, I am using the contents of Chapter 10 as my guide. Wes Smith
  22. I have an error in user registration in Chapter 18. After registering, activating after receiving email, and then running login.php script, I get the error that the page "....../indes.php" not found on the server. Can anyone help me identify my error. Thanks in advance. Wes Smith wesmith4@gmail.com
  23. Let me add this...... When I run the script "stylesoflearningnet/view_users.php" things seem to work. When I run the script "stylesoflearning.net/pumc/view_households.php" I get the error. Using this subfolder on my website may be causing the error?? I appreciate any advice. Wes Smith
×
×
  • Create New...