I'm making a simple 'army' game in PHP. I'm using a database, so you can create an account, like a username and a army (name). Using the database, I can check if you have created an army, before you advance to the game. Unfortunately, I don't know how.
So this is my code:
<?php
include('connect.php'); //a file where I connect to my database
session_start();
//now I want to check if the person has created an army:
$query = "SELECT army FROM Account WHERE username = $_SESSION['username']";
if (mysql_num_rows(mysql_query($query))==0) {
echo "Please create an army to continue";
}
else {
echo "Have fun playing this game";
}
?>
Btw: $_SESSION['username'] excists. I echooed it and it displayed the username.
I think the fault has something to do with mysql_num_rows(mysql_query($query))==0
, but I'm not sure.
syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
This is the error my browser gives.
Now, this code doesn't work, seeing the error the browser gives. Does anyone know what I should do to achieve my goal in checking for somoene's army excistence in my database for making sure this person doesn't start a battle without an army and for making sure my browser doesn't give any error?
Thank you.