Jump to content

chris17

Members
  • Posts

    19
  • Joined

  • Last visited

chris17's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. If you look closely at my code, you ll see that there is a php embedded in the code that i need to retrieve values from my database. How will i come about this. The fields' and the doctors' table are different but related. Thanks a lot.
  2. Ok thanks but how can i do that Sir. This is the little of tried doing: <?php include("includes/database.php"); ?> <!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=iso-8859-1" /> <title>NHIS - Book Appointment</title> <link rel="stylesheet" type="text/css" href="styles/lay_comp.css"> <script type="text/javascript" src="script.js"></script> </head> <body> <div id = "container"> <div id = "header"><a href="">Back to Home</a></div> <div id = "title"><h3>BOOK APPOINTMENT</h3></div> <div id = "content"> <div id = "form_cont"> <form id="form1" name="form1" method="post" action=""> <fieldset> <fieldset class="f1"> <label for="field"><span>Category:</span> <select name="field"> <?php $fields = mysql_query("SELECT * FROM field",$connection); if(!$fields){ die("Error1: " . mysql_error()); } while($row = mysql_fetch_array($fields)){ echo "<option value=\"{$row["field_id"]}\" > {$row["field"]} </option>"; } ?> </select> </label> <?php $fields = mysql_query("SELECT * FROM field",$connection); if(!$fields){ die("Error1: " . mysql_error()); } $row = mysql_fetch_array($fields); $tips = mysql_query("SELECT * FROM doctor WHERE field_field_id = {$row["field_id"]}", $connection); if(!$tips){ die("Error2: " . mysql_error()); } $row2 = mysql_fetch_array($tips); ?> <label for="doctor"><span>Doctor:</span> <select name="doctor"> <script type="text/javascript"> window.onload = InitFrm; function InitFrm(){ document.getElementById("field").selectedIndex = 0; document.getElementById("field").onchange = populateDoc; } function populateDoc(){ <?php "<option value=\"{$row2["doc_id"]}\" > {$row2["Fname"]} </option>"; ?> } </script> </select> </label> <label for="topic"><span>Topic:</span> <input type="text" name="topic" id="topic"/> </label> </fieldset> <div id="comps"> <label for="complaint"><span>Summary of Complaints:</span> <textarea rows="20" cols="40" name="complaint" id="complaint"></textarea> </label> </div> </fieldset> <div> <input id="buttondiv" type="submit" name="submit" value="BOOK"/> </div> </form> </div> </div> </body> </html> Please help me. Thanks
  3. Ok thanks but how can i do that Sir. This is the little of tried doing: <?php include("includes/database.php"); ?> <!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=iso-8859-1" /> <title>NHIS - Book Appointment</title> <link rel="stylesheet" type="text/css" href="styles/lay_comp.css"> <script type="text/javascript" src="script.js"></script> </head> <body> <div id = "container"> <div id = "header"><a href="">Back to Home</a></div> <div id = "title"><h3>BOOK APPOINTMENT</h3></div> <div id = "content"> <div id = "form_cont"> <form id="form1" name="form1" method="post" action=""> <fieldset> <fieldset class="f1"> <label for="field"><span>Category:</span> <select name="field"> <?php $fields = mysql_query("SELECT * FROM field",$connection); if(!$fields){ die("Error1: " . mysql_error()); } while($row = mysql_fetch_array($fields)){ echo "<option value=\"{$row["field_id"]}\" > {$row["field"]} </option>"; } ?> </select> </label> <?php $fields = mysql_query("SELECT * FROM field",$connection); if(!$fields){ die("Error1: " . mysql_error()); } $row = mysql_fetch_array($fields); $tips = mysql_query("SELECT * FROM doctor WHERE field_field_id = {$row["field_id"]}", $connection); if(!$tips){ die("Error2: " . mysql_error()); } $row2 = mysql_fetch_array($tips); ?> <label for="doctor"><span>Doctor:</span> <select name="doctor"> <script type="text/javascript"> window.onload = InitFrm; function InitFrm(){ document.getElementById("field").selectedIndex = 0; document.getElementById("field").onchange = populateDoc; } function populateDoc(){ <?php "<option value=\"{$row2["doc_id"]}\" > {$row2["Fname"]} </option>"; ?> } </script> </select> </label> <label for="topic"><span>Topic:</span> <input type="text" name="topic" id="topic"/> </label> </fieldset> <div id="comps"> <label for="complaint"><span>Summary of Complaints:</span> <textarea rows="20" cols="40" name="complaint" id="complaint"></textarea> </label> </div> </fieldset> <div> <input id="buttondiv" type="submit" name="submit" value="BOOK"/> </div> </form> </div> </div> </body> </html> Please help me. Thanks
  4. Hi Pals. I have a select option named doctor that i need to depend on the another select option named field, just like in Months and days where February shows 29 days in the days select option when clicked. The only difference here is that my data source is from mysql database instead of just html.
  5. I have written none yet. The only php is in the html and it pulls up all the fields in the field table to the select option. What I wish to do is to insert this into my database with respect to the selected option. Thanks
  6. <?php include("includes/database.php"); ?> <!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=iso-8859-1" /> <title>NHIS - Doctors' Registration</title> <link rel="stylesheet" type="text/css" href="styles/reg_doc.css"> </head> <body> <div id = "container"> <div id = "header"><a href="">Back to Home</a></div> <div id = "title"><h3>DOCTOR'S REGISTRATION FORM</h3></div> <div id = "content"> <div id = "form_cont"> <form id="form1" name="form1" method="post" action="create_doctor.php"> <fieldset> <fieldset> <label for="email"><span>Email Address:</span> <input type="text" name="email" id="email"/> </label> <label for="pass"><span>Password:</span> <input type="password" name="pass" id="pass"/> </label> <label for="pass_conf"><span>Confirm Password:</span> <input type="password" name="pass_conf" id="pass_conf"/> </label> </fieldset> <fieldset> <label for="Fname"><span>First Name:</span> <input type="text" name="Fname" id="Fname"/> </label> <label for="Lname"><span>Last Name:</span> <input type="text" name="Lname" id="Lname"/> </label> <label for="Sname"><span>Surname:</span> <input type="text" name="Sname" id="Sname"/> </label> <?php $fields = mysql_query("SELECT * FROM field",$connection); if(!$fields){ die("Error1: " . mysql_error()); } ?> <label for="field"><span>Field:</span> <select name="field"> <?php while($row = mysql_fetch_array($fields)){ echo "<option value=\"{$row["field"]}\" > {$row["field"]} </option>" ; } ?> </select> </label> </fieldset> <fieldset class="f1"> <label for="address"><span>Address:</span> <input type="text" name="address" id="address"/> </label> <label for="dob"><span>DOB:</span> <input type="text" name="dob" id="dob"/> </label> </fieldset> <fieldset> <label for="gender"><span>Gender:</span> <input type="radio" name="gender" value = "Male"/> Male <br/ > <input type="radio" name="gender" value = "Female"/> Female </label> </fieldset> </fieldset> <div> <input id="buttondiv" type="submit" name="submit" value="REGISTER"/> </div> </form> </div> </div> </body> </html> This is the doctors' form. How can i insert into my database?
  7. Thanks for your attention. I just realized i dont have to insert into the two tables instead i would just update the foreign key that is in doctors. But how the form is to be filed is using the field names. I dont know if you can get the picture of what am trying to explain. Thanks once more
  8. I would appreciate any form of help to this problem: I have two tables named doctors and fields with a one to many relationship with the field being the one part and doctors the many part. My form is supposed to insert into the doctors' table and as well select has a select option the chooses from already existing fields in the fields table. The name of my foreign key in the doctors' table is "field_id". How can i this insert in the two tables?
  9. Ok tnx for your attention. For the new_page.php, it shows only the Page Name and Position, it leaves out, Visible and Content with the submit button too. And am not sure if there is a complete transaction b/w the form and the database For the edit_page.php, it has the same issue with new_page.php and secondly an error above the form saying that the variable error and new_page are not defined. Futhermore, an SQL error "Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY position ASC' at line 4". Thanks Boss.
  10. Please how can i create a table on a browser that can be edited and posted back to the database. Just like a data grid view
  11. <?php //File Name: form_functions.php //Form Validation //This is a raw alternative /*if(!isset($_POST['menu_name']) || empty($_POST['menu_name'])){ $error[] = 'menu_name'; } if(!isset($_POST['position']) || empty($_POST['position'])){ $error[] = 'position'; } */ //OR function check_required_field($required_array){ $field_error = array(); //Required fields foreach($required_fields as $fieldname) { if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname]) && ($_POST[$fieldname] != 0)){ $error[] = $fieldname; } } return $field_error; } function check_max_field_length($field_length_array){ $field_error = array(); //Field Length foreach($fields_length_array as $fieldname => $maxlength){ if(strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength){ $error[] = $fieldname; } } return $field_error; } function display_errors($error_array){ echo "<p class=\"errors\">"; echo "Please review the following fields: <br />"; foreach($error as $err) { echo "*" . $err . "<br />"; } echo "</p>"; } ?> <?php //File Name: functions.php /***********************************************************/ /*This file contains all the functions used in this project*/ /**********************************************************/ //3. Perform DB query //error handling for returning query function mysql_prep($value){ /*This function will help me handle issues of having special characters like "" as the values of the insert into query*/ $magic_qotes_active = get_magic_quotes_gpc(); $new_enough_php = function_exists("mysql_real_escape_string"); if ($new_enough_php){ if($magic_qotes_active){$value = stripslashes($value);} $value = mysql_real_escape_string($value); } else { if(!$magic_qotes_active){$value = addslashes($value);} } return $value; } function redirect_to($location = NULL){ if ($location != NULL){ header("Location: {$location}"); exit; } } function confirm_query($result_set){ if(!$result_set){ die("Database query failed: " .mysql_error()); } } //return subjects function get_all_subjects(){ $query = "SELECT * FROM subjects ORDER BY position ASC"; $subject_set = mysql_query($query); confirm_query($subject_set); return $subject_set; } //return pages function get_pages_of_all_subjects($subject_id){ $query = "SELECT * FROM pages WHERE subjects_id1 = {$subject_id} ORDER BY position ASC"; $page_set = mysql_query($query); confirm_query($page_set); return $page_set; } function get_subject_by_id($subject_id){ $query = "SELECT * "; $query .= "FROM subjects "; $query .= "WHERE id = {$subject_id} "; $query .= "LIMIT 1"; $result_set = mysql_query($query); confirm_query($result_set); if ($subject = mysql_fetch_array($result_set)){ return $subject; } else { return NULL; } } function get_page_by_id($page_id){ $query = "SELECT * "; $query .= "FROM pages "; $query .= "WHERE id = {$page_id} " ; $query .= "LIMIT 1"; $result_set = mysql_query($query); confirm_query($result_set); if ($page = mysql_fetch_array($result_set)){ return $page; } else { return NULL; } } function find_selected_page(){ global $sel_subject; global $sel_page; if (isset($_GET['subj'])) { $sel_subject = get_subject_by_id($_GET['subj']); $sel_page = NULL; } elseif (isset($_GET['page'])){ $sel_subject = NULL; $sel_page = get_page_by_id($_GET['page']); } else { $sel_subj = NULL; $sel_page = NULL; } } function navigation ($sel_subject, $sel_page){ $output = "<ul class=\"subjects\">"; $subject_set = get_all_subjects(); //4. Use returned data while($subject = mysql_fetch_array($subject_set)){ $output .= "<li"; if ($subject["id"] == $sel_subject["id"]){ $output .= " class=\"selected\""; } $output .= "><a href=\"edit_subject.php?subj=" .urlencode($subject["id"]). "\">{$subject["menu_name"]}</a></li>"; //5. A loop in a loop: Pages in Subjects $page_set = get_pages_of_all_subjects($subject["id"]); $output .= "<ul class=\"pages\">"; //4 again. Use returned data while($pages = mysql_fetch_array($page_set)){ $output .= "<li"; if($pages["id"] == $sel_page["id"]){ $output .= "class=\"selected\""; } $output .= "><a href=\"content.php?page=".urlencode($pages["id"])."\">{$pages["menu_name"]}</a></li>"; } $output .= "</ul>"; } $output .= "</ul>"; return $output; } ?> <?php // File Name: page_form.php ?> <?php // this page is included by new_page.php and edit_page.php ?> <?php if (isset($new_page)) {$new_page = false;}?> <p>Page Name: <input type="text" name="menu_name" value="<?php echo $sel_page['menu_name']; ?>" id="menu_name" /></p> <p>Position: <select name="position"><?php if (!$new_page){ $page_set = get_pages_of_all_subjects($sel_page['subject_id']); $page_count = mysql_num_rows($page_set); } else { $page_set = get_pages_of_all_subjects($sel_subject['id']); $page_count = mysql_num_rows($page_set)+1; } for($count=1; $count<=$page_count; $count++){echo"<option value=\"{$count}\">{$count}</option>";} ?></select></p> <p>Visible: <input type="radio" name="visible" value="0"<?php if($sel_page['visible'] == 0) {echo " checked";} ?> />No <input type="radio" name="visible" value="0"<?php if($sel_page['visible'] == 1) {echo " checked";} ?> />Yes</p> <p>Content: <br /> <textarea name="content" rows="20" cols="80"> <?php echo $sel_page['content']; ?></textarea> </p> <?php //File Name: new_page.php ?> <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php // make sure the subject id sent is an integer if (intval($_GET['subj']) == 0) { redirect_to('content.php'); } include_once("includes/form_functions.php"); // START FORM PROCESSING // only execute the form processing if the form has been submitted if (isset($_POST['submit'])) { // initialize an array to hold our errors $errors = array(); // perform validations on the form data $required_fields = array('menu_name', 'position', 'visible', 'content'); $errors = array_merge($error, check_required_field($required_fields, $_POST)); $fields_with_lengths = array('menu_name' => 30); $errors = array_merge($error, check_max_field_length($fields_with_lengths, $_POST)); // clean up the form data before putting it in the database $subject_id = mysql_prep($_GET['subj']); $menu_name = trim(mysql_prep($_POST['menu_name'])); $position = mysql_prep($_POST['position']); $visible = mysql_prep($_POST['visible']); $content = mysql_prep($_POST['content']); // Database submission only proceeds if there were NO errors. if (empty($errors)) { $query = "INSERT INTO pages ( menu_name, position, visible, content, subject_id ) VALUES ( '{$menu_name}', {$position}, {$visible}, '{$content}', {$subject_id} )"; if ($result = mysql_query($query, $connection)) { // as is, $message will still be discarded on the redirect $message = "The page was successfully created."; // get the last id inserted over the current db connection $new_page_id = mysql_insert_id(); redirect_to("content.php?page={$new_page_id}"); } else { $message = "The page could not be created."; $message .= "<br />" . mysql_error(); } } else { if (count($errors) == 1) { $message = "There was 1 error in the form."; } else { $message = "There were " . count($error) . " errors in the form."; } } // END FORM PROCESSING } ?> <?php find_selected_page(); ?> <?php include("includes/header.php"); ?> <table id="structure"> <tr> <td id="navigation"> <?php echo navigation($sel_subject, $sel_page, $public = false); ?> <br /> <a href="new_subject.php">+ Add a new subject</a> </td> <td id="page"> <h2>Adding New Page</h2> <?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?> <?php if (!empty($error)) { display_errors($error); } ?> <form action="new_page.php?subj=<?php echo $sel_subject['id']; ?>" method="post"> <?php $new_page = true; ?> <?php include "page_form.php" ?> <input type="submit" name="submit" value="Create Page" /> </form> <br /> <a href="edit_subject.php?subj=<?php echo $sel_subject['id']; ?>">Cancel</a><br /> </td> </tr> </table> <?php include("includes/footer.php"); ?> <?php //File Name: edit_page.php ?> <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php if (intval($_GET['subj']) == 0){ redirect_to("content.php"); } include_once("includes/form_functions.php"); //START FORM PROCESSING //only excute the form processing if the form has been submitted if (isset($_POST['submit'])){ //initialize array to hold errors $error = array(); // perform validation on form data $required_fields = array('menu_name', 'position', 'visible', 'content'); $error = array_merge($error, check_required_fields($required_fields)); $fields_with_length = array('menu_name' => 30); $error = array_merge($error, check_required_fields($required_fields)); //Form Variables $id = mysql_prep($_GET['page']); $menu_name = trim(mysql_prep($_POST['menu_name'])); $position = mysql_prep($_POST['position']); $visible = mysql_prep($_POST['visible']); $content = mysql_prep($_POST['content']); $query = "UPDATE subjects SET menu_name = '{$menu_name}', position = {$position}, visible = {$visible}, content = '{$content}' WHERE id = {$id}"; $result = mysql_query($query); if(mysql_affected_rows() == 1){ //Successful $message = "The Subject was successfully updated"; } else { //Failed $message = "NO Update was made: " . mysql_error(); } } else { //Errors Occured if(count($error)<2){ $message = "There was an error in the form."; } else { $message = "There were " .count($error). " errors in the form."; } } //end : if isset condition ?> <?php find_selected_page(); ?> <?php include("includes/header.php"); ?> <table id="structure"> <tr> <td id="navigation"> <ul class="subjects"> <?php echo navigation ($sel_subject, $sel_page); ?> </ul> </td> <td id="page"> <h2>Edit Page <?php echo $sel_page['menu_name']; ?></h2> <?php if(!empty($message)){echo"<p class=\"message\">".$message."</p>";} ?> <?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?> <?php if (!empty($error)) {display_errors($error);} ?> <form action="edit_page.php?page=<?php echo urlencode($sel_page['id']); ?>" method="post"> <?php include "page_form.php" ?> <input type="submit" name="submit" value="Update Page" /> <a href="delete_page.php?subj=<?php echo urlencode($sel_page['id']); ?>" onClick="return confirm('Are you sure');">Delete Subject</a> </form> <br /> <a href="content.php">Cancel</a> <div style="margin-top:2em; border-top:1px solid #000000;"> <h3>Pages in this subject are: </h3> <ul> <?php $subject_pages = get_pages_of_all_subjects($sel_subject['id']); ?> </ul> </div> </td> </tr> </table> <?php require("includes/footer.php"); ?> <?php // File Name: new_subject.php ?> <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php find_selected_page(); ?> <?php include("includes/header.php"); ?> <table id="structure"> <tr> <td id="navigation"> <ul class="subjects"> <?php echo navigation ($sel_subject, $sel_page); ?> </ul> </td> <td id="page"> <h2>Add Subject</h2> <form action="create_subject.php" method="post"> <p>Subject name: <input type="text" name="menu_name" value="" id="menu_name" /></p> <p> Position: <select name="position"> <?php $subject_set = get_all_subjects(); $subject_count = mysql_num_rows($subject_set); for($count=1; $count<=$subject_count; $count++){echo"<option value=\"{$count}\">{$count}</option>";} ?> </select> </p> <p>Visible: <input type="radio" name="visible" value="0" />No <input type="radio" name="visible" value="1" />Yes</p> <input type="submit" value="Add Subject" /> </form> <br /> <a href="content.php">Cancel</a> </td> </tr> </table> <?php require("includes/footer.php"); ?> Hi everyone, am a newbi and am using the above project to learn. Am halfway the project and am stuck because the files, new_page.php and edit_page.php are not working fine. I would appreciate every effort made to pull me through so as minimize my level of frustration in PHP. Thanks The new_subject.php is working fine and am using functions.php, form_functions.php and page_form.php as include files.
  12. Am a Beginner. Please be easy on me. Thanks

  13. I have this code in my application for form validation. it is working fine but i just copied and applied it in my work, i don't really understand how it works. This is it: $required_fields = array('menu_name', 'position', 'visible'); foreach($required_fields as $fieldname) { if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname]) && ($_POST[$fieldname] != 0)){ $error[] = $fieldname; } } if(!empty($error)){ redirect_to("new_subject.php"); } //Field Length $fields_with_lengths = array('menu_name' => 30); foreach($fields_with_lengths as $fieldname => $maxlength){ if(strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength){ $error[] = $fieldname; } }
  14. Please am a newbie to php. When ever this block is executed, it returns an SQL syntax error as follows "Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= 1 LIMIT 1' at line 1". Please help me am stuck. function get_subject_by_id($subject_id){ $query = "SELECT * "; $query .= "FROM subjects"; $query .= "WHERE id = {$subject_id} "; $query .= "LIMIT 1"; $result_set = mysql_query($query); confirm_query($result_set); if ($subject = mysql_fetch_array($result_set)){ return $subject; } else { return NULL; } } //or function get_page_by_id($page_id){ $query = "SELECT * "; $query .= "FROM pages"; $query .= "WHERE id = {$page_id} " ; $query .= "LIMIT 1"; $result_set = mysql_query($query); confirm_query($result_set); if ($page = mysql_fetch_array($result_set)){ return $page; } else { return NULL; } }
×
×
  • 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.