Bikkebakke Posted February 12, 2010 Share Posted February 12, 2010 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? 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 More sharing options...
mikesta707 Posted February 12, 2010 Share Posted February 12, 2010 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 Link to comment https://forums.phpfreaks.com/topic/191891-need-help-with-and-stuff/#findComment-1011433 Share on other sites More sharing options...
Bikkebakke Posted February 12, 2010 Author Share Posted February 12, 2010 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!) Link to comment https://forums.phpfreaks.com/topic/191891-need-help-with-and-stuff/#findComment-1011445 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.