Jump to content

Update code isn't wking


tobimichigan

Recommended Posts

Code Gents,

I am appalled by what exactly is going here with this update code: It seems not to have any effect on the db. Rather than updating, it remains the same:

<?php
include ("cn.php");

$username=$_POST['username'];
$password=$_POST['password'];
$fullname=$_POST['fullname'];
$address=$_POST['address'];
$phone=$_POST['phone'];
$datereg=$_POST['datereg'];


//clean up any carriage returns etc
$username = preg_replace("/[\n\r]*/","",$username);
$password = preg_replace("/[\n\r]*/","",$password);
$fullname = preg_replace("/[\n\r]*/","",$fullname);
//$address = preg_replace("/[\n\r]*/","",$address);
$phone = preg_replace("/[\n\r]*/","",$phone);


//Select the database we want to use
mysql_query(" UPDATE admin
SET username='$username',password='$password',fullname='$fullname',address='$address',phone='$phone',datereg=SYSDATE(), WHERE username='$_SESSION[username]'");
if (!@mysql_query)
{
  die('Error: ' . mysql_error()."  SQL: ".$sql);
  }
else
header ("Location:Edit_Success.php");
?>

 

Please any excellent pointer would be highly appreciated.

Link to comment
Share on other sites

Your actual UPDATE query contains a syntax error (an extra comma.) If you look at the SQL you can probably see it.

 

You also have the following line of code that is doing nothing -

 

if (!@mysql_query)

 

The @ is suppressing the fact that php is treating that as a defined constant named mysql_query, then when it does not find one by that name, treats that as the string 'mysql_query'. Since the string 'mysql_query' is TRUE the if(){} conditional statement is skipped. You should not use @ in any code (ever) to suppress errors.

 

Your error checking and error reporting logic needs to test the value returned by the first mysql_query() statement or you need to form the query in a string and put it into the second mysql_query statement (after you fix it so that it is an actual mysql_query() function call.)

Link to comment
Share on other sites

pf, thanks for your reply I implemented your corrections but yet the problem is till there,

 

<?php
include ("cn.php");

if ($_POST["Submit"])
   {

$table=admin;
$id=$_POST['id'];
$username=$_POST['username'];
$password=$_POST['password'];
$fullname=$_POST['fullname'];
$address=$_POST['address'];
$phone=$_POST['phone'];
$datereg=$_POST['datereg'];


//clean up any carriage returns etc
$username = preg_replace("/[\n\r]*/","",$username);
$password = preg_replace("/[\n\r]*/","",$password);
$fullname = preg_replace("/[\n\r]*/","",$fullname);
//$address = preg_replace("/[\n\r]*/","",$address);
$phone = preg_replace("/[\n\r]*/","",$phone);


//Select the database we want to use
$query=" UPDATE $table
SET id='$id',username='$username',password='$password',fullname='$fullname',address='$address',phone='$phone',datereg=SYSDATE(), WHERE  username='$_SESSION[username]'";
mysql_query($query);
if (!mysql_query)
{
  die('Error: ' . mysql_error()."  SQL: ".$sql);
  }
else
header ("Location:Edit_Success.php");
}
?>

Please what do I do?

Link to comment
Share on other sites

I implemented your corrections

LOL, you only removed the @. That is only one of the three things that needed to be fixed.

 

You still need to do this -

Your actual UPDATE query contains a syntax error (an extra comma.) If you look at the SQL you can probably see it.

And this -

Your error checking and error reporting logic needs to test the value returned by the first mysql_query() statement or you need to form the query in a string and put it into the second mysql_query statement (after you fix it so that it is an actual mysql_query() function call.)
Link to comment
Share on other sites

Hi Mate,

 

What does your html form look like?

 

try changing:

 

if ($_POST["Submit"])

 

This is what it looks like:

 




to

if (isset($_POST["Submit"]))

cheers

Graham
[/quote]

<?php
	$id=$_GET['id'];
	$result=mysql_query("SELECT * FROM admin");
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
// collect all details for our one reference
$id=mysql_result($result,$i,"id");
$username=mysql_result($result,$i,"username");
$password=mysql_result($result,$i,"password");
$fullname=mysql_result($result,$i,"fullname");
$address=mysql_result($result,$i,"address");
$phone=mysql_result($result,$i,"phone");
$datereg=mysql_result($result,$i,"datereg");

$f='<font face=Verdana,Arial,Helvetica size=2 Color=Blue';
$view='<img src=http://your_website/thumbs/';
//next we display only the details we want to allow to be changed in a form object
// the other details that we won't allow to be changed can be echoed to the screen
//note the hidden input line 3 below. We don't need to echo it to the screen
?>

	<p align="center">
	<div align="center">
	<table border='0'>
	<form name='Edit_Admin' method='post' action='Edit_AdminAct.php'>
	<tr>
	<td>
	  <span class='style1'>EDIT ADMIN DETAILS</span>		</td>
	</tr>
<tr>
	<td><span class='style2'></span>
	<td>
	<th scope='col'><input name='id' type='hidden' value="<?php echo $id ?>" /></th>
	</tr>
	<tr>
	<td><span class='style2'>USERNAME</span>
	<td>
	<th scope='col'><input name='username' type='text' value="<?php echo $username ?>" /></th>
	</tr>
	<tr>
	<td><span class='style2'>PASSWORD</span>
	<td>
	<th scope='col'><input name='password' type='password' value="<?php echo $password ?>" /></th>
	</tr>
	<tr>
	<td><span class='style2'>FULL NAME</span>
	<td>
	<th scope='col'><input name='fullname' type='text' value="<?php echo $fullname ?>" /></th>
	</tr>
	<tr>
	<td><span class='style2'>ADDRESS</span>
	<td>
	<th scope='col'><textarea name='address' label="<?php echo $address ?>"></textarea ></th>
	</tr>
	<tr>
	<td><span class='style2'>PHONE</span>
	<td>
	<th scope='col'><input name='phone' type='text' value="<?php echo $phone ?>" /></th>
	</tr>
	<tr>
	<tr>
	<td><td>
	<th scope='col'><input name='Submit' type='submit' value='Submit' /></th>
	</tr>
	<tr>
	<td><td>
	<th scope='col'><input name='datereg' type='hidden' value="<?php echo '$datereg' ?>"/></th>
	</tr>
	</form>
	</table>
	</div>
	</p>
	<?php
++$i;
}
?>

 

