Jump to content

Search the Community

Showing results for tags 'sql'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. <h1>View Log</h1> <?php $timezone = "America/Chicago"; date_default_timezone_set($timezone); $today = date("Y-m-d"); ?> <?php $serverName = 'Server\SQLEXPRESS'; $connectionInfo = array('Database'=>'database', 'UID'=>'username', 'PWD'=>'password','ReturnDatesAsStrings'=>true,); $connection = sqlsrv_connect($serverName, $connectionInfo); $query = ' SELECT ForteID FROM database.dbo.Reps ORDER By ForteID'; $result = sqlsrv_query($connection,$query); // Move the data to a simple array to simplify presentation code. $resultAsArray = array(); while ( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC )) { $resultAsArray = $row; } ?> <form method="get" action="getlog.php"> <select> <?php foreach ($resultAsArray as $row): ?> <option value="<?php= $row['ForteID'] ?>"><?php= $row['ForteID'] ?></option> <?php endforeach; ?> </select> <BR> <table> <tr> <td>Start Date:</td> <td><input name="start_date" type="date" value="<?php echo $today;?>" autocomplete="off" required="required"></td> </tr> <tr> <td>End Date:</td> <td><input name="end_date" type="date" value="<?php echo $today;?>" autocomplete="off" required="required"></td> </tr> </table> <br> <input type="submit" name="getLog" value="Get Log"><br><br> <input type="button" value="Back to Form" onclick="window.location.href='index.php';"> <br> </form> </html> My result for the drop down box is nothing. I believe something is wrong with the while ( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC )) Thanks in advance for the help.
  2. I run the code I created and I get this error below. 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 'character, tag, server, type, outfit, url, voice) VALUES ('test','test','test','' at line 1 Below is the code I use <? require_once("funcs.inc"); $character = ($_POST['character']); $tag = ($_POST['tag']); $server = ($_POST['server']); $type = ($_POST['type']); $outfit = ($_POST['outfit']); $url = ($_POST['url']); $voice = ($_POST['voice']); $fields = "(character, tag, server, type, outfit, url, voice)"; $values = "('$character','$tag','$server','$type','$outfit','$url','$voice')"; $query2 = "INSERT INTO `users` $fields VALUES $values"; $result2 = dbquery($query2); if (!$result2) { print ("Submit Failed!"); die; } else { print ("Insert Successfully!"); ?> <meta http-equiv="refresh" content=""> <? } ?>
  3. Hi, I'm working on a new site. And i can't get my code to work properly. I have already made a site with this script and it works just fine, but it will not work on my new site (wordpress with PHP enable). What I need is an alternative to this code (the delete button command): <td><a onclick="return confirmSubmit()" <a href="?slettID=<?php echo $row_persondata2['id']; ?>"><img src="images/Delete-button.bmp" name="Image3" width="45" height="20" border="0" id="Image3" /></a><a href="?slettID=<?php echo $row_persondata2['id']; ?>"></a> <script LANGUAGE="Javascript"> <!-- // Skript for Confirmasjon-delete function confirmSubmit() { var agree=confirm("Er du sikker på at du vil slette denne hendelsen?"); if (agree) return true ; else return false ; } // --> </script> <a href="update.php?oppdaterID=<?php echo $row_persondata2['id']; ?>"><img src="images/Update-button.bmp" width="45" height="20" border="0" /></a></td> </tr> <?php } while ($row_persondata2 = mysql_fetch_assoc($persondata2)); ?> </table> Take a look at my attachment. What i want is a delete button that is asking "are you sure?" and then if i click yes it delete that row from the database. Is there an easy alternative? Thanks!
  4. Could someone tell me what is the query for what im trying to do, for example: i have 2 tables, one is "comments" table and the other is "articles" tables. In the comments table there is a 3 columns (id, title, message) and in the articles table there is 3 columns too(id, title,info) I would like is to get all the data of the column message from the table "comments" but the table "comments" got to have the same title of the column title of the column title of Articles table. I dont no if im beign confusing, im sorry.
  5. Hey I'm creating a small system for a high school project, and I need to be able to control content on the front end from the back end. I've hooked most of it up successfully however now I have a small dilemma. How it works is you edit a "website layout" page, which shows you raw HTML (shown below) and you put in a bb code of "[element=title]" for example, and this is then converted into a function which displays the content of that database entry... These elements are then individually edited. However, I now have the need to display some PHP in elements... For example, as seen below, determining what menu you see depending on your level of access or if you're signed in... BUT... When this get's to the output: My PHP is a string... Any suggestions? Thanks...
  6. I want to list out the cities that are from the SQL statement in rows of 3 but I'm doing something wrong. Can someone check me on this? I want it to look like this: City, State (#) City, State (#) City, State (#) City, State (#) City, State (#) City, State (#) City, State (#) City, State (#) City, State (#) City, State (#) City, State (#) City, State (#) $fquery = mysql_query("SELECT state, city, count(city) as num FROM needs WHERE status='posted' GROUP BY state, city ORDER BY state, city"); echo "<table><tr>"; $i=0; while ($frows = mysql_fetch_array($fquery)) { $fcity = $frows['city']; $fstate = $frows['state']; $fcitycount = $frows['num']; // num is holding your count by city if ($i == 0) { echo "<td><a href='node/browseresults.php?city=$fcity&state=$fstate'>$fcity, $fstate ($fcitycount)</a> $i</td>"; ++$i; } if ($i < 3) { echo "<td></td><td><a href='node/browseresults.php?city=$fcity&state=$fstate'>$fcity, $fstate ($fcitycount)</a> $i</td>"; ++$i; } if ($i == 2) { echo "</tr><tr></tr><tr></tr><tr><td><a href='node/browseresults.php?city=$fcity&state=$fstate'>$fcity, $fstate ($fcitycount)</a> $i</td>"; $i = 0; } } echo "</tr></table>";
  7. I've got the following code below and it works great. It's list all the entrys in the database that meet those specifications and it's sorted by the title of need and the ID. My question is is there a way to put a space between the different titled groups. Right now it looks like this: Title1 Title1 Title1 Title2 Title3 Title3 But I'd like for it to look like this: Title1 Title1 Title1 Title2 Title3 Title3 I'm not sure how to go about it. Thanks for the help! $query = mysql_query("SELECT * FROM needs WHERE status !='hidden' AND status !='denied' AND status !='deleted' AND status !='expired' AND (workerfoldername IS NULL OR workerfoldername='') AND (needsusername='$username' OR workerusername='$username') ORDER BY titleofneed, ID"); echo "<table border='1'><tr><th><center>Title of Need</center></th><th><center> Organization </center></th><th><center>Needs Username</center></th><th><center>Worker Username</center></th><th><center>City, State</center></th></tr>"; while ($rows = mysql_fetch_array($query)) { $id = $rows['ID']; $status = $rows['status']; $firstname = $rows['firstname']; $city = $rows['city']; $state = $rows['state']; $phone = $rows['phone']; $email = $rows['email']; $typeofneed = $rows['typeofneed']; $description = $rows['description']; $workername = $rows['workername']; $workeremail = $rows['workeremail']; $workerphone = $rows['workerphone']; $completiondate = $rows['completiondate']; $needsusername = $rows['needsusername']; $workerusername = $rows['workerusername']; $howmanypeopleneeded = $rows['howmanypeopleneeded']; $howmanypeoplesignedup = $rows['howmanypeoplesignedup']; $titleofneed = $rows['titleofneed']; $theneedsfoldername = $rows['needsfoldername']; $theworkerfoldername = $rows['workerfoldername']; if (($needsusername == $username && $theneedsfoldername == '') || ($workerusername == $username && $theworkerfoldername == '')) { $orgname = $rows['orgname']; $expiredate = $rows['expiredate']; echo " <tr><td>$titleofneed</td><td>$orgname</td><td>$needsusername</td><td>$workerusername</td><td>$city, $state</td><td>view more</td></tr> "; } }
  8. In the code below I'm trying to make it so that when they submit a newfoldername if the username is already in the database it will just add that newfoldername to the NEXT NULL COLUMN. Stumped. Thanks for the help! global $user; $username = $user->name; $newfoldername = $_POST['newfoldername']; $query = "INSERT INTO folders (username, folder1) VALUES ('$username', '$newfoldername') ON DUPLICATE KEY UPDATE (NEXT NULL COLUMN)='$newfoldername'"; mysql_query($query) or die("Query: $query Error: ".mysql_error());
  9. Hey Everybody, The issue I am having is that I would like to declare a varchar to hold a couple comma separated values to use in an in operator. DECLARE @TEST varchar(1000); SET @TEST=' ''test1'', ''test2'' '; to confirm the value is set correctly I run a select on the variable Select @TEST; The result is 'test1','test2' which is what I am looking to place in my where clause: Select * from testTable where col in (@TEST); the result should return rows but nothing is returned. I also tried to use where col =any(@TEST) and it errors. If any one can see the error in my ways I would be grateful. Thank you.
  10. Hi guys Right I have a major headache of a problem. its with regards to the database design of a phrase system for languages for a client of mine. Basically the client has a website with 219 different countries. They want a new section in which they will call phrases. Within this section they want to be able to show a category..... say greetings. When greetings is clicked all of the phrases for greetings in that country come up next to the english version of that word. Let say a users is looking at emergency phrases in france. when they click phrases and then emergency they will see english phrases next to the correct French response the country languages is stored currently in the country table and has a max of 3 language ID's. ok so here is what i have tables Country Languages phrasecat Phrases idcountry idlanguages idphrasecat idphrases country_name lang_name phrasecat_name phrase idlang1 idcountry idlang2 idlanguages idlang3 idphrasecat so from here I have the phrase with the country the phrase is in and the category the phrase belongs to. I dont know where to go from here!!!! I know that every country will have their languages compared to English versions as its an english site but thats it. How do I link 2 phrases together. Whats more if a country has 3 languages. how do I show all three, in order and the english next to it? Im thinking I may need more tables but I cant figure out the design of them. Any thoughts? Any help would be much appreciated Thanks Danny
  11. Im trying to connect to it with this code; <?php mysql_connect("localhost", "root", "root") or die("Error connecting to database: ".mysql_error()); mysql_select_db("playerSearch") or die(mysql_error()); ?> but i get this error; Unknown database 'playersearch' any help?
  12. Hello, I am doing a kind of financial calculator which gives you results about the best alternatives to choose from. I do a sql query to the table having the banks data. After that i create a bunch of variables in php and echo the results. These variables are math operations consisting in sql results variables and user input variables. I know how to order sql results, but the problem is that my criteria of sorting is from the php variables created later (which consist of math oparations between sql and user input variables). I have tried sorting it by sql rows....but the dynamic php variables created later are sometimes negatively related to the sql data....so the result does not always get the same. I have an idea like putting the dynamic php variables in an array/arrays and than sorting them according to one of the php variables. But i have no idea how it can be done. Here is a partial code, just to give you an idea of what i mean. <form method="post" action="calc2.php" /> <input name="ss" class="highlight"/> <input class="highlight" name="nn" size="5" /> </form> <?php if (isset($_POST['ss']) && $_POST['nn']>5) { $target = $_POST['ss']; $result = mysql_query("SELECT * FROM list1 WHERE minimum <= {$target} ORDER BY i_rate DESC LIMIT {$number_result}"); if (mysql_num_rows($result) > 0){ while($row = mysql_fetch_array($result)) { $s = $target-$support+$pu+$pv; // according to this variable i want to sort the results, and $pu, $pv are created from user input, which i don't have it here, $traget is sql output. $s is a mix. } } } ?> PLS HEEELP, i have searched everywhere for this and cennot find nothing about exactly what i want.
  13. Ok, i think this is the best place for this question. I have the following problem that no matter what i do the number doesn't add to the sql variable. $i=interest rate, which is a row in sql database, i need to add 1 to it. The result is 1. Which should have been for example 1.01 if $i=1. Here is the code: $result1 = mysql_query("SELECT interest_rate FROM list1") or die(mysql_error()); $row1 = mysql_fetch_array($result1); $i = $row1['interest_rate']; echo $i . "<br/>"; echo $i+1 . "<br/>"; On echo $i i get the row values. On $i+1 i get only 1 in a column repeated vertically. WHY?? PLSSSSS help!!!!
  14. Hi all, this my first post. I'd like to insert values of checkboxes as a string using a comma as a delimiter. So I have these checkboxes: <input type="checkbox" class="checkbox" name="box[]" value="1">One</input> <input type="checkbox" class="checkbox" name="box[]" value="2">Two</input> <input type="checkbox" class="checkbox" name="box[]" value="3">Three</input> Then I'd have a code like this, which is obviously wrong hence I wrote it for illustration only, it should also have an explode function for the delimiter: if (isset($_POST['box'])) { $newbox = array(); foreach($_POST['box'] as $boxArr){ array_push($newbox, $boxArr); } $query="INSERT INTO boxesTable (boxes) VALUES ('$newbox')"; } Any help would be much appreciated.
  15. Hello i am getting this error message, please help me to correct it : Invalid query: 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 'table (id, name, description, linkdown, pubsite, category, image, os) VALUES ('' at line 1 The code is as follows : <?php /// In order /// you /// information in this file: /// Copyright 2012 /// All rights reserved. include("connect.php"); $name = trim(mysql_real_escape_string($_POST["name"])); $description = trim(mysql_real_escape_string($_POST["description"])); $linkdown = trim(mysql_real_escape_string($_POST["linkdown"])); $pubsite = trim(mysql_real_escape_string($_POST["pubsite"])); $category = trim(mysql_real_escape_string($_POST["category"])); $image = trim(mysql_real_escape_string($_POST["image"])); $os = trim(mysql_real_escape_string($_POST["os"])); $results = mysql_query("INSERT INTO table (id, name, description, linkdown, pubsite, category, image, os) VALUES ('', '$name', '$description', '$linkdown', '$pubsite', '$category', '$image', '$os')"); if($results) { echo "Successfully Added"; } else { die('Invalid query: '.mysql_error()); } ?> <a href="index.php">Back to index</a>
  16. I need help with this php survey script. It's supposed to check and see if there are any usernames that are already in the system and if there are then it just adds the values "voted" and "total" to the existing values that are there. If the username is not in the database it will insert that name and add the values. What I have right now is this: $workerusername=$_POST['workerusername']; $q1=$_POST['question1']; $q2=$_POST['question2']; $q3=$_POST['question3']; $values = $q1 + $q2 + $q3; mysql_query("INSERT INTO survey (username, voted, total) VALUES ($workerusername, $values, '30') ON DUPLICATE KEY UPDATE `voted` = $values + VALUES(`voted`), `total` = 30 + VALUES(`total`)"); What am I doing wrong? My primary key in the database is ID and then I have username, voted, and total as varchar.
  17. I've only been learning php for two weeks so please excuse my ignorance, I would like to store an array of data from a mysql table in a variable to be called as and when its needed in my script. i have written this function and used a vardump just to check wether the function was working: function getquestions($id) { $sql =mysql_query("select text FROM questions WHERE quiz_ID =$id "); while($row = mysql_fetch_array($sql)) { var_dump($row) ; } } ///Actual code $quizid = get_id("quizName", "ID"); $questionid = get_id("questions","quiz_ID"); if ($quizid == $questionid) { $question = getquestions("1"); } BUT my array lists all of my row values twice like this: array(2) { [0]=> string(68) "The ‘Sea Swallow’ is an alternative name for which bird?" ["text"]=> string(68) "The ‘Sea Swallow’ is an alternative name for which bird?" } array(2) { [0]=> string(58) "In which sport would you see a ‘Western Roll’?" ["text"]=> string(58) "In which sport would you see a ‘Western Roll’?" } array(2) { [0]=> string(53) "Who is better known as ‘Herbert Khaury’?" ["text"]=> string(53) "Who is better known as ‘Herbert Khaury’?" } array(2) { [0]=> string(42) "'Diet' is the parliament of which country?" ["text"]=> string(42) "'Diet' is the parliament of which country?" } array(2) { [0]=> string(43) "What is the real first name of Coco Chanel?" ["text"]=> string(43) "What is the real first name of Coco Chanel?" } array(2) { [0]=> string(43) "'The Aztecs' were natives of which country?" ["text"]=> string(43) "'The Aztecs' were natives of which country?" } array(2) { [0]=> string(54) "What was invented by‘O.A. North’ in 1869?" ["text"]=> string(54) "What was invented by‘O.A. North’ in 1869?" } array(2) { [0]=> string(40) "King Zog was the ruler of which country?" ["text"]=> string(40) "King Zog was the ruler of which country?" } I'd appreciate any explanation on how i stop this.
  18. I have an html form that takes a date and send it to an php script: <form action='tupdatecompletiondate.php' method='post'><input type='hidden' name='idtosubmit' value=$id><tr> <td><label>Date:</label></td> <td><input type= 'date' name= 'date' value='Select Date' id='popupDatepicker'></td> </tr><input type='submit' value='Click to Update'></form> I've got it going to this script: $id = $_POST['idtosubmit']; $date = $_POST['date']; $datetoset = date('Y-m-d', strtotime($date)); $sql = "UPDATE needs SET completiondate=$datetoset WHERE ID=$id"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } mysql_close(); Confused as to why it's not working. It takes the date, sends it to the php script, makes it into a format that is accepted by the DATE column, and then puts it in that column....well at least its supposed to.
  19. I have a script that I need some help with. Its a reminder script (posted below). Basically I have a completiondate (which in the database is a varchar...don't know if that makes a difference) that is made up like day, month, year (Ex: 06102012) and I want the script (which is a cron job) to look at todays date and see if it is 2 days before todays date. If it is then I want an email sent. I'm confused on where I'm going wrong. Please help! Thanks. An example would be: Todays date is: 06102012 If completiondate = 2 days before todays date { send email } $todaysdate = date('d/m/Y'); $query = "SELECT completiondate FROM needs WHERE completiondate =($todaysdate, strtotime('-1 days'))"; $result = mysql_query($query); mail('derekshull@gmail.com', 'Important Stuff', 'Hey there.'); ?>
  20. my question now is everything is working like my template and the content all i want is to include keywods description and title for each page different it is giving me headache i have a database name pages it has 6 columns id,name,title,description,keywords ,status.where name=home,about,contact etc <?php // Set document: include ('config/setup.php'); if(!isset($_GET['page'])) { $pg= 'page'; }else{ $pg= $_GET['page']; } ?> <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>help</title> <meta name="description" content="." /> <meta name="keywords" content=" " /> </head> <body> <!-- Header Start --> <div id="logo"> <a class="logo" =pic"> <div class="right"> <?php include('template/right_logo.php');?> </div> </div> <div id="header"> <?php include('template/header.php');?> </div> <!-- Header End --> <!-- Main Start --> <div id="main"> <!-- ### Main Left Start ### --> <div id="left"> <?php //include('content/'.$pg.'.php'); $q="SELECT*FROM pages WHERE name='$pg' "; $r=mysqli_query($dbc,$q); $page= mysqli_fetch_assoc($r); echo '<div class="content_body">'.$page['body'].'</div>'; ?> </div> <!-- ### Main Left End ### --> <!-- ### Main Rigt Start ### --> <div id="right"> <?php include('template/right.php');?> </div> <!-- ### Main Rigt End ### --> <div class="clear"></div> <div id="footer"> <?php include('template/footer.php');?> </div> </div> </div> <!-- Main End --> </body> </html>
  21. Hi all,,, i have to hide a column(LOCATION) that may not be seen for user level 3 or below i have like this ID Name Location Sex , , , | | | | | | | | how to do it ,,, any one would like to help me please ??? Thank you ,,,
  22. I have a problem in connecting the wampp localhost to sql server , There is a lan network that it`s server is windows server 2008 with sql server 2008 , I want to connect to this sql by php in a client with windows 7 , but when I run mssql_connect function It shows that coudlent connect to this IP , It shows Reply when I ping server IP . Do I have to change anything in wampp or php application in localhost ? It is php 5.3 the latestversion of wampp . Other programmers can connect to this sql by C sharp and Delphi , Only me cant access that by php I use VmWare also , and install windows server 2008 and sql server 2008 , and create network between win7 and windows server by NAT , even in this way I cant access to sql by php , but there is reply in pinging servers IP .
  23. I am creating a scheduling script in PHP from a mySQL database. My problem can be explained with the following example. I have 10 appointment cells in day x (0-9). Each appointment cell has an adjacent corresponding cell to describe whether the appointment is available or not (either 0 or 1...and call this NID). I will need to identify whether appointment t, t+1, t+2 and t+3 are all available. In other words, some appointments will require multiple time slots. How can I filter through the dumped sql data with PHP by looking at the NID and checking whether t, t+1, t+2, t+3 are available? I've tried enumerating the time slots and putting them in arrays but can't figure this one out. Thanks for any ideas
  24. <body> <div class="header"> <?php include('navbar.php'); ?> </div> <div class="container"> <div class="row mt-4"> <div class="col-sm-3"> <p>Patient Name :</p> </div> <div class="col-sm-3"> <p><?php echo $_POST['name']; ?></p> </div> </div> <div class="row" id="fir"> <div class="col-sm-3"> <p>UHID :</p> </div> <div class="col-sm-3"> <p><?php echo $_POST['id']; ?></p> </div> </div> <?php $_SESSION['p_name'] = $_POST['name']; $_SESSION['p_id'] = $_POST['id']; ?> <form action="personal_medical_record_download.php" method="POST"> <div class="form-header mt-4 text-center">Medical Record</div> <div class="card"> <div class="card-header"> <h2>Any Allergies</h2> </div> <div class="card-body"> <?php $uhid = $_SESSION['p_id']; $conn = mysqli_connect("127.0.0.1", "root", "iMpAcTHeaLTH7%", 'threephih'); $query = " Select * from allergies where uhid = '$uhid' "; $query_res = mysqli_query($conn, $query); while ($query_run = mysqli_fetch_array($query_res)) { ?> <div class="form-group"> <label for="1">1. Are you allergic to any substance?</label> <p style="margin-left: 25px"><?php echo $query_run['ques_1']; ?></p> </div> <div class="form-group"> <label for="2">2. What happened to you when you took this substance?</label> <p style="margin-left: 25px"><?php echo $query_run['ques_2']; ?></p> </div> <div class="form-group"> <label for="3">3. When was this reaction?</label> <p style="margin-left: 25px"><?php echo $query_run['ques_3']; ?></p> </div> <div class="form-group"> <label for="4">4. Since when have you taken that substance?</label> <p style="margin-left: 25px"><?php echo $query_run['ques_4']; ?></p> </div> <div class="form-group"> <label for="5">5. Any other kind of allergies?</label> <p style="margin-left: 25px"><?php echo $query_run['ques_5']; ?></p> </div> <?php } ?> </div> </div> <div class="submit-button mt-4 text-center"> <button type="submit" value="Pdf" name="pdf">PDF</button> </div> </form> </div> </body> I'm trying to show that "No records" message when there are no data in sql table but if there is data then go to the pdf page. please help me
  25. <?php //updateemployee.php session_start(); //Resume session if(isset($_SESSION['name'])){// If $_SESSION['name'] not set, force redirect to home page $name = $_SESSION['name']; $status_msg=""; if (isset($_GET['data'])){ $data = $_GET['data']; if(isset($_GET['update'])){ if(isset($_GET['name']) && isset($_GET['email'])&& isset($_GET['gender']) && isset($_GET['faculty'])){ if(!empty($_GET['name']) && !empty($_GET['email'])&& !empty($_GET['gender']) && !empty($_GET['faculty'])){ //$data = $_GET['data']; $new_name = $_GET['name']; $new_email = $_GET['email']; $new_gender = $_GET['gender']; $new_school = $_GET['faculty']; $conn= connectDB(); $status_msg=updateRecord($new_name,$new_school,$new_gender,$conn,$new_email,$data); echo $new_name; echo $new_school; echo $new_gender; echo $new_email; echo $data; }else{ $status_msg="<h2 style='color:red;'>Incomplete Input. Please try again</h2>"; } } } }}else{ header('Location: index.php'); } if(isset($_GET['logout'])){ session_destroy(); header('Location: index.php'); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> </head> <body> <?php if(isset($_GET['data'])){ $data = $_GET['data']; echo $data;//To test if the Id matches the profile that needs to be updated } $status_msg = ""; function connectDB(){//Function to connect to database $servername = "localhost"; $username = "root"; $password = ""; $db= "staff_db"; $conn = mysqli_connect($servername,$username,$password,$db); if(!$conn){ die('Connection Failed: '.mysqli_connect_error()); } return $conn; } //$sql = "SELECT * FROM staff_table WHERE staff_id='$data'"; $conn = connectDB(); function updateRecord($new_name,$new_gender,$new_school,$conn,$new_email,$data){ $sql = "UPDATE staff_table SET name='$new_name',gender='$new_gender',school='$new_school',email='$new_email' WHERE staff_id='$data'"; if (mysqli_query($conn,$sql)){ $status_msg="<h3 style= 'color:green;'>Account details are successfully updated.</h3>"; }else{ $status_msg= "ERROR: Could not execute SQL".mysqli_error($conn); } mysqli_close($conn); return $status_msg; } ?> <h1>Update Staff Profile</h1> <form action="UpdateEmployee.php" method="GET"> <fieldset> <legend>Personal Information</legend> <p><span class="error">* required field</span></p> <label for="name">Full Name: <input type="text" id="name" name="name"><span class="error">*</span></label><br> <label for="sID">Staff ID: <input type="text" id="sID" name="sID" placeholder="<?php echo $data;?>" disabled="disabled"></label><br> <label for="email">Email: <input type="text" id="email" name="email"><span class="error">*</span></label><br> <label for="gender">Gender:</label> <select id="gender" name="gender"> <option value = "-1" selected>[Gender]</option> <option value = "Male">Male</option> <option value = "Female">Female</option> </select><br> <label for="faculty">School/Faculty</label> <select id="faculty" name="faculty"> <option value = "-1" selected>[School/Faculty]</option> <option value = "SFS">SFS</option> <option value = "FBDA">FBDA</option> <option value = "FECS">FECS</option> </select><br> <p><input type="submit" name="update" value="Update Staff"></p> <p><?php echo $status_msg;?></p> </fieldset> </form> <footer> <p><a href="MainMenu.php">Main Menu</a></p> <p><a href="">Logout</a></p> </footer> </body> </html> <?php //displayemployeeinf.php session_start(); //Resume session if(isset($_SESSION['name'])){// If $_SESSION['name'] not set, force redirect to home page $name = $_SESSION['name']; }else{ header('Location: index.php'); } if(isset($_POST['logout'])){ session_destroy(); header('Location: index.php'); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Display Employee Information</title> </head> <body> <h1>Staff Profile</h1> <div class="display"> <fieldset> <legend>Employees Information</legend> <?php function connectDB(){//Function to connect to database $servername = "localhost"; $username = "root"; $password = ""; $db= "staff_db"; $conn = mysqli_connect($servername,$username,$password,$db); if(!$conn){ die('Connection Failed: '.mysqli_connect_error()); } return $conn; } $data = $_GET['data']; $sql = "SELECT * FROM staff_table WHERE name ='$data'"; $conn= connectDB(); $result = mysqli_query($conn,$sql); if($result){ $row = mysqli_fetch_assoc($result); } if(isset($_POST['update'])){ header('Location: UpdateEmployee.php?data='.$row['staff_id'].''); } ?> <form method="POST"> <table class="center"> <tr><td><p><strong>Name:</strong></p></td><td><p><?php echo $row['name'];?></p></td></tr> <tr><td><p><strong>Staff ID:</strong></p></td><td><p><?php echo $row['staff_id'];?></p></td></tr> <tr><td><p><strong>Email</strong></p></td><td><p><?php echo $row['email'];?></p></td></tr> <tr><td><p><strong>Gender</strong></p></td><td><p><?php echo $row['gender'];?></p></td></tr> <tr><td><p><strong>School</strong></p></td><td><p><?php echo $row['school'];?></p></td></tr> </table> <p><input type="submit" name="update" value="Update"></p> <p><input type="submit" name="delete" value="Delete"></p> </form> </fieldset> </div> <footer> <p><a href="MainMenu.php">Main Menu</a></p> <p><a href="">Logout</a></p> </footer> </body> </html>
×
×
  • 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.