Ok, so I need to make the PHP form detect whether a string starts with the substring "DonVito:" or not. However, it's always returning a false even when DonVito: is present.
Thanks. Also, I'd like it in a way that it returns true only if DonVito: is at the beginning of the string, and not anywhere else in the String (ex. middle etc)
Code:
<?php
$host="localhost"; // Host name
$username="****"; // Mysql username
$password="***"; // Mysql password
$db_name="*******"; // Database name
$tbl_name="post"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("ERROR: Cannot connect to MySQL Server on 'localhost'.<br/><br/><i>Remember this is only a prototype demo!</i>");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$postcontent=$_POST['like_content'];
// To protect MySQL injection (more detail about MySQL injection)
$postcontent = stripslashes($postcontent);
$postcontent = mysql_real_escape_string($postcontent);
$sql="INSERT INTO $tbl_name (post_content) VALUES('$postcontent')";
mysql_query($sql)or die("database error");
$homeID = "DonVito:";
if (strpos($postcontent, $homeID)===true){
header("location:result.php?p=$postcontent&mail=Sent");
}
else{
//redirect back to site
header("location:result.php?p=$postcontent&debug=noMailSent");
}
?>
Comment