Jump to content

webdevdea

Members
  • Posts

    144
  • Joined

  • Last visited

Everything posted by webdevdea

  1. webdevdea

    Json help

    how would i change data type from html to json,
  2. webdevdea

    Json help

    yes I think it is not formatting correctly..
  3. webdevdea

    Json help

    at my link http://dandewebwonders.com/BBProject%204/index.php when you click on players you see the error.. this is what i need to do .. change data type from html to json, fix the controller error, and change it to parse the data.data object. case "listPlayers_Data" : $response = null; $results = array(); $players = new PlayersClass(); foreach ($players -> RetrieveAll() as $row) { $results[] = new PlayerListModel($row -> Id); } $response -> data = $results; echo json_encode($response); break; and a link to the project on github https://github.com/deannariddlespur/bb_Project/blob/master/Controllers/Controller.php
  4. public function saveCreate() { $input = Input::all(); try { $clientsite = new ClientSite; $clientsite->siteName = $input['siteName']; $clientsite->description = $input['description']; $clientsite->launchDate = $input['launchDate']; $clientsite->save(); //ClientSite::whereSiteName($clientsite->siteName)->first(); ClientSite::where('siteName', $clientsite->siteName)->first(); $clientID = $clientsite['clientID'];//getting clientID for use in join query //queries for retrieving features of each group for the selected client $clientFeatures = DB::table('features')->join('clientFeatures', function($join) use($clientID) { $join->on( 'clientFeatures.featureID', '=', 'features.featureID') ->where('clientFeatures.clientID', '=', $clientID); })->get(); $groupIDs = array(); foreach ($clientFeatures as $c) $groupIDs[] = $c->groupID; } catch(\Illuminate\Database\QueryException $e) { return View::make('profiles.clientProfiles')->with('clientsite',$clientsite) ->with('groupIDs',$groupIDs) ->with('clientFeatures',$clientFeatures) ->with('status','<strong>'.$siteName.' Site already exist!</strong>'); ; } } public function show($clientID) { $clientsite = Clientsite::find($clientID); return View::make('clientsite', compact('clientsite')); }
  5. I am new to the Laravel Framework, doing an internship and at the very end.. I need some assistance please with some try catch error, Its supposed to throw an error if the site name is already in the database.. If someone could help me please and thank you .. ``` public function create() { return View::make('edit.create'); } public function edit( $clientsite ) { return View::make('edit.edit', compact('clientsite')); } public function saveCreate() { $input = Input::all(); try { $clientsite = new ClientSite; $clientsite->siteName = $input['siteName']; $clientsite->description = $input['description']; $clientsite->launchDate = $input['launchDate']; $clientsite->save(); //ClientSite::whereSiteName($clientsite->siteName)->first(); ClientSite::where('siteName', $clientsite->siteName)->first(); $clientID = $clientsite['clientID'];//getting clientID for use in join query //queries for retrieving features of each group for the selected client $clientFeatures = DB::table('features')->join('clientFeatures', function($join) use($clientID) { $join->on( 'clientFeatures.featureID', '=', 'features.featureID') ->where('clientFeatures.clientID', '=', $clientID); })->get(); $groupIDs = array(); foreach ($clientFeatures as $c) { $groupIDs[] = $c->groupID; } catch(\Illuminate\Database\QueryException $e) { return View::make('profiles.clientProfiles')->with('clientsite',$clientsite) ->with('groupIDs',$groupIDs) ->with('clientFeatures',$clientFeatures) ->with('status','<strong>'.$siteName.' Site already exist!</strong>'); ; } ``` https://github.com/webdevdea/MyDyn ( i have not pushed these changes because I have an error )
  6. Thank you so much, I am very new to this and learning. I had thought I asked the question right but I guess I didnt.. Im trying to learn and sometimes being a female I get treated like I am stupid.. Im going to try the above sample and see
  7. I have created a sample database for a race. I want to make it so you do not have to update all of the information when update is selected. Link to the project and here is the update.php file How do i get the fields to retain the information that was already entered so that user does not have to put data in every field upon update.. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="description" content="" /> <meta name="keywords" content="" /> <meta name="author" content="" /> <link rel="stylesheet" type="text/css" href="style.css" media="screen" /> <title>Angels 5K & 1 Mile Family Fun Run/Walk </title> <?php include('header.php'); ?> <?php include('nav.php'); ?> <?php include 'connection.php';?> </head> <body> <div id="wrapper"> <fieldset> <form method="post" action=""> <select name="select" id="del"> <option id="0"> --Select your Name--- </option> <?php $aaa=mysql_query("select * from DR_race"); while ($view = mysql_fetch_array($aaa)) { ?> <option id=" <?php echo $view['ID'];?> "> <?php echo $view['LastName'];?> </option> <?php } ?> </select> </fieldset> <br> <br> <br> <?php //<input type="submit" /> save it to later use $D= filter_input(INPUT_POST, "select"); include 'connection.php'; $con=mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase); if (isset($_POST['firstname'])&& isset($_POST['lastname']) && isset($_POST['phone']) && isset($_POST['email']) && isset($_POST['age']) && isset($_POST['size'])) { $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $Phone = $_POST['phone']; $email = $_POST['email']; $age = $_POST['age']; $size= $_POST['size']; } else { $firstname = "(Not entered)"; $lastname = "(Not entered)"; $Phone = "(Not entered)"; $email = "(Not entered)"; $age = "(Not entered)"; $size = "(Not entered)"; } echo <<<_END <body> <form method="post" action=""> <fieldset> Firstname: <input type="text" name="firstname" required/><br><br> LastName : <input type="text" name="lastname" required/><br><br> Phone: <input type="text" name="phone" required /><br><br> E_mail: <input type="text" name="email" required /><br><br> Age: <input type="text" name="age"/ required ><br><br><br> T-shirt size: <input type="text" name="size" required /> <input type="submit" value="update" /> </form> </fieldset> </body> </html> _END; // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_query($con,"UPDATE DR_race SET FirstName='$firstname' , LastName='$lastname' , Phone='$Phone', Email='$email' , Age='$age' , Size='$size' WHERE FirstName='$D' "); //******************************************** ?> </form> <<?php include('footer.php'); ?> </body> </html>
  8. I have the game working but when it pulls up it automatically says the guess is to low try again What do I need to do for the game to pull up and start from scratch without assuming the user has already entered input? Here is the working link to see what I am talking abou t http://dandewebwonders.com/aliendata/phpguessing.php Here is my code <?php $guess=$_POST['guess']; $number= 25; if($guess>$number) { echo "Sorry, your guess is too high, try again"; echo "<form method=\"post\" name=\"guess\"> <input type=\"hidden\" name=\"number\" value=\"$number\"> Pick a number 1 through 50: <input name=\"guess\" type=\"text\"> <input name=\"submit\" type=\"submit\" value=\"Submit Guess\"> </form>"; }elseif($guess <= 15){ echo "Sorry, your guess is too low, try again"; echo "<form method=\"post\" name=\"guess\"> <input type=\"hidden\" name=\"number\" value=\"$number\"> Pick a number 1 through 50: <input name=\"guess\" type=\"text\"> <input name=\"submit\" type=\"submit\" value=\"Submit Guess\"> </form>"; }elseif($guess>15 && $guess<$number){ echo "You are getting Close!"; echo "<form method=\"post\" name=\"guess\"> <input type=\"hidden\" name=\"number\" value=\"$number\"> Pick a number 1 through 50: <input name=\"guess\" type=\"text\"> <input name=\"submit\" type=\"submit\" value=\"Submit Guess\"> </form>"; }elseif($guess==$number) { echo str_repeat("You got it, good guess", 25); echo "<form method=\"post\" name=\"guess\"> <input type=\"hidden\" name=\"number\" value=\"$number\"> Pick a number 1 through 50: <input name=\"guess\" type=\"text\"> <input name=\"submit\" type=\"submit\" value=\"Submit Guess\"> </form>"; } else{ ?><form method="post" name="guess"> <input type="hidden" name="number" value="<?php echo $number; ?>"> Pick a number 1 through 50: <input name="guess" type="text"> <input name="submit" type="submit" value="Submit Guess"> </form> <?php } ?>
  9. I have my code almost working, I am still new with this so if someone could help me understand why this thing is letting you know you win if you choose anything between 20 and 25? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Computer can you guess my number</title> <style type = "text/css"> #footer {font-size:xx-small; text-align:center; clear:right; padding-bottom:20px; } body { background-image:url("img_tree.png"); color: RED;text-align:center } p { color: Blue; text-align:center;} </style> </head> <body> <?php $guess=$_POST['guess']; $number= 25; if($guess>$number) { echo "Sorry, your guess is too high, try again"; echo "<form method=\"post\" name=\"guess\"> <input type=\"hidden\" name=\"number\" value=\"$number\"> Pick a number 1 through 25: <input name=\"guess\" type=\"text\"> <input name=\"submit\" type=\"submit\" value=\"Submit Guess\"> </form>"; }elseif($guess <15){ echo "Sorry, your guess is too low, try again"; echo "<form method=\"post\" name=\"guess\"> <input type=\"hidden\" name=\"number\" value=\"$number\"> Pick a number 1 through 25: <input name=\"guess\" type=\"text\"> <input name=\"submit\" type=\"submit\" value=\"Submit Guess\"> </form>"; }elseif($guess = $number) { echo "You got it, good guess"; echo "You got it, good guess."; $number= 25; echo "<form method=\"post\" name=\"guess\"> <input type=\"hidden\" name=\"number\" value=\"$number\"> Pick a number 1 through 25: <input name=\"guess\" type=\"text\"> <input name=\"submit\" type=\"submit\" value=\"Submit Guess\"> </form>"; } else{ ?><form method="post" name="guess"> <input type="hidden" name="number" value="<?php echo $number; ?>"> Pick a number 1 through 25: <input name="guess" type="text"> <input name="submit" type="submit" value="Submit Guess"> </form> <?php } ?> </body> </html>
  10. I fugured it out, Yes I had just figured that one out.. thank you so much !!!:-)
  11. I cannot understand why my background color is not changing when user selects it ?http://dandewebwonders.com/aliendata/response.php?username=Deanna&background=yellow&submit=Submit+Query <!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>Untitled Document</title> <style type="text/css"> body { background-color: <?= $_GET['color'] ?>; } </style> </head> <body> Hello, <?= $_GET['username'] ?>! </body> </html> <!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>Untitled Document</title> <style type="text/css"> option.red { background-color: red; } option.yellow { background-color: yellow; } option.blue { background-color: blue; } option.orange { background-color: #FF8040; } option.purple { background-color: #800080; } </style> </head> <body> <form action="response.php" method="get"> What is your name? <input type="text" name="username" size="20" /> <select name="background"> <option style="display:none;" selected="selected">color</option> <option class="red" value="red">Red</option> <option class="yellow" value="yellow">Yellow</option> <option class="blue" value="blue">Blue</option> <option class="orange" value="orange">Orange</option> <option class="purple" value="purple">Purple</option> </select> <input type="submit" name="submit" /> </form> </body> </html>
  12. Got my code to work!!!!! On to the next problem lol

  13. echo '<p> <b>'.$row['topictitle'].'</b> '."<a href='". $row['topicdescription'] ."' >".'</p>'; I tried this, and it does not work... any ideas?
  14. Yes I am not understanding how to echo an anchor tag using php when I run my query, I want the results in an anchor tag and cant seem to get it to work..
  15. echo '<p> <b>'.$row['topictitle'].'</b> '.$row['topicdescription'].'</p>' ; Im trying to make the 'topicdescription' a clickable link. I am trying to make my personal pdf library easier to access for my friends, so when they query the database I want it so they can just click on the link to download the material. Please and thank you . I have tried a few different things but nothing works so far. I thought I would just bring it to the experts.
  16. I do not understand. am i not to name the class new? I am so confused <?php class new db { private $DB_HOST = "localhost"; private $DB_USER = "aundie_test"; private $DB_PASSWORD = "pass_word"; private $DB_NAME = "aundie_books"; } ?>
  17. I am running the code and searching the errors, trying to figure out what is wrong, this is my do_search.php this is the error I am getting Call to undefined method db::select_list() in /home3/aundie/public_html/dandewebwonders.com/HeadFirst/do_search.php on line 17 <?php //if we got something through $_POST if (isset($_POST['search'])) { // here you would normally include some database connection include('db.php'); $db = new db($DB_HOST, $DB_USER, $DB_PASSWORD, $DB_NAME); mysql_connect("localhost", "aundie_test", "pass_word") or die(mysql_error()); mysql_select_db("aundie_books") or die(mysql_error()); // never trust what user wrote! We must ALWAYS sanitize user input $word = mysql_real_escape_string($_POST['search']); $word = htmlentities($word); // build your search query to the database $sql = "SELECT title, download FROM test WHERE content LIKE '%" . $word . "%' ORDER BY title LIMIT 10"; // get results $row = $db->select_list($sql); if(count($row)) { $end_result = ''; foreach($row as $r) { $result = $r['title']; // we will use this to bold the search word in result $bold = '<span class="found">' . $word . '</span>'; $end_result .= '<li>' . str_ireplace($word, $bold, $result) . '</li>'; } echo $end_result; } else { echo '<li>No results found</li>'; } } ?>
  18. This is my db.php file class new { private $DB_HOST = "localhost"; private $DB_USER = "stuff"; private $DB_PASSWORD = "stuff"; private $DB_NAME = "stuff"; function __construct() { $connection = mysql_connect($this->DB_HOST, $this->DB_USER, $this->DB_PASSWORD) or die("Could not connect to the database:<br />" . mysql_error()); mysql_select_db($this->DB_NAME, $connection) or die("Database error:<br />" . mysql_error()); } } ?>
  19. Hello I need a little assistance with my code please its saying class db not found here is a link http://dandewebwonders.com/HeadFirst/Library.php Here is my code <?php //if we got something through $_POST if (isset($_POST['search'])) { // here you would normally include some database connection include('db.php'); $db = new db($DB_HOST, $DB_USER, $DB_PASSWORD, $DB_NAME); // never trust what user wrote! We must ALWAYS sanitize user input $word = mysql_real_escape_string($_POST['search']); $word = htmlentities($word); // build your search query to the database $sql = "SELECT title, download FROM test WHERE content LIKE '%" . $word . "%' ORDER BY title LIMIT 10"; // get results $row = $db->select_list($sql); if(count($row)) { $end_result = ''; foreach($row as $r) { $result = $r['title']; // we will use this to bold the search word in result $bold = '<span class="found">' . $word . '</span>'; $end_result .= '<li>' . str_ireplace($word, $bold, $result) . '</li>'; } echo $end_result; } else { echo '<li>No results found</li>'; } } ?> Thank you so much in advance, Im trying to make a searchable library for my pdf books I have in various cloud accounts.
  20. I cannot get it to connect.. something in my code is wrong I do not know if I am putting the database where the username should be or something like that .. I tried it a few different ways and cannot get it to connect
  21. I am in the process of learning.. I am working on some code from my book trying to get my database connected and I must have something mixed up somewhere THIS IS THE CODE I AM REPLACING IT WITH( i have used anonymous usernames and passwords and such) $connect = mysql_connect("localhost","user","password") or die ("Could not connect."); mysql_select_db("databasename") or die ("Could not find database"); $dbname='databasename'; ?> code from book $connect = mysql_connect("mapswidgetsusers.db.3618229.hostedresource.com","mapswidgetsusers","MtM2008yG5") or die ("Could not connect."); mysql_select_db("mapswidgetsusers") or die ("Could not find database"); $dbname='mapwidgetsusers'; ?>
  22. Sorry I have figured this out.. :-) thanks for looking.. stay tuned, i know i will need some help on this big project.
  23. Ok as you all know im still learning after hours of struggling over the sql code, I cannot get it to pull up in php. I have looked over books and sites. I cannot figure out what is wrong with the code. I am getting a 500 error Here is the code if you could give it a once over and see if anything sticks out to you professionals that would be greatly appreciated. $result = mysql_query("SELECT ( d.theCost + r.theCost + n.theCost ) AS TheBIll FROM doctor AS d, account AS a, room AS r, nurse AS n WHERE d.doctorID = a.doctorID AND r.roomID = a.roomID AND n.nurseID = a.nurseID"); echo "<table border='1'> <tr> <th>User Name</th> </tr>"; while($row = mysql_fetch_array($result)){ echo "<tr>"; echo "<td>" . $row['TheBill'] "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?>
  24. I have changed the "s" to an "i" for the emergency contact, I am not sure if BIGINT is an "s" or an "i" also I am not sure if that is what I am supposed to use for phone numbers? I am new to this trying to learn.. anyway I have to do a lunch meeting, I will check back for more advice <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>My Patients</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <h1>My Patients</h1> <p><b>View All Patients</b> </p> <?php // connect to the database include('connectme.php'); // get the records from the database if ($result = $mysqli->query("SELECT * FROM patient ORDER BY patientId")) { // display records if there are records to display if ($result->num_rows > 0) { // display records in a table echo "<table border='1' cellpadding='10'>"; // set table headers echo "<tr><th>Patient ID</th> <th>InfantId</th> <th>RoomNumber</th> <th>FirstName</th> <th>LastName</th> <th>Address</th> <th>Phone</th> <th>Emergency Contact</th> <th></th> <th></th> </tr>"; while ($row = $result->fetch_object()) { // set up a row for each record echo "<tr>"; echo "<td>" . $row->patientId . "</td>"; echo "<td>" . $row->infantPatientid . "</td>"; echo "<td>" . $row->roomNumberId . "</td>"; echo "<td>" . $row->patientFirstname . "</td>"; echo "<td>" . $row->patientLastname . "</td>"; echo "<td>" . $row->patientAddress . "</td>"; echo "<td>" . $row->patientPhone . "</td>"; echo "<td>" . $row->patientEmergencycontact . "</td>"; echo "<td><a href='model.php?patientId=" . $row->patientId . "'>Edit</a></td>"; echo "<td><a href='deletepatient.php?patientId=" . $row->patientId . "'>Delete</a></td>"; echo "</tr>"; } echo "</table>"; } // if there are no records in the database, display an alert message else { echo "No results to display!"; } } // show an error if there is an issue with the database query else { echo "Error: " . $mysqli->error; } // close database connection $mysqli->close(); ?> <a href="model.php">Add New Patient Record</a> </body> </html>
  25. I finally got some of the kinks out, obviously I had my paths crossed lol .. anyway now I need to figure out why all my fields are not showing values, and my update and insert are not working.. Here is the code <? ob_start(); ?> <?php /* Allows the user to both create new model and edit existing model */ // connect to the database include("connectme.php"); // creates the new/edit record form // since this form is used multiple times in this file, I have made it a function that is easily reusable function renderForm( $infantPatientid ='', $roomNumberId = '', $patientFirstname = '', $patientLastname = '', $patientAddress = '', $patientPhone = '', $patientEmergencycontact = '', $error = '', $patientId = '') { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title> <?php if ($patientId != '') { echo "Edit Record"; } else { echo "New Record"; } ?> </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <link rel="stylesheet" type="text/css" href="Styles.css" /> </head> <body> <h1><?php if ($patientId != '') { echo "Edit Record"; } else { echo "New Record"; } ?></h1> <?php if ($error != '') { echo "<div style='padding:4px; border:1px solid pink; color:pink'>" . $error . "</div>"; } ?> <form action="" method="post"> <div> <?php if ($patientId != '') { ?> <input type="hidden" name="patientId" value="<?php echo $patientId; ?>" /> <p>ID: <?php echo $patientId; ?></p><br/> <?php } ?> <strong>InfantPatientid: </strong><input type="text" name="infantPatientid" value="<?php echo $infantPatientid; ?>"/><br/> <strong>roomNumberId: </strong> <input type="text" name="roomNumberId" value="<?php echo $roomNumberId; ?>"/><br/> <strong>patientFirstname: </strong> <input type="text" name="patientFirstname" value="<?php echo $patientFirstname; ?>"/><br/> <strong>patientLastname: </strong> <input type="text" name="patientLastname" value="<?php echo $patientLastname; ?>"/><br/> <strong>patientAddress: </strong> <input type="text" name="patientAddress" value="<?php echo $patientAddress; ?>"/><br/> <strong>patientPhone: </strong> <input type="text" name="patientPhone" value="<?php echo $patientPhone; ?>"/><br/> <strong>patientEmergencycontact: </strong> <input type="text" name="patientEmergencycontact" value="<?php echo $patientEmergencycontact; ?>"/><br/> <p>* required</p> <input type="submit" name="submit" value="Submit" /> </div> </form> </body> </html> <?php } /* EDIT RECORD */ // if the 'id' variable is set in the URL, we know that we need to edit a record if (isset($_GET['patientId'])) { // if the form's submit button is clicked, we need to process the form if (isset($_POST['submit'])) { // make sure the 'id' in the URL is valid if (is_numeric($_POST['patientId'])) { // get variables from the URL/form //ENT_QUOTES - Decodes double and single quotes $patientId = $_POST['patientId']; $infantPatientid = htmlentities($_POST['infantPatientid'], ENT_QUOTES); $roomNumberId = htmlentities($_POST['roomNumberId'], ENT_QUOTES); $patientFirstname = htmlentities($_POST['patientFirstname'], ENT_QUOTES); $patientLastname = htmlentities($_POST['patientLastname'], ENT_QUOTES); $patientAddress = htmlentities($_POST['patientAddress'], ENT_QUOTES); $patientPhone = htmlentities($_POST['patientPhone'], ENT_QUOTES); $patientEmergencycontact = htmlentities($_POST['patientEmergencycontact'], ENT_QUOTES); // check that firstname and addressname are both not empty if ($patientFirstname == '' || $patientLastname == '') { // if they are empty, show an error message and display the form $error = 'ERROR: Please fill in all required fields!'; renderForm($infantPatientid, $roomNumberId, $patientFirstname, $patientLastname, $patientAddress, $patientPhone, $patientEmergencycontact, $error, $id); } else { // if everything is fine, update the record in the database // bind statement string, string, string, integer if ($stmt = $mysqli->prepare("UPDATE patient SET infantPatientid = ?, roomNumberId = ?, patientFirstname = ?, patientLastname = ?, patientAddress = ?, patientPhone = ?, patientEmergencycontact = ? WHERE patientId=?")) { $stmt->bind_param("issssssi", $infantPatientid, $roomNumberId, $patientFirstname, $patientLastname, $patientAddress, $patientPhone, $patientEmergencycontact, $patientId); $stmt->execute(); $stmt->close(); } // show an error message if the query has an error else { echo "ERROR: could not prepare SQL statement."; } // redirect the user once the form is updated header("Location: viewpatient.php"); } } // if the 'id' variable is not valid, show an error message else { echo "Error!"; } } // if the form hasn't been submitted yet, get the info from the database and show the form else { // make sure the 'id' value is valid if (is_numeric($_GET['patientId']) && $_GET['patientId'] > 0) { // get 'id' from URL $patientId = $_GET['patientId']; // get the recod from the database if($stmt = $mysqli->prepare("SELECT * FROM patient WHERE patientId=?")) { $stmt->bind_param("i", $patientId); $stmt->execute(); $stmt->bind_result($patientId, $infantPatientid, $roomNumberId, $patientFirstname, $patientLastname, $patientAddress, $patientPhone, $patientEmergencycontact); $stmt->fetch(); // show the form renderForm($infantPatientid, $roomNumberId, $patientFirstname, $patientLastname, $patientAddress, $patientPhone, $patientEmergencycontact, NULL, $patientId); $stmt->close(); } // show an error if the query has an error else { echo "Error: could not prepare SQL statement"; } } // if the 'id' value is not valid, redirect the user back to the view.php page else { header("Location:viewpatient.php"); } } } /* NEW RECORD */ // if the 'id' variable is not set in the URL, we must be creating a new record else { // if the form's submit button is clicked, we need to process the form if (isset($_POST['submit'])) { // get the form data $infantPatientid = htmlentities($_POST['firstname'], ENT_QUOTES); $roomNumberId = htmlentities($_POST['roomNumberid'], ENT_QUOTES); $patientFirstname = htmlentities($_POST['roomNumberId'], ENT_QUOTES); $patientLastname = htmlentities($_POST['patientLastname'], ENT_QUOTES); $patientAddress = htmlentities($_POST['patientAddress'], ENT_QUOTES); $patientPhone = htmlentities($_POST['patientPhone'], ENT_QUOTES); $patientEmergencycontact = htmlentities($_POST['patientEmergencycontact'], ENT_QUOTES); // check that firstname and addressname are both not empty if ($patientFirstname == '' || $patientLastname == '') { // if they are empty, show an error message and display the form $error = 'ERROR: Please fill in all required fields!'; renderForm($infantPatientid, $roomNumberId, $patientFirstname, $patientLastname, $patientAddress, $patientPhone, $patientEmergencycontact, $error); } else { // insert the new record into the database if ($stmt = $mysqli->prepare("INSERT patient (infantPatientid, roomNumberId, patientFirstname, patientLastname, patientAddress, patientPhone, patientEmergencycontact) VALUES (?, ?, ?, ?, ?, ?, ?)")) { $stmt->bind_param("issssss", $infantPatientid, $roomNumberId, $patientFirstname, $patientLastname, $patientAddress,$patientPhone,$patientEmergencycontact); $stmt->execute(); $stmt->close(); } // show an error if the query has an error else { echo "ERROR: Could not prepare SQL statement."; } // redirec the user header("Location: viewpatient.php"); } } // if the form hasn't been submitted yet, show the form else { renderForm(); } } // close the mysqli connection $mysqli->close(); ?> <? ob_flush(); ?> Here is the LInk http://dandewebwonders.com/project/viewpatient.php
×
×
  • 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.