Jump to content

[SOLVED] Updating data in a database - Without Session


taz321

Recommended Posts

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

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ?

 

 

 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.