Jump to content
Larry Ullman's Book Forums

wesmith4

Members
  • Posts

    36
  • Joined

  • Last visited

wesmith4's Achievements

Newbie

Newbie (1/14)

0

Reputation

  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.
×
×
  • Create New...