Edit user php script

Iam new to php and iam having some problems with my edit user php file. The problem is the query doesnt perform. PLs can some one help me with this code. Thanks in advance.

[php]

<?php session_start(); if(!isset($_SESSION['SESS_LOGIN']) || $_SESSION['SESS_TYPE'] !='admin')// if session variable "login" does not exist. { echo ''; //header("location:login-form.php"); // Re-direct to login-form.php } else { include("config.php"); $id = mysql_real_escape_string($_POST['id']); $login = mysql_real_escape_string($_POST['login']); $password = mysql_real_escape_string($_POST['password']); $type = mysql_real_escape_string($_POST['type']); $qry_edit = " UPDATE members SET login='$login', password='$password', type='$type' WHERE id='$id' "; $count = mysql_query("SELECT COUNT(id) FROM members WHERE id='$id'"); if(mysql_num_rows($count)==1) { if($result=mysql_query($qry_edit)) //or die(mysql_error()); { /*echo '';*/ header("Location: view_all_user.php"); } else { echo "
Problem in editing !" ; echo "ERROR - unable to save new username and password!
"; $SQLError = "SQL ERROR: ".mysql_errno().". ".mysql_error()."

"; echo "$SQLError"; mysql_close(); } } //echo "
you have successfully edited one user !
[ username = $login ] " ; else { echo "
No id !" ; } } ?>

[/php]

hello viddz,

You need to replace your code with my code,

replace below code (remove)
$qry_edit = " UPDATE members SET login=’$login’, password=’$password’, type=’$type’ WHERE id=’$id’ ";

use below code (use this)
$qry_edit = " UPDATE members SET login=’$login’, password=’$password’, type=’$type’ WHERE id=".$id;

replace below code
$count = mysql_query(“SELECT COUNT(id) FROM members WHERE id=’$id’”);

use below code
$count = mysql_query(“SELECT COUNT(id) FROM members WHERE id=”.$id);

i hope this will helpful for you.

SR

Thanks for the rply SR,
but then this error occurred after changing the code as u hav mentioned.

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in F:\xampplite\htdocs\vidi\edit_user_save.php on line 26

No id !

hello viddz,
try below code instead of current code you are using.
i hope this will helpful for you.

[php]

<?php session_start(); if(!isset($_SESSION['SESS_LOGIN']) || $_SESSION['SESS_TYPE'] !='admin')// if session variable "login" does not exist. { echo ''; //header("location:login-form.php"); // Re-direct to login-form.php } else { include("config.php"); $id = mysql_real_escape_string($_POST['id']); $login = mysql_real_escape_string($_POST['login']); $password = mysql_real_escape_string($_POST['password']); $type = mysql_real_escape_string($_POST['type']); $qry_edit = " UPDATE members SET login='$login', password='$password', type='$type' WHERE id=".$id; $count = mysql_query("SELECT COUNT(id) FROM members WHERE id=".$id); if($count > 0) { if(mysql_query($qry_edit)) //or die(mysql_error()); { /*echo '';*/ header("Location: view_all_user.php"); } else { echo "
Problem in editing !" ; echo "ERROR - unable to save new username and password!
"; $SQLError = "SQL ERROR: ".mysql_errno().". ".mysql_error()."

"; echo "$SQLError"; mysql_close(); } } //echo "
you have successfully edited one user !
[ username = $login ] " ; else { echo "
No id !" ; } } ?>

[/php]

SR

oh ! there is another error :frowning: :’(

<<No id !>>

hello ,
try this code

[php]

<?php session_start(); if(!isset($_SESSION['SESS_LOGIN']) || $_SESSION['SESS_TYPE'] !='admin')// if session variable "login" does not exist. { echo ''; //header("location:login-form.php"); // Re-direct to login-form.php } else { include("config.php"); $id = mysql_real_escape_string($_POST['id']); $login = mysql_real_escape_string($_POST['login']); $password = mysql_real_escape_string($_POST['password']); $type = mysql_real_escape_string($_POST['type']); $qry_edit = " UPDATE members SET login='$login', password='$password', type='$type' WHERE id=".$id; $count = mysql_query("SELECT * FROM members WHERE id=".$id); $rcount = mysql_num_rows($count); if($rcount > 0) { if(mysql_query($qry_edit)) //or die(mysql_error()); { /*echo '';*/ header("Location: view_all_user.php"); } else { echo "
Problem in editing !" ; echo "ERROR - unable to save new username and password!
"; $SQLError = "SQL ERROR: ".mysql_errno().". ".mysql_error()."

"; echo "$SQLError"; mysql_close(); } } //echo "
you have successfully edited one user !
[ username = $login ] " ; else { echo "
No id !" ; } } ?>

[/php]

Still you get any error than do one thing
echo “SELECT COUNT(id) FROM members WHERE id=”.$id; and execute this query directly in your database.

SR

done
this error occured

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in F:\xampplite\htdocs\vidi\edit_user_save.php on line 41

No id !

can pls tel me how to echo “SELECT COUNT(id) FROM members WHERE id=”.$id; in DB.
this is the way i hv done it, go to phpmyadmin>> select db >> type “SELECT COUNT(id) FROM members WHERE id=”.$id;
am i correct ???

then this error occured
#1064 - 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 ‘echo “SELECT COUNT(id) FROM members WHERE id=”.$id’ at line 1

Found the error. there was id parsing error
Thank u very much 4 ur time n help :slight_smile:

hello viddz,

do this
go to phpmyadmin>> select db >> type
SELECT COUNT(id) FROM members WHERE id=1;

SR

Thank u very much ;D :smiley: Really appreciate ur help.

Sponsor our Newsletter | Privacy Policy | Terms of Service