Jump to content

inserting data into a table


freemancomputer

Recommended Posts

I am having a problem with updating 2 table entry's at time. If i take out the num_votes it will add the rating. I'm not sure if I'm not doing the math correctly or if its not being entered correctly, then again I could be way off.

 

@mysql_select_db($database) or die( "Unable to select database");
$title = mysql_real_escape_string(urldecode($_POST["title"]));
$rating= mysql_real_escape_string($_POST['rating']);
$find_query="SELECT * FROM movie WHERE title='$title'";
$find_result=mysql_query($find_query);

$find_rating= mysql_result($find_result, $i, "rating");
$find_num_votes= mysql_result($find_result, $i, "num_votes")

$sum_rating = $find_rating + $rating;
$sum_num_votes = $find_num_votes + 1;


include"scripts/connect.php" ;
mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$title= mysql_real_escape_string($_POST['title']);
$error = '';

$sql_rating = "UPDATE movie SET rating='$sum_rating' num_votes='$sum_num_votes' WHERE title='$title'"; 
mysql_query($sql_rating) or die (mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/261610-inserting-data-into-a-table/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.