Jump to content

problem with if (isset($_POST[


halfpint

Recommended Posts

Hi I am not a php coder and only know bits and bobs which I have picked up

 

I have a problem with  isset($_POST

 

I have edited this

<?
include 'header.php';

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

  $avatar = $_POST["avatar"];
  $quote = $_POST["quote"];
  $banner = $_POST["banner"];
  $sig = $_POST["sig"];
  //insert the values
  if (!isset($message)){
    $result= mysql_query("UPDATE `grpgusers` SET `avatar`='".$avatar."', `quote`='".$quote."' WHERE `id`='".$user_class->id."'");
    $result= mysql_query("UPDATE `grpgusers` SET `banner`='".$banner."', `sig`='".$sig."' WHERE `id`='".$user_class->id."'");
    echo Message('Your preferences have been saved.');
    
die();
  }
}

 

to this so that they do not update all at the same time when a user sumbmits

 

<?
include 'header.php';
if (isset($_POST['submit'])) {

if (isset($_POST['avatar'])){ $result = mysql_query("UPDATE `grpgusers` SET `avatar`='".$avatar."', WHERE `id`='".$user_class->id."'");
}
if (isset($_POST['quote'])){ $result = mysql_query("UPDATE `grpgusers` SET `quote`='".$quote."', WHERE `id`='".$user_class->id."'");
}
if (isset($_POST['banner'])){ $result = mysql_query("UPDATE `grpgusers` SET `banner`='".$banner."', WHERE `id`='".$user_class->id."'");
}
if (isset($_POST['sig'])){ $result = mysql_query("UPDATE `grpgusers` SET `sig`='".$sig."', WHERE `id`='".$user_class->id."'");
}  

//insert the values
    echo Message('Your preferences have been saved.');
    
die();

}
?>

 

but now the users can not use the forms to submit anything

 

Does anybody know if this will work or why it is not working as I want the forms to be independant of each other so they do not update at the same time

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/102241-problem-with-if-isset_post/
Share on other sites

Your need code does does not take the values from the $_POST variable like they should

 

Example:

// BAD
"UPDATE `grpgusers` SET `avatar`='".$avatar."', WHERE `id`='".$user_class->id."'"

// GOOD
"UPDATE `grpgusers` SET `avatar`='".$_POST['avatar']."', WHERE `id`='".$user_class->id."'"

What is the name of the "submit" button on the form?  For example:

 

<input type="submit" name="this_is_what_I_want" value="Submit" />

 

That value is what shoule be in your if statement...in this example:

 

if (isset($_POST['this_is_what_I_want'])) { ... }

 

Thanks is this what you are asking for

 

tr><td class="contentcontent">
<form name='login' method='post'>
  <table width='100%' border='0' align='center' cellpadding='0' cellspacing='0'>
  	<tr>
      <td height='28'><font size='2' face='verdana'>Banner Image Location   </font></td>
      <td><font size='2' face='verdana'>
        <input type='text' name='banner' value='<?= $user_class->banner ?>'>
        </font></td>
    </tr>
    <tr>
    <tr>
      <td height='28' align="right"><font size='2' face='verdana'>Quote   </font></td>
      <td><font size='2' face='verdana'>
        <input type='text' name='sig' value='<?= $user_class->sig ?>'>
        </font></td>
    </tr>
      <td> </td>
      <td><font size='2' face='verdana'>
        <input type='submit' name='submit' value='Save Preferences'>

Your need code does does not take the values from the $_POST variable like they should

 

Example:

// BAD
"UPDATE `grpgusers` SET `avatar`='".$avatar."', WHERE `id`='".$user_class->id."'"

// GOOD
"UPDATE `grpgusers` SET `avatar`='".$_POST['avatar']."', WHERE `id`='".$user_class->id."'"

 

If I change them to the above "good" will it work?

Yes, that was the only error I found in the code, and that is why I think it was not working.

 

thank you

so it should look like this

 

if (isset($_POST['avatar'])){ $result = mysql_query("UPDATE `grpgusers` SET `avatar`='".$_POST['avatar']."', WHERE `id`='".$user_class->id."'");

Gave it a go but unfortunately it still wont work I am wondering if has anything to do with this in the classes.php and this code

 

	$this->quote = $worked['quote'];

$this->avatar = $worked['avatar'];

        $this->banner = $worked['banner'];

        $this->sig = $worked['sig'];

 

I dont understand why it wont work if I try and seperate the submit forms Im really stumped now

thank you

so it should look like this

 

if (isset($_POST['avatar'])){ $result = mysql_query("UPDATE `grpgusers` SET `avatar`='".$_POST['avatar']."', WHERE `id`='".$user_class->id."'");

 

REMEMBER TO SANITIZE YOUR INCOMING VARIABLES!

 

Please read about mysql_real_escape_string http://us2.php.net/mysql_real_escape_string

thank you

so it should look like this

 

if (isset($_POST['avatar'])){ $result = mysql_query("UPDATE `grpgusers` SET `avatar`='".$_POST['avatar']."', WHERE `id`='".$user_class->id."'");

 

REMEMBER TO SANITIZE YOUR INCOMING VARIABLES!

 

Please read about mysql_real_escape_string http://us2.php.net/mysql_real_escape_string

 

Hi thanks I have now got it working with the help of some other webmasters

The code that worked was this

<?

include 'header.php';


if($_POST['form_type'] == 'avatarquote') {
$avatar = $_POST["avatar"];
$quote = $_POST["quote"];
$result= mysql_query("UPDATE `grpgusers` SET `avatar`='".$avatar."', `quote`='".$quote."' WHERE `id`='".$user_class->id."'");
	echo 'Your preferences have been saved.';
	die();
}
elseif($_POST['form_type'] == 'bannersig') {
$banner = $_POST["banner"];
$sig = $_POST["sig"];
$result= mysql_query("UPDATE `grpgusers` SET `banner`='".$banner."', `sig`='".$sig."' WHERE `id`='".$user_class->id."'");
	echo 'Your preferences have been saved.';
	die();
}

 

I have also been talking to another guy who is helping me to stop users from injecting code in to mysql

 

Thanks for all your help  :) Im a happy bunny now..lol

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.