I have a SQL query to get my id and insert a new id into the database. How am I supposed to alert the user if he has not entered in anything in the textbox before submitting? What should I add?
Here is my code:
if ($_GET['username'])
{
$result = mysql_query("SELECT * FROM users WHERE user_name = '$_GET[username]'");
if ($user = mysql_fetch_assoc($result))
{
$_SESSION['user_id'] = $user['user_id'];
$_SESSION['user_name'] = $user['user_name'];
}
else
{
mysql_query("INSERT INTO `personality_test`.`users` (`user_name`)VALUES ('$_GET[username]');");
$_SESSION['user_id'] = mysql_insert_id();
$_SESSION['user_name'] = $_GET['username'];
}
}
if ($_SESSION['user_id'])
{
$result = mysql_query("SELECT * FROM users WHERE user_id = '$_SESSION[user_id]'");
$row = mysql_fetch_assoc($result);
$user_result = json_decode($row['user_result'], true);
if (!empty($user_result))
{
header('Location:result.php');
}
else
{
header('Location:index.php');
}
}