taz321
Members-
Posts
149 -
Joined
-
Last visited
Never
Everything posted by taz321
-
[SOLVED] Updating data in a database - Without Session
taz321 replied to taz321's topic in PHP Coding Help
Hmmm i wouldnt know where to begin, as it the code is for the two pages The actual script AND the form Are you saying there could be an error outside of these two pages ? -
[SOLVED] Updating data in a database - Without Session
taz321 replied to taz321's topic in PHP Coding Help
Because its showing an error message, would this affect my system being able to update data in the employee table, as it seems to be working fine at the momment ? -
[SOLVED] Updating data in a database - Without Session
taz321 replied to taz321's topic in PHP Coding Help
well this is the update script <?php require "connect.php"; $employeeID = $_GET['employeeID']; $title = $_GET['title']; $firstname = $_GET['firstname']; $surname = $_GET['surname']; $username = $_GET['username']; $password1 = $_GET['password']; $query = "update employee set title ='".$title."', firstname ='".$firstname."', surname ='".$surname."', username ='".$username."', password ='".$password1."' where employeeID = ".$employeeID; $result = mysql_query($query, $connection) or die ("Unable to perform query: $query<p>".mysql_error()); header("Location: displayEmployeeAdmin.php"); exit(); ?> And this is the SQL in the form <?php require "connect.php"; $employeeID = $_GET['employeeID']; $query = "select * from employee where employeeID = ".$employeeID; $result = mysql_query($query, $connection) or die ("Unable to perform query: $query<p>".mysql_error()); $row= mysql_fetch_array($result); ?> Both the $results in the two scripts are te same so, im not quite understanding what you mean by we might not be looking at the right page. -
[SOLVED] Updating data in a database - Without Session
taz321 replied to taz321's topic in PHP Coding Help
Thanks it appears to have worked :-) But im abit confused about something, i have two PHP pages - 1) The actual SQL thats runs the form 2) The form itself Now when i display the form in a browser, it all looks fine and the update works fine. But when i open the actual SQL script, it shows me an error message saying Unable to perform query: update employee set title ='', firstname ='', surname ='', username ='', password ='' where employeeID = 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 '' at line 1 I know the SQL won't display in the browser but as the SQL is now working for me, why is it still showing me an error message ? -
[SOLVED] Updating data in a database - Without Session
taz321 replied to taz321's topic in PHP Coding Help
Ahh sorry, stupid me, i have now amended the 'title2' :-S When you say change the column name, do you mean - <td height="40"><span class="style1">Password</span></td> <td><input name="password" type="text" value="<?php echo $row['password'];?>"></td> Change the "input name" to something else ? Sorry it may be a dumb question. -
[SOLVED] Updating data in a database - Without Session
taz321 replied to taz321's topic in PHP Coding Help
have column named as a reserved word (password). Rerun your code again and it should output an error from mysql why your query is failing I dont quite understand the above comment, please elaborate. -
[SOLVED] Updating data in a database - Without Session
taz321 replied to taz321's topic in PHP Coding Help
i have re run the system and the following error message is displayed Unable to perform query: update employee set title ='', firstname ='', surname ='', username ='', password ='' where employeeID = 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 '' at line 1 -
[SOLVED] Updating data in a database - Without Session
taz321 replied to taz321's topic in PHP Coding Help
Its quite big <?php session_start(); if (isset($_SESSION['username']) == false){ header("Location:Adminlogin.php"); exit(); } ?> <?php require "connect.php"; $employeeID = $_GET['employeeID']; $query = "select * from employee where employeeID ='".$_GET['employeeID']."'"; $result = mysql_query($query, $connection) or die ("Unable to perform query<br>$query"); $row= mysql_fetch_array($result); ?> <html> <head> <title>Jupiter Development Support</title> <link href="Images/mystyle.css" rel="stylesheet" type="text/css"> <style type="text/css"> <!-- #Layer2 {position:absolute; width:174px; height:48px; z-index:2; left: 16px; top: 143px; } #Layer1 {position:absolute; width:200px; height:76px; z-index:1; left: 254px; top: 84px; } .style1 {font-family: "Copperplate Gothic Bold"} .style3 {font-family: "Copperplate Gothic Bold"; font-size: x-large; } #Layer3 { position:absolute; width:386px; height:40px; z-index:3; left: 418px; top: 226px; } #Layer10 {position:absolute; width:200px; height:115px; z-index:10; left: 804px; top: 318px; } .style4 { font-family: "Copperplate Gothic Bold"; font-size: medium; font-weight: bold; } #Layer4 { position:absolute; width:155px; height:42px; z-index:11; left: 59px; top: 367px; } #Layer5 { position:absolute; width:157px; height:41px; z-index:12; left: 58px; top: 421px; } #Layer6 { position:absolute; width:159px; height:41px; z-index:13; left: 58px; top: 311px; } --> </style> </head> <body> <div id="header"> <h1 align="center"> </h1> <h1 align="center"> </h1> <h1 align="center"> </h1> <div id="Layer1"><img src="Images/JDS.jpg" width="704" height="79"></div> <h1 align="center"> </h1> <h1 align="center"> </h1> <div id="Layer2"><img src="Images/logo.jpg" width="173" height="43"></div> <h1 align="center"> </h1> <form action="EditUser.php" method="get"> <table width="1225" border="0"> <tr> <td width="286" height="39"> </td> <td width="137"> </td> <td width="172"> </td> <td width="117"> </td> <td width="491"> </td> </tr> <tr> <td height="39"> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td height="40"><div id="Layer5"><a href="deletepersonScreen.php"><img src="Images/deleteUser.jpg" width="158" height="41" border="0"></a></div> <div id="Layer6"><a href="AdminMainPage.php"><img src="Images/AdminHomepagebutton.jpg" width="158" height="42" border="0"></a></div></td> <td height="40"><span class="style1">Employee ID </span></td> <td><input name="title2" type="text" readonly="true" value="<?php echo $row['employeeID'];?>"></td> <td> </td> <td><div id="Layer10"><img src="Images/Symbol.jpg" width="235" height="231"></div></td> </tr> <tr> <td height="40"> </td> <td height="40"><span class="style1">Title</span></td> <td><input name="title" type="text" value="<?php echo $row['title'];?>"></td> <td><div id="Layer3"><span class="style3">Update User Details</span></div></td> <td> </td> </tr> <tr> <td height="40"> </td> <td height="40"><span class="style1">FirstName</span></td> <td><input name="firstname" type="text" value="<?php echo $row['firstname'];?>"></td> <td> </td> <td> </td> </tr> <tr> <td height="40"> </td> <td height="40"><span class="style1">SurName</span></td> <td><input name="surname" type="text" value="<?php echo $row['surname'];?>"></td> <td> </td> <td> </td> </tr> <tr> <td height="40"><div id="Layer4"><a href="CreateUser.php"><img src="Images/createUserButton.jpg" width="158" height="42" border="0"></a></div></td> <td height="40"><span class="style1">UserName</span></td> <td><input name="username" type="text" value="<?php echo $row['username'];?>"></td> <td> </td> <td> </td> </tr> <tr> <td height="40"> </td> <td height="40"><span class="style1">Password</span></td> <td><input name="password" type="text" value="<?php echo $row['password'];?>"></td> <td> <label></label> <div align="center"> <input name="Save" type="submit" class="style4" id="Update" value="Update"> </div> </td> <td> </td> </tr> <tr> <td height="52"> </td> <td> </td> <td> </td> <td><label> </label></td> <td> </td> </tr> <tr> <td height="52"> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </table> <p align="center"> </p> </body> </form> </html> -
Hi As you can see from the previous post that my update was'nt working because i was using sessions, but this time i dont want to use a session, so below is my code for updating a record in the database which doesnt work, i get a error message saying Unable to perform queryupdate employee set title ='', firstname ='', surname ='', username ='', password ='' where employeeID = My code is - <?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 title ='".$title."', firstname ='".$firstname."', surname ='".$surname."', username ='".$username."', password ='".$password."' where employeeID = ".$employeeID; $result = mysql_query($query, $connection) or die ("Unable to perform query$query"); header("Location: displayEmployeeAdmin.php"); exit(); ?> Iv been doing for days but still not working. Any help would be grateful Thanks
-
Thanks for all ur help guys, its not quite working yet but il keep trying and playing around with things.
-
This peice of code below, is a loop which displays each record of the table EMPLOYEE while($row= mysql_fetch_array($result)){?></td> <td width="130"><div align="center" class="style7"><?php echo $row['title'];?> <div id="Layer10"><img src="Images/Symbol.jpg" width="235" height="231"></div> </div></td> <td width="130"><div align="center" class="style7"><?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><a href="EditUserForm.php?employeeID=<?php echo $row['employeeID'];?>"><img src="Images/smallUpdateButton.jpg" width="67" height="25"></td> </tr> <tr> <td height="38"> </td> <td><div id="Layer7"><a href="deletepersonScreen.php"><img src="Images/deleteUser.jpg" width="158" height="41" border="0"></a></div></td> <td><?php } ?> Hope this makes sense :-)
-
<?php session_start(); require "connect.php"; $employeeID = $_SESSION['employeeID']; $title = $_GET['title']; $firstname = $_GET['firstname']; $surname = $_GET['surname']; $username = $_GET['username']; $password = $_GET['password']; $query = "update employee set title =' ".$title." ', firstname =' ".$firstname." ', surname =' ".$surname." ', username =' ".$username." ', password =' ".$password. " ' where employeeID = ".$employeeID; $result = mysql_query($query, $connection) or die ('Unable to perform query: '.$query.' Error: '.mysql_error()); header("Location: displayEmployeeAdmin.php"); exit(); ?> This is the displayEmployeeAdmin.php script, this displays the data in the DB ready for me to edit and calls the above script for updating. <?php session_start(); if (isset($_SESSION['username']) == false){ header("Location:Adminlogin.php"); exit(); } ?> <?php require "connect.php"; $query = "select * from employee"; $result = mysql_query($query, $connection) or die ("MySQL Error: ".mysql_error()); ?> <head> <title>Jupiter Development Support</title> <link href="Images/mystyle.css" rel="stylesheet" type="text/css"> <style type="text/css"> <!-- #Layer2 {position:absolute; width:174px; height:48px; z-index:2; left: 16px; top: 143px; } #Layer1 {position:absolute; width:200px; height:76px; z-index:1; left: 254px; top: 84px; } .style1 { font-family: "Copperplate Gothic Bold"; font-size: x-large; } #Layer3 { position:absolute; width:177px; height:34px; z-index:3; left: 498px; top: 218px; } .style6 {font-size: medium; font-family: "Copperplate Gothic Bold";} .style7 {font-size: small} #Layer6 { position:absolute; width:117px; height:115px; z-index:4; left: 945px; top: 195px; } #Layer10 { position:absolute; width:200px; height:115px; z-index:10; left: 992px; top: 200px; } #Layer4 { position:absolute; width:200px; height:73px; z-index:11; left: 272px; top: 295px; } #Layer5 { position:absolute; width:158px; height:43px; z-index:11; left: 52px; top: 310px; } #Layer8 { position:absolute; width:158px; height:42px; z-index:13; left: 51px; top: 361px; } #Layer7 { position:absolute; width:157px; height:42px; z-index:14; left: 50px; top: 410px; } --> </style> </head> <body> <div id="header"> <p> </p> <p> </p> <div id="Layer1"><img src="Images/JDS.jpg" width="704" height="79"></div> <p> </p> <div id="Layer2"><img src="Images/logo.jpg" width="173" height="43"></div> <p> </p> <p> </p> <table width="975" height="194" border="0"> <tr> <td width="26" height="26"> </td> <td width="123"><div id="Layer5"><a href="AdminMainPage.php"><img src="Images/AdminHomepagebutton.jpg" width="158" height="42" border="0"></a></div></td> <td width="79"></td> <td width="130"> </td> <td width="130"> </td> <td width="130"> </td> <td width="130"> </td> <td width="130"> </td> <td width="86"> </td> </tr> <tr> <td height="56"> </td> <td> </td> <td><div id="Layer3"><span class="style1">Edit User</span></div></td> <td width="130"><div align="center" class="style6">Title</div></td> <td width="130"><div align="center" class="style6">FirstName</div></td> <td width="130"><div align="center" class="style6">Surname</div></td> <td width="130"><div align="center" class="style6">Username</div></td> <td width="130"><div align="center" class="style6">Password</div></td> </tr> <tr> <td height="21"> </td> <td> </td> <td> </td> <td width="130"> </td> <td width="130"> </td> <td width="130"> </td> <td width="130"> </td> <td width="130"> </td> <td width="86"> </td> </tr> <tr> <td height="41"> </td> <td> </td> <td><?php while($row= mysql_fetch_array($result)){?></td> <td width="130"><div align="center" class="style7"><?php echo $row['title'];?> <div id="Layer10"><img src="Images/Symbol.jpg" width="235" height="231"></div> </div></td> <td width="130"><div align="center" class="style7"><?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><a href="EditUserForm.php?employeeID=<?php echo $row['employeeID'];?>"><img src="Images/smallUpdateButton.jpg" width="67" height="25"></td> </tr> <tr> <td height="38"> </td> <td><div id="Layer7"><a href="deletepersonScreen.php"><img src="Images/deleteUser.jpg" width="158" height="41" border="0"></a></div></td> <td><?php } ?></td> <td width="130"> </td> <td width="130"> </td> <td width="130"> </td> <td width="130"> </td> <td width="130"> </td> <td width="86"> </td> </tr> </table> <div id="Layer8"><a href="CreateUser.php"><img src="Images/createUserButton.jpg" width="158" height="42" border="0"></a></div> <p> </p> <p><br/> </p> </p> </body>
-
Hi it does work THANKS but this has occured. This is screen where i edit the data. e.g In my database i have 5 users in the employee table. If i edit changes in user 5, then the details in the first user gets deleted and replaced by the details of user 5. So it does update but deletes the first row. I hope this makes sense.
-
i think this is what your looking, its my login script. <?php session_start(); require "connect.php"; $username = $_GET['username']; $password = $_GET['password']; $query = "select * from admin where username='".$username."' AND password='".$password."'"; $result = mysql_query($query, $connection) or die ("Unable to perform query<br>$query"); $row=mysql_fetch_array($result); if($row != null) { $_SESSION['username'] = $row['username']; header("Location: AdminMainPage.php"); exit(); } else { $message = "Invalid UserName or Password, Please Try Again"; header("Location: Adminlogin.php?message=$message"); exit(); } ?>
-
so like this <?php session_start(); require "connect.php"; $employeeID = $_SESSION['employeeID'] = 1; $title = $_GET['title']; Adding the 1 at the end of employeeID, but isnt that making it static again ?
-
add a line saying $_SESSION['employeeID'] = somestuff here; Sorry abit bambozzled, where would i put that extra line you were saying and what do you mean by somestuff ?
-
Sorry this is slowly going over my head :-S the code below - <?php session_start(); require "connect.php"; $employeeID = $_SESSION['employeeID']; $title = $_GET['title']; $firstname = $_GET['firstname']; $surname = $_GET['surname']; $username = $_GET['username']; $password = $_GET['password']; $query = "update employee set title =' ".$title." ', firstname =' ".$firstname." ', surname =' ".$surname." ', username =' ".$username." ', password =' ".$password. " ' where employeeID = ".$employeeID; $result = mysql_query($query, $connection) or die ('Unable to perform query: '.$query.' Error: '.mysql_error()); header("Location: displayEmployeeAdmin.php"); exit(); ?> has a session in the displayEmployeeForm.php (bottom of the code) And in the displayEmployeeForm.php file, right at the top (line 1)it has the following session (PHP code) <?php session_start(); if (isset($_SESSION['username']) == false){ header("Location:Adminlogin.php"); exit(); } ?> If this helps.
-
The updating of the data is apart of the admin section of my system and i have set up sessions whereby you have to login before you can view any of the admin pages and if you try and jump pages it will take you back to the login screen. But i am putting my sessions at the end once all the admin pages are created. I understand the concepts of sessions but just confused over the problem in hand and why it doesnt return a value :-(
-
Can this be done without the session then ?
-
The session around the employee does not need to be there, that was advised to me by a friend who is doing something similar to me, but dont think his is working either.
-
Hi I changed the code to show a 6 at the end, because thats the ID number of the record in the database i was changing and its worked. where employeeID = ".$employeeID = 6; like you have said. But obviously needing it to work without hardcoding the number :-S
-
Sorry im not quite sure what u mean when you mentioned about giving the employeeID value explicity :-S
-
Hi After adding session_start(); at the top, i still get the same error message, would i actually need a session around the employee i.e - $employeeID = $_SESSION['employeeID']; This is the whole code again with the new changes - <?php session_start(); require "connect.php"; $employeeID = $_SESSION['employeeID']; $title = $_GET['title']; $firstname = $_GET['firstname']; $surname = $_GET['surname']; $username = $_GET['username']; $password = $_GET['password']; $query = "update employee set title =' ".$title." ', firstname =' ".$firstname." ', surname =' ".$surname." ', username =' ".$username." ', password =' ".$password. " ' where employeeID = ".$employeeID; $result = mysql_query($query, $connection) or die ('Unable to perform query: '.$query.' Error: '.mysql_error()); header("Location: displayEmployeeAdmin.php"); exit(); ?>
-
Hi Duclet This is the original code with ur results amendments <?php require "connect.php"; $employeeID = $_SESSION['employeeID']; $title = $_GET['title']; $firstname = $_GET['firstname']; $surname = $_GET['surname']; $username = $_GET['username']; $password = $_GET['password']; $query = "update employee set title =' ".$title." ', firstname =' ".$firstname." ', surname =' ".$surname." ', username =' ".$username." ', password =' ".$password. " ' where employeeID = ".$employeeID; $result = mysql_query($query, $connection) or die ('Unable to perform query: '.$query.'<br />Error: '.mysql_error()); header("Location: displayEmployeeAdmin.php"); exit(); ?> And the following error message has come up - Unable to perform query: update employee set title =' Mr ', firstname =' David ', surname =' Beckham ', username =' David ', password =' Beckham ' where employeeID = Error: 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 '' at line 1 Thanks
-
Hi Neilfurry, just read ur msg and tried the new query but im afraid it still doesnt update :-(