Jump to content


Photo

Form wont send a value


  • Please log in to reply
6 replies to this topic

#1 Madatan

Madatan
  • Members
  • PipPipPip
  • Advanced Member
  • 51 posts

Posted 06 June 2006 - 11:38 AM

I've done this kind of things many times before... and yet I can't get it to work this time. The code down here simply wont send a value from the Form. Can anyone see why?





<?
session_start();
include 'dbconnect.php';
$Button = $_SESSION['charactername'];
$query = "SELECT * FROM mud_users WHERE name = '$Button'";
$result = mysql_query($query) or die('Error : ' . mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$rowid = $row['id'];
//EQUIP


if(isset($_POST['equip']))
 {
//Change don't get a value
$query = "UPDATE mud_armour SET equipped = '1' WHERE arid = '$change'";
$result = mysql_query($query) or die('Error : ' . mysql_error());
}

$query = "SELECT * FROM mud_armour WHERE ownerid = '$rowid' AND equipped = '0'"; //Torso
$result = mysql_query($query) or die('Error : ' . mysql_error());

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

?>
<tr>
<td><span class="style4"><b>
Unequipped</b>:<br>
Name: <? echo $row['name']; ?></span></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><form id="yes" name="jak" method="post">
<input name="add" type="text" value="<? echo $row['arid']; ?>">
//This is change, it's supposed to get a value from the database. It does but it wont send the value.
<input name="change" type="hidden" value="<? echo $row['arid']; ?>">
<input name="equip" type="submit" value="Equip">
</form>
</td>
</tr>
<? } ?>
</table>


#2 witt

witt
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 06 June 2006 - 11:47 AM

Shouldn't you have something like action="getform.php" ?

#3 Madatan

Madatan
  • Members
  • PipPipPip
  • Advanced Member
  • 51 posts

Posted 06 June 2006 - 01:33 PM

[!--quoteo(post=380558:date=Jun 6 2006, 06:47 AM:name=witt)--][div class=\'quotetop\']QUOTE(witt @ Jun 6 2006, 06:47 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Shouldn't you have something like action="getform.php" ?
[/quote]

no because the script I want to start is not in another php file but in the same... thats the reason why I use if(isset($_POST['attack']))

when I click the button named attack it will do the code in that if statement.

#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 02:16 PM

I'm going to guess it's because you're nesting a form inside of a table. Put your form tags outside of the table (you can obviously leave the input fields in the table) and see what happens.

Also, it's good practice to put the action attribute in the form even if you're submitting to the same page.

And I assume you mean "equip" instead of "attack", because that's how it is coded.

Info: PHP Manual


#5 Madatan

Madatan
  • Members
  • PipPipPip
  • Advanced Member
  • 51 posts

Posted 06 June 2006 - 02:37 PM

[!--quoteo(post=380606:date=Jun 6 2006, 09:16 AM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Jun 6 2006, 09:16 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I'm going to guess it's because you're nesting a form inside of a table. Put your form tags outside of the table (you can obviously leave the input fields in the table) and see what happens.

Also, it's good practice to put the action attribute in the form even if you're submitting to the same page.

And I assume you mean "equip" instead of "attack", because that's how it is coded.
[/quote]

Yes I mean equip of course :)

I changed everything now, moving the form out of the table but I wont get a value anyway :/ so that didn't work. I guess I have to figure out something else!

#6 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 02:51 PM

I think your error may be in your query:

$query = "UPDATE mud_armour SET equipped = '1' WHERE arid = '$change'";

Change it to:
$query = "UPDATE mud_armour SET equipped = '1' WHERE arid = '" . $_POST['change'] . "'";

Info: PHP Manual


#7 Madatan

Madatan
  • Members
  • PipPipPip
  • Advanced Member
  • 51 posts

Posted 06 June 2006 - 02:54 PM

[!--quoteo(post=380617:date=Jun 6 2006, 09:51 AM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Jun 6 2006, 09:51 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I think your error may be in your query:

$query = "UPDATE mud_armour SET equipped = '1' WHERE arid = '$change'";

Change it to:
$query = "UPDATE mud_armour SET equipped = '1' WHERE arid = '" . $_POST['change'] . "'";
[/quote]

Thank you so much! I've been trying to get this to work the last 24 hours and it truly have made me insane.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users