taz321 Posted December 24, 2007 Share Posted December 24, 2007 Hi Im having abit of trouble updating data in the database. I have displayed a list of people who have the attributes, EmpID, Name, firstname, surname ect and have placed a link around the name attribute which goes to the update form. The name which i click on should display all its contents in the update form but it doesnt. The code is shown below for this - <a href="EditUserForm.php?employeeID=<?=$row['employeeID']?>"><?php echo $row['firstname'];?></div></td> i have below the form from where im going to manually update the existing data below. <?php session_start(); require "connect.php"; $Username = $_SESSION['employeeID']; $query = "select * from employee where employeeID = '".$_SESSION['employeeID']."'"; $result = mysql_query($query, $connection) or die ("Unable to perform query<br>$query"); $row= mysql_fetch_array($result); ?> <body> <h1 align="center">Edit person Details </h1> <form action="EditUser.php" method="get"> <p>employeeID:<br/> <input name="employeeID" type="text" readonly="true" value=" <?=$row['employeeID']?>" > </p> <p>title:<br/> <input name="title" type="text" value="<?=$row['title']?>"> </p> <p>firstname:<br/> <input name="firstname" type="text" value="<?=$row['firstname']?>"> </p> <p>surname:<br/> <input name="surname" type="text" value="<?=$row['surname']?>"> </p> <p>username:<br/> <input name="username" type="text" value="<?=$row['username']?>"> </p> <p>Password: <br/> <input name="password" type="password" value="<?=$row['password']?>"> </p> <input name="Save" type="submit" value="Update"> </form> </body> </html> AND this is the PHP code (EditUser.php) which the above calls in order for the updating to work <?php require "connect.php"; $employeeID = $_SESSION['employeeID']; $title = $_SESSION['title']; $firstname = $_GET['firstname']; $surname = $_GET['surname']; $username = $_GET['username']; $password = $_GET['password']; $query = "update employee set employeeID='".$employeeID."',title= '".$title."', firstname = '".$firstname."', surname = '".$surname."', username = '".$username."', password = '".$password."'"; $result = mysql_query($query, $connection) or die ("Unable to perform query<br>$query"); header ("Location: EditUserForm.php"); exit(); ?> When i look at the form, it doesnt appear to show me any data to edit, im abit confused. Any help would be grateful. MOD EDIT: code tags added Quote Link to comment https://forums.phpfreaks.com/topic/83065-updating-data-in-a-database/ Share on other sites More sharing options...
corbin Posted December 24, 2007 Share Posted December 24, 2007 Shouldn't you be using $_GET['employeeID'] instead of $_SESSION? Quote Link to comment https://forums.phpfreaks.com/topic/83065-updating-data-in-a-database/#findComment-422533 Share on other sites More sharing options...
taz321 Posted December 24, 2007 Author Share Posted December 24, 2007 I have just noticed that in this bit of the code it says $_SESSION instead of $_GET as you have rightfully pointed out. <?php require "connect.php"; $employeeID = $_GET['employeeID']; $title = $_GET['title']; $firstname = $_GET['firstname']; $surname = $_GET['surname']; $username = $_GET['username']; $password = $_GET['password']; i have changed but but nothing seems to be working yet ? Quote Link to comment https://forums.phpfreaks.com/topic/83065-updating-data-in-a-database/#findComment-422539 Share on other sites More sharing options...
revraz Posted December 24, 2007 Share Posted December 24, 2007 Are you familiar with how GET works? Quote Link to comment https://forums.phpfreaks.com/topic/83065-updating-data-in-a-database/#findComment-422542 Share on other sites More sharing options...
taz321 Posted December 24, 2007 Author Share Posted December 24, 2007 I understand that it gets the information from the database. Quote Link to comment https://forums.phpfreaks.com/topic/83065-updating-data-in-a-database/#findComment-422544 Share on other sites More sharing options...
corbin Posted December 24, 2007 Share Posted December 24, 2007 Errmmmm.... No. $_GET doesn't get things from a database. http://www.w3schools.com/php/php_get.asp http://www.tizag.com/phpT/postget.php Quote Link to comment https://forums.phpfreaks.com/topic/83065-updating-data-in-a-database/#findComment-422545 Share on other sites More sharing options...
taz321 Posted December 24, 2007 Author Share Posted December 24, 2007 Thanks just read those links you gave me and have got a better understanding now. The code below for the form where it gets the data from the database, is it correct ? <?php require "connect.php"; $employeeID = $_GET['employeeID']; $title = $_GET['title']; $firstname = $_GET['firstname']; $surname = $_GET['surname']; $username = $_GET['username']; $password = $_GET['password']; $query = "update employee set employeeID='".$employeeID."',title= '".$title."', firstname = '".$firstname."', surname = '".$surname."', username = '".$username."', password = '".$password."'"; $result = mysql_query($query, $connection) or die ("Unable to perform query<br>$query"); header ("Location: EditUserForm.php"); exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/83065-updating-data-in-a-database/#findComment-422559 Share on other sites More sharing options...
taz321 Posted December 24, 2007 Author Share Posted December 24, 2007 Sorry im not sure if this will help, but i have displayed the contents from the database in another sheet and below is a sample of the code, there is a link around the "name" attribute and i was hoping that once this is clicked the user would go to the form and have displayed the details of that particular person ready for me to edit. <td width="130"><div align="center" class="style7"> <a href="EditUserForm.php?employeeID=<?=$row['employeeID']?>"><?php echo $row['firstname'];?></div></td> <td width="130"><div align="center" class="style7"><?php echo $row['surname'];?></div></td> <td width="130"><div align="center" class="style7"><?php echo $row['username'];?></div></td> <td width="130"><div align="center" class="style7"><?php echo $row['password'];?></div></td> <td width="80"> </td> Quote Link to comment https://forums.phpfreaks.com/topic/83065-updating-data-in-a-database/#findComment-422567 Share on other sites More sharing options...
Barand Posted December 24, 2007 Share Posted December 24, 2007 You shoudn't be updating the employeeID. You should be using that to identify the record to be updated (otherwise all records in the table will be set to those values) <?php $query = "update employee SET title= '$title', firstname = '$firstname', surname = '$surname', username = '$username', password = '$password' WHERE employeeID = '$employeeID' "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/83065-updating-data-in-a-database/#findComment-422568 Share on other sites More sharing options...
janim Posted December 24, 2007 Share Posted December 24, 2007 no you didn't understood what $_GET means look try something like this : require "connect.php"; $Username = $_SESSION['employeeID']; $query = mysql_query("select * from employee where employeeID = '$Username') or die("".mysql_error()); if( mysql_num_rows($query)) { $row = mysql_fetch_array($query); } i hope it helps Quote Link to comment https://forums.phpfreaks.com/topic/83065-updating-data-in-a-database/#findComment-422572 Share on other sites More sharing options...
taz321 Posted December 24, 2007 Author Share Posted December 24, 2007 Thanks, il try and play around with it and see where i get. Quote Link to comment https://forums.phpfreaks.com/topic/83065-updating-data-in-a-database/#findComment-422586 Share on other sites More sharing options...
raku Posted December 24, 2007 Share Posted December 24, 2007 $_GET gets variables from the URL like: www.example.com/test.php?employee=4 echo $_GET['employee'] --> outputs 4 If you want to get the information from the database, you can use a select statement, then iterate through the row to get what you're looking for. Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/83065-updating-data-in-a-database/#findComment-422625 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.