taz321 Posted January 1, 2008 Share Posted January 1, 2008 Hi I am trying to update data in my database, but i keep getting an error message saying - Unable to perform query update employee set title =' Mr ', firstname =' Tarik ', surname =' Chowdary ', username =' Tarf ', password =' surxth ',where employeeID = This is my PHP script (below) - i have been doing this for ages but cant find the problem. <?php require "connect.php"; $title = $_GET['title']; $firstname = $_GET['firstname']; $surname = $_GET['surname']; $username = $_GET['username']; $password = $_GET['password']; $query = "insert into employee values ('','".$title."','".$firstname."','".$surname."','".$username."','".$password."')"; $result = mysql_query($query, $connection) or die ("Unable to perform query<br>$query"); header("Location: ClientForm.php"); exit(); ?> Thanks Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted January 1, 2008 Share Posted January 1, 2008 this query is not updating the table, its inserting a new value Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 1, 2008 Author Share Posted January 1, 2008 Sorry that was the code for inserting data :-S The actual code is below - <?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<br>$query"); header("Location: displayEmployeeAdmin.php"); exit(); ?> Thanks Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted January 1, 2008 Share Posted January 1, 2008 $query = "update employee set title =' ".$title." ', firstname =' ".$firstname." ', surname =' ".$surname." ', username =' ".$username." ', password =' ".$password. " ',where employeeID = ".$employeeID.""; Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 1, 2008 Author Share Posted January 1, 2008 Sorry im not quite following. I have a feeling the error is in the peice of code you have shown, but where in the code im not sure. Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted January 1, 2008 Share Posted January 1, 2008 replace the variable $query with what i wrote Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted January 1, 2008 Share Posted January 1, 2008 did it work? if so, remember to press "Topic Solved" Quote Link to comment Share on other sites More sharing options...
neilfurry Posted January 1, 2008 Share Posted January 1, 2008 I think i found the error This is your current code : $query = "update employee set title =' ".$title." ', firstname =' ".$firstname." ', surname =' ".$surname." ', username =' ".$username." ', password =' ".$password. " ',where employeeID = ".$employeeID.""; if you will notice, there should be no comma after the where clause |--[.]-[.]--|. $query = "update employee set title =' ".$title." ', firstname =' ".$firstname." ', surname =' ".$surname." ', username =' ".$username." ', password =' ".$password. " ' where employeeID = ".$employeeID.""; Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 1, 2008 Author Share Posted January 1, 2008 Hi Im afraid it didnt work. The code you gave me - $query = "update employee set title =' ".$title." ', firstname =' ".$firstname." ', surname =' ".$surname." ', username =' ".$username." ', password =' ".$password. " ',where employeeID = ".$employeeID.""; Has two "" at the end, is this right ? I took one off and then i got the error message Parse error: syntax error, unexpected T_STRING in C:\wamp\www\HelpDesk\EditUser.php on line 10 Does this mean i have solved the SQL query ? and just have to tackle another. Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 1, 2008 Author Share Posted January 1, 2008 Sorry just noticed the above comment, im justing applying the changes advised by neilfurry now :-) Quote Link to comment Share on other sites More sharing options...
duclet Posted January 1, 2008 Share Posted January 1, 2008 The problem is in your query. Remove the comma before the WHERE clause. That should fix the problem. Also, you might want to check that you are actually getting a value from $employeeID because from the query that you posted in the first post, it seems to be missing. Updated: Someone got ahead of me, oh well. Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 1, 2008 Author Share Posted January 1, 2008 This is the code with the amendments and still it doesnt work, i keep getting the "unable to update data ...." error msg. <?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<br>$query"); header("Location: displayEmployeeAdmin.php"); exit(); ?> Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted January 1, 2008 Share Posted January 1, 2008 oh try this: replace your variable $query with this: $query = "update employee set title ='".$title."' && firstname ='".$firstname."' && surname ='".$surname."' && username ='".$username."' && password ='".$password."' where employeeID = '".$employeeID."'"; Quote Link to comment Share on other sites More sharing options...
duclet Posted January 1, 2008 Share Posted January 1, 2008 Change the result line to: $result = mysql_query($query, $connection) or die ('Unable to perform query: '.$query.'<br />Error: '.mysql_error()); That way, I can get a clearer understanding of the problem. Quote Link to comment Share on other sites More sharing options...
neilfurry Posted January 1, 2008 Share Posted January 1, 2008 Hi, Can you try this on your query: $query = "update employee set title ='$title', firstname ='$firstname', surname ='$surname', username ='$username ', password ='$password' where employeeID ='$employeeID'"; Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 1, 2008 Author Share Posted January 1, 2008 Hi, This is the new and updated Code <?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(); ?> Thankfully the error mesages have gone now, but when i edit a text field with new data and click submit, nothing happens !! The data is as it was before. e.g Txtfield 1 - employeeID - 1 Txtfield 2 - name - David Txtfield 3 - surname - Beckham Txtfield 4 - username - david Txtfield 5 - password - david The above is the data which i originally inserted into the DB, i want to change the password to beckham, but when i click submit nothing happens. Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 1, 2008 Author Share Posted January 1, 2008 Hi Neilfurry, just read ur msg and tried the new query but im afraid it still doesnt update :-( Quote Link to comment Share on other sites More sharing options...
duclet Posted January 1, 2008 Share Posted January 1, 2008 Please revert to your original code and do as I suggested in my previous post. It will give me a better understanding of the problem which should helps in answering your question. Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 1, 2008 Author Share Posted January 1, 2008 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 Quote Link to comment Share on other sites More sharing options...
duclet Posted January 1, 2008 Share Posted January 1, 2008 By looking at the SQL, it seems like the $employeeID does not contain any value as I had thought. Which means this line: $employeeID = $_SESSION['employeeID']; is not doing what it is suppose to be doing. Trying added session_start() at the top of the script and see if you are getting any value for $employeeID. Also, to definitively know that $employeeID is the problem of all of this, trying giving it the value explicitly. If the script runs correctly, then it is because you are not getting the session data. Otherwise, the SQL is correct. Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 1, 2008 Author Share Posted January 1, 2008 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(); ?> Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 1, 2008 Author Share Posted January 1, 2008 Sorry im not quite sure what u mean when you mentioned about giving the employeeID value explicity :-S Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 1, 2008 Share Posted January 1, 2008 did you put some value on $_SESSION['employeeID'] eg.. $_SESSION['employeeID'] ='tes'; Quote Link to comment Share on other sites More sharing options...
duclet Posted January 1, 2008 Share Posted January 1, 2008 The problem is that $_SESSION['employeeID'] is just returning NULL and not giving you a true value. So when you add that part to the SQL query, your query ends with "WHERE employeeID =" which is an invalid SQL. If you change that line to $employeeID = 1; the query should work. And if you still don't believe me, trying doing a var_dump($employeeID) and see what it gives you. Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 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 Quote Link to comment 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.