taz321 Posted January 2, 2008 Share Posted January 2, 2008 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 Quote Link to comment Share on other sites More sharing options...
revraz Posted January 2, 2008 Share Posted January 2, 2008 Lets see the form that sends this info over. Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 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> Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted January 2, 2008 Share Posted January 2, 2008 To find out why you query isn't running add mysql_error to your or die clause: $result = mysql_query($query, $connection) or die ("Unable to perform query: $query<p>".mysql_error()); I have a feeling that it is because you are 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 Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 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 Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 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. Quote Link to comment Share on other sites More sharing options...
revraz Posted January 2, 2008 Share Posted January 2, 2008 You set employeeid to title2 here <td height="40"><span class="style1">Employee ID </span></td> <td><input name="title2" type="text" readonly="true" value="<?php echo $row['employeeID'];?>"></td> But you assign $employeeID here to $employeeID = $_GET['employeeID']; I would double check all your variable names as well. What wildteen is saying is that your column name Password should be changed. Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 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. Quote Link to comment Share on other sites More sharing options...
revraz Posted January 2, 2008 Share Posted January 2, 2008 No, in MySQL, change the fieldname. But your error appears to come before that, verify your tablename is in fact employee Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 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 ? Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 2, 2008 Share Posted January 2, 2008 I guess session id not working echo employee session............ Quote Link to comment Share on other sites More sharing options...
revraz Posted January 2, 2008 Share Posted January 2, 2008 This error is coming from somewhere else. Look at this line: $result = mysql_query($query, $connection) or die ("Unable to perform query$query"); Notice your error, Unable to perform query$query. This would produce an error like Unable to perform queryupdate employee set title blah blah But your error is Unable to perform query: update employee set title blah blah Notice the colon and space? This is coming from a error like: Unable to perform query: $query So I don't think we're looking at the right page somewhere. Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 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. Quote Link to comment Share on other sites More sharing options...
revraz Posted January 2, 2008 Share Posted January 2, 2008 Ok, then you changed the error reporting since the first post. It really looks like it's running twice for some reason. The first time it works fine, but then it runs again and all your variables are empty. Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 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 ? Quote Link to comment Share on other sites More sharing options...
revraz Posted January 2, 2008 Share Posted January 2, 2008 It would be in your best interest to find out why and fix it. Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 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 ? Quote Link to comment Share on other sites More sharing options...
revraz Posted January 2, 2008 Share Posted January 2, 2008 I would start adding echo's in the current scripts so you can see what's going on and when. Then remove them after you see where it's coming from. Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 Sorry may be a dumb question. I know what echo's do, but where would i start adding echo's and not quite what u mean there. Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 Thanks for your help guys. Thanks to you i can rest in peice now :-) Quote Link to comment Share on other sites More sharing options...
revraz Posted January 2, 2008 Share Posted January 2, 2008 So what was it? Quote Link to comment Share on other sites More sharing options...
taz321 Posted January 4, 2008 Author Share Posted January 4, 2008 I didnt resolve the bit when you asked me to echo it, but the update works and the error message remains as im not sure what to actually echo. Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 4, 2008 Share Posted January 4, 2008 Ok mate i added the print_r function to print your current query, i also change the query names and they where both the same, remember if query names are the same on the same php page there might be unexspected problams always have seprate query names .... if print_r dosent work replace with echo, good luck.......... <?php require "connect.php"; $employeeID = $_GET['employeeID']; $title = $_GET['title']; $firstname = $_GET['firstname']; $surname = $_GET['surname']; $username = $_GET['username']; $password1 = $_GET['password']; $query1 = "update employee set title ='".$title."', firstname ='".$firstname."', surname ='".$surname."', username ='".$username."', password ='".$password1."' where employeeID = ".$employeeID; PRINT_R($query1);// debug mode. $result1 = mysql_query($query1, $connection) or die ("Unable to perform query: $query1<p>".mysql_error()); header("Location: displayEmployeeAdmin.php"); exit(); ?> And this is the SQL in the form <?php require "connect.php"; $employeeID = $_GET['employeeID']; $query2 = "select * from employee where employeeID = ".$employeeID; PRINT_R($query2);//debug mode. $result2 = mysql_query($query2, $connection) or die ("Unable to perform query: $query2<p>".mysql_error()); $row= mysql_fetch_array($result2); ?> 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.