Jump to content

[SOLVED] UPDATE statement problem :(


tom.hill

Recommended Posts

Hi Guys,

 

for some reason this code is not working, i dont suppose anyone can spot an obvious error?

 

many thanks in advance.

 

<?php

// Check if session is not registered , redirect back to login page.

include('../includes/checklogin.php');

// Connect to server and select database

include('../db_login.php');

 

$oldusername = $_GET['username'];

 

// username and password sent from form

$username =$_POST['username'];

$password =md5($_POST['password']);

 

// Insert data into mysql

$query = "UPDATE tusers

          SET username = '$username' ,

          password = '$password'

          WHERE username = '$oldusername'";

         

$result = mysql_query($query);

 

// if successfully insert data into database, displays message "Successful".

  if($result){

  echo "Successful";

  echo "<BR>";

  echo "<a href='administration.php'>Back to admin</a>";

  }

  else {

  echo "ERROR  <BR>";

  // for testing

  echo "old $oldusername <BR>";

  echo "new $username <BR>";

  echo "pass $password <BR>";

  }

?>

 

my echo's for testing display the correct information but will not update the data in the database!!! :(

Link to comment
https://forums.phpfreaks.com/topic/82956-solved-update-statement-problem/
Share on other sites

Great news that you fixed it but for future issues have a look what i posted just after you had replyed.

 

 

change

 

$result = mysql_query($query);

 

to

 

$result = mysql_query($query) or die('Error updating: '.mysql_error());

 

That will return what error you have.

 

The syntax looks fine but could be a column name or somthing.

 

This is a very very useful debugging code to use!

 

Regards

Liam

Archived

This topic is now archived and is closed to further replies.

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