I am trying to make a chat for my steam site, but anytime I try to post something it won't add it to my database. Here is the code I'm running:
<?php
//Connect to database
include ('steamauth/userInfo.php');
$link = mysqli_connect("*******", "********", "*******", "******") or die("Error" . $link->connect_error);
//Form var
$name = $steamprofile['personaname'];
@$text = $_POST["text"];
//Error messages
$notext = "<p><strong>Enter Text</strong></p>";
//On submit
if(@$_POST['submit']){
if(!$text){
@$errors .= $notext;
}else{
$text = filter_var($text, FILTER_SANITIZE_STRING);
}
if(@$errors){
echo "<div class='errors'> " . $errors ."</div>";
}else{
//No errors, prepare database
$tblname = "Messages";
$name = mysqli_real_escape_string($link, $name);
$text = mysqli_real_escape_string($link, $text);
//Insert into database
$sql = "INSERT INTO Messages (text, name) VALUES ('$text', '$name')";
mysqli_query($link, $sql);
}
}
?>
<?php
if(isset($_SESSION['steamid'])){
echo "<div id='send'>
<form action='#' method='post'>
<input type='text' id='text' placeholder='Send Message ...' class='input' name='text'>
<input type='submit' id='submit' value=''>
</form>
</div>";
}else{
echo "<div class='error' id='chat_log_in'>Please Log In</br>to chat</div>";
}
?>
I'd say there is something wrong with the $name variable. Can anyone tell me what I did wrong in here please.