I am writing a php file that takes values from a form and posts them to a mysql database. One of the table fields is a button link to a video that will play when clicked. It works great if I go into the database and manually add the link. However my PHP insert causes an error. Please have a look at this code:
$fileName = "video_".$id.".html";
$link = "<a href=\"javascript: void(0)\" onclick=\"MM_openBrWindow('videos/".$fileName."','','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=420,height=390')\"><button class=\"count\">Watch Video</button></a>";
$con=mysqli_connect("localhost","videomanager","password","my_database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO video_list (date, title, description, link) VALUES('$_POST[date]','".mysqli_real_escape_string($_POST['sermon'])."','".mysqli_real_escape_string($_POST['description'])."','$link' )";
if (!mysqli_query($sql,$con))
{
die('Error: ' . mysqli_error());
}
echo "This video has been successfully added to the video database.";
mysqli_close($con);
If I look at $link by doing something like: echo $link; die(); it produces a page with the button and the code in the button looks good. Is it how I am trying to insert it? Thanks for your help!