Jump to content

Not updating query


xcoderx

Recommended Posts

why is it not updating?

 

<?php
$_POST['email'];
$_POST['submit'];
if (isset($_POST['submit']))
{ 
/*$sql =" UPDATE class_members SET email ='".$_POST['email']."', WHERE S_UID ='".$_POST['mem_id']."' ";*/
$result = mysql_query("UPDATE class_members SET email ='".$_POST['email']."', WHERE mem_id='".$_POST['mem_id']."'") 
or die(mysql_error());  
} 

?>

Link to comment
Share on other sites

You have a comma after setting the value of email but you're only updating 1 column, remove it.

 

$result = mysql_query("UPDATE class_members SET email ='".$_POST['email']."' WHERE mem_id='".$_POST['mem_id']."'") 
or die(mysql_error());  

Link to comment
Share on other sites

still it wont :-(

 

ok here is the whole page

 

<?php
//Start session
session_start();

//Check the session MEMBER_ID is present or not
if(!isset($_SESSION['S_UID']) || (trim($_SESSION['S_UID']) == '')) {
	header("location: access-denied.php");
	exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>My Profile</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
$_POST['email'];
$_POST['submit'];
if (isset($_POST['submit']))
{ 
/*$sql =" UPDATE class_members SET email ='".$_POST['email']."', WHERE S_UID ='".$_POST['mem_id']."' ";*/
$result = mysql_query("UPDATE class_members SET email ='".$_POST['email']."' WHERE mem_id='".$_POST['mem_id']."'") 
or die(mysql_error());  
} 

?>

<h1>My Profile <?php echo $_SESSION['S_UID'];?></h1>
<a href="member-index.php">Home</a> | <a href="logout.php">Logout</a>
<p>This is another secure page. </p>
<form action="member-profile.php" method="post">
<input type="text" name="email" />
<input type="submit" value="update" />
</form>
</body>
</html>

 

what could possibly be wrong?

Link to comment
Share on other sites

the current code is this looks all ok but does not update anything in db. browser had been refreshed too

 

<?php
        require_once('config.php');
//Start session
session_start();

//Check the session MEMBER_ID is present or not
if(!isset($_SESSION['S_UID']) || (trim($_SESSION['S_UID']) == '')) {
	header("location: access-denied.php");
	exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>My Profile</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
$_POST['email'];
$_POST['submit'];
if (isset($_POST['submit']))
{ 
/*$sql =" UPDATE class_members SET email ='".$_POST['email']."' WHERE mem_id='".$_POST['mem_id']."' ";*/
$result = mysql_query("UPDATE class_members SET email ='".$_POST['email']."' WHERE mem_id='".$_POST['mem_id']."'") 
or die(mysql_error());  
} 

?>

<h1>My Profile <?php echo $_SESSION['S_UID'];?></h1>
<a href="member-index.php">Home</a> | <a href="logout.php">Logout</a>
<p>This is another secure page. </p>
<form action="member-profile.php" method="post">
<input type="text" name="email" />
<input type="submit" name="submit" value="update" />
</form>
</body>
</html>

Link to comment
Share on other sites

@jesirose now it should be right?

 

$email = $_POST['email'];

if (isset($_POST['submit']))

{

print_r($_POST);

/*$sql =" UPDATE class_members SET email ='".$_POST['email']."', WHERE S_UID ='".$_POST['mem_id']."' ";*/

$result = mysql_query("UPDATE class_members SET email ='".$_POST['email']."' WHERE mem_id='".$_POST['mem_id']."'")

or die(mysql_error()); 

}

 

@PFM bro man now am i goin set the field name mem_id tell me please im now starting to give up. i guess there should be a hidden field to assign the mem_id? i do not know how to get it done at all :-(

Link to comment
Share on other sites

Where should mem_id be coming from?  Even if you have a hidden field for it, the value must come from somewhere, right?

 

It just seems like you're skipping steps.  Remember, you need to explicitly tell PHP to do everything you want to do.  In your head it's automatic to think that "oh, yeah, I'll match my query on the member's id."  PHP has no notion of that unless you tell it to do that.  Nothing is automatic.

Link to comment
Share on other sites

I see a couple of issues:

 

1) You're not passing a mem_id via POST.  Maybe you store it in $_SESSION['S_UID']; ?

2) The email field is blank...

3) You don't sanitize your input to the DB.

Link to comment
Share on other sites

yes thats true im storing the mem_id in session but how come email field is blank?

 

therefore how am i goin to get it to work please show me examples for im not too cinfident with all these yet im only trying all i could.

Link to comment
Share on other sites

i tried this now

 

$email = $_POST['email'];
$mem_id = $_SESSION['S_UID'];
if (isset($_POST['submit']))
{ 
print_r($_POST); 

/*$sql =" UPDATE class_members SET email ='".$_POST['email']."', WHERE S_UID ='".$_POST['mem_id']."' ";*/
$result = mysql_query("UPDATE class_members SET email ='".$_POST['email']."' WHERE mem_id='".$_SESSION['mem_id']."'") 
or die(mysql_error());  

still now luck

Link to comment
Share on other sites

damn i did it :-) and it is updatng the field but is this the right way i did?

 

$email = $_POST['email'];

$mem_id['mem_id'] = $_SESSION['S_UID'];

if (isset($_POST['submit']))

{

print_r($_POST);

 

/*$sql =" UPDATE class_members SET email ='".$_POST['email']."', WHERE S_UID ='".$_POST['mem_id']."' ";*/

$result = mysql_query("UPDATE class_members SET email ='".$_POST['email']."' WHERE mem_id='".$mem_id['mem_id']."'")

or die(mysql_error()); 

}

 

i retrived the mem_id from the session where i stored it so i did it the right way?

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.