I don't really know why I have this issue, I have looked over my code; and all looks well.
Here my "addtofavorites.php" page
<?php
$con = mysql_connect("localhost","root","student");
if (!$con);
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("tvid", $con);
$sql="INSERT INTO tv (userid, favorites) VALUES ('345','77');"
if (!mysql_query($sql,$con));
{
die('Error: ' . mysql_error());
}
echo "Your Video was Added To Your Favorites";
mysql_close($con);
?>
Here where I reference it on a Ajax listen event (listen for a button click)
$(document).ready(function () {
$('#button_1').click(function(e){
e.preventDefault();
e.stopPropagation();
favfunct();
});
});
function favfunct() {
$.ajax({
type: "POST",
url: "js/addtofavorites.php",
data: { "get" : "runfunction", "action" : "favorites1" },
success: function (response) {
alert ("successfully loaded")
}
});
}
Any error I have? or Advice You might be able to give?
I think this is wrong
if (!$con);
{
die('Could not connect: ' . mysql_error());
}
This line
if (!$con);
should be
if (!$con)
NOTE: Removed the ;
Here, try this piece:
<?php
$con = mysql_connect("localhost","root","student");
if (!$con) { //mis-placed semicolon here
die('Could not connect: ' . mysql_error());
}
mysql_select_db("tvid", $con);
$sql="INSERT INTO tv (userid, favorites) VALUES ('345','77');"; //semicolon here
if (!mysql_query($sql,$con));
{
die('Error: ' . mysql_error());
}
echo "Your Video was Added To Your Favorites";
mysql_close($con);
?>
You current page will insert the values 345|77
repeatedly into the database.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.