Jump to content

Recommended Posts

So, I'm building a browser-game and I made a new battle system today, where you choose your 'action' from radio inputs and then submit the value to another php file, where the action is then executed.

 

But, I encountered a problem: I can slip the "attack message" in the value of the input, but I'd need to include the mysql_query in too, but I can't figure out how!

 

Heres the input code:

<input type='radio' value='<? echo $attackmsg; $_SESSION['update_damage_taken']; ?>' name='action' checked='yes' />
<input type='submit' value='Submit'>

And heres the what the variables do:

$attackmsg = "$playername throws a rock-hard punch at {$_SESSION['monstername']}. <br>{$_SESSION['monstername']} loses {$_SESSION['attackamount']} HP.";

$_SESSION['update_damage_taken'] = "mysql_query('UPDATE users SET hp = {$playerhp}  WHERE id = {$_SESSION['user_id']}')";

 

But the single quotes ( ' ) mess up the input. Is there any way to do this properly?  :confused:

 

Or if you got a better idea for a battle system, I'd be glad to hear it out! (As long as it supports multiple attack options)

 

EDIT:

 

Heres how it shows up in browser:

Mabish throws a rock-hard punch at Drops.

Drops loses 10 HP.

Drops attacks Mabish.

Mabish loses 8 HP.

But it still doesn't update the player hp in the database, so the mysql_query isn't working.

Link to comment
https://forums.phpfreaks.com/topic/191891-need-help-with-and-stuff/
Share on other sites

remove the quotes around the mysql_query code. Instead of calling the function mysql_query, you are just creating a strign with some PHP code. alternatively, you could keep the code like that and use eval(), but just removing the quotes is easier and better

Thanks for the answer, I altered the battle system already tho :)

 

Instead of trying to stuff everything in the input value I just did this:

<form action='battle_action.php' method='post'>
<input type='radio' value='attack' name='action' checked='yes' />
<input type='radio' value='flee' name='action' />
<input type='submit' value='Submit'>

 

And on the battle_action.php page:

//Check which action was performed
$action = "{$_POST['action']}";

And:

switch ($action){

case "attack":
echo "$playername throws a rock-hard punch at {$_SESSION['mname']}. <br>{$_SESSION['mname']} loses {$_SESSION['attack']} HP.";
$_SESSION['mhp'] -= $_SESSION['attack'];
break;

case "flee":

<< Flee script here >>

}
break;
}

 

 

Oh I just wish I didn't waste hours for nothing. (Except the experience!)

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.