Jump to content

Add yes to new field in database


jimjim

Recommended Posts

hi,

this is my first post, i hope someone here can give me a hand with this.

i have created a new field in the member_profile table in my database. lets say i named it newfield.

i would like a yes to be placed in this newfield at the same time i give moderator privlages to a member.

i can manually enter a yes in newfield now with phpmyadmin.

 

i believe this code applies the moderator settings, any ideas on a way to have this post yes in my new field as well.

 

 

//make Moderator

//////////////////////

if (isset($_POST['moderator']) && isset($_POST['list'])) {

    foreach ($_POST['list'] as $user_id) {

        managemember($user_id,'moderator');

}

 

    //notifications

    $show_notification = 1;

    $message = notifications(1);

}

 

 

any help greatly appreciated.

 

 

 

 

 

 

 

Link to comment
Share on other sites

ok set it up as bool and it now takes a value of 1 in newfield but i still have to add it manualy.  i still cant get the script to add a 1 at the same time that i set a member to moderator. it adds a 1 to the moderator field but not to the newfield. any ideas.

Link to comment
Share on other sites

hi,

i hope this makes sense i don't have much experience with this stuff.

 

i have this adding a one to newfield in my database what would i need to do to make this check if newfield = 1 change newfield back to 0

 

 

 

$sql = "SELECT * FROM member_profile SET newfield = '1' WHERE  userid = $user_id";

 

 

Many Thanks

 

Link to comment
Share on other sites

hi kansas

 

thanks, i pasted the wrong code this is the code that sets newfield to 1.

 

$sql = "UPDATE member_profile SET newfield = '1' WHERE user_id = $user_id";

 

 

what i would like to do is make this code check to see if newfield = 1  and if it does change newfield back to 0

 

 

Link to comment
Share on other sites

I think the steps are just about there.  Me being new as well, I still get lost in what I want to do and what I am telling the code to do.

 

 

$sql = "SELECT * FROM member_profile SET newfield = '1' WHERE  userid = $user_id";
$qry = mysql_query($sql);
$res = mysql_assoc($qry)
if($res['newfield'] == 1){
     $sql = "UPDATE member_profile SET newfield = '0' WHERE user_id = $user_id";
     $upresult = mysql_query($sql);
if(mysql_affected_rows()== 1){
	//update successfull
}else{
	//update failed
}
}

 

I think this will get you closer, I did not test it but I tried to make sure the syntax was correct. 

 

I still make a lot of errors when writing code blocks and debug them constantly

 

Kansas

Link to comment
Share on other sites

hi Kansas,

 

i have tried the code every way that i can think of but it will not replace the 1 with a 0

 

i get a blank screen with this in the code  $res = mysql_assoc($qry);

when i remove it places a 1 in newfield but won't replace it with 0

 

any ideas?

Link to comment
Share on other sites

hi Kansas,

 

i have tried the code every way that i can think of but it will not replace the 1 with a 0

 

i get a blank screen with this in the code  $res = mysql_assoc($qry);

when i remove it places a 1 in newfield but won't replace it with 0

 

any ideas?

 

In the code I posted, I left out the semi colon in the code have you tried it adding a semi colon to terminate the line as you have posted it ?

 

$res = mysql_assoc($qry);
??

 

That syntax error could cause a blank screen. 

Another step in the debugging process I would take would be to do an

 

$sql = "SELECT * FROM member_profile SET newfield = '1' WHERE  userid = $user_id";
$qry = mysql_query($sql);
$res = mysql_assoc($qry);

echo '<pre>';
print_r ($res);
echo '</pre>';

if($res['newfield'] == 1){
     $sql = "UPDATE member_profile SET newfield = '0' WHERE user_id = $user_id";
     $upresult = mysql_query($sql);
if(mysql_affected_rows()== 1){
	//update successfull
}else{
//update failed
}
}

 

the print_r will allow you to see the array values in $res.

 

Kansas

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.