I implemented your corrections

LOL, you only removed the @. That is only one of the three things that needed to be fixed.

 

You still need to do this -

Your actual UPDATE query contains a syntax error (an extra comma.) If you look at the SQL you can probably see it.

And this -

Your error checking and error reporting logic needs to test the value returned by the first mysql_query() statement or you need to form the query in a string and put it into the second mysql_query statement (after you fix it so that it is an actual mysql_query() function call.)

 

What do you mean by " Your error checking and error reporting logic"? The only error logic I've got here is

if (!mysql_query)
{
  die('Error: ' . mysql_error()."  SQL: ".$sql);
  }

This is my modified code: Removing the extra comma:

<?php
include ("cn.php");

if ($_POST["Submit"])
   {

$table=admin;
$id=$_POST['id'];
$username=$_POST['username'];
$password=$_POST['password'];
$fullname=$_POST['fullname'];
$address=$_POST['address'];
$phone=$_POST['phone'];
$datereg=$_POST['datereg'];


//clean up any carriage returns etc
$username = preg_replace("/[\n\r]*/","",$username);
$password = preg_replace("/[\n\r]*/","",$password);
$fullname = preg_replace("/[\n\r]*/","",$fullname);
//$address = preg_replace("/[\n\r]*/","",$address);
$phone = preg_replace("/[\n\r]*/","",$phone);


//Select the database we want to use
$query="UPDATE $table
SET id='$id',username='$username',password='$password',fullname='$fullname',address='$address',phone='$phone',datereg=SYSDATE() WHERE  username='$_SESSION[username]'";
mysql_query($query);
if (!mysql_query)
{
  die('Error: ' . mysql_error()."  SQL: ".$sql);
  }
else
header ("Location:Edit_Success.php");
}
?>
What I'm I missing this time gurus?

 

Link to comment
Share on other sites

P, I ran this logic:

 

<?php
$query="UPDATE $table
SET id='$id',username='$username',password='$password',fullname='$fullname',address='$address',phone='$phone',datereg=SYSDATE() WHERE  username='$_SESSION[username]'";
if (!$query);
{
die('Error: Cannot Update: '  . mysql_error()."  SQL: ".$sql);
}

mysql_query($query);
if (!mysql_query)
{
  die('Error: ' . mysql_error()."  SQL: ".$sql);
  }
else
header ("Location:Edit_Success.php");
}
?>

 

On the screen it is now giving: "Error: Cannot Update: SQL: " But its not giving any reason behind this.

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.