Jump to content

Help with updating tables


chomedey

Recommended Posts

Hello all,

 

Does anyone know what is wrong with this?  It's a rating update page, where it selects rating info from the database, adds to that info, and then updates it back to the db.

 

There are no error messages - but my table is not being updated.

 

Any help much appreciated.

 

Cheers.

 

Julian

 

<?php

 

//Call functions

 

require_once('mds_fns.php');

 

//Call header

 

do_html_header('Update Ratings');

do_top_display_bar();

do_second_display_bar();

 

//Connect to db

 

$dbc = mysql_connect('localhost', 'root', 'One4Two');

mysql_select_db('mds');

 

 

if ((isset($_GET['id']) && is_numeric($_GET['id'])) && (isset($_GET['rate']) && is_numeric($_GET['rate'])))

 

 

{

 

$query = "SELECT total_rating, total_ratings, num_votes

FROM deepshares

WHERE entryID={$_GET['id']} LIMIT 1";

 

if ($r = mysql_query($query))

 

{

while ($row = mysql_fetch_array($r))

{

$total_rating = $row['total_rating'];

$total_ratings = $row['total_ratings'];

$num_votes = $row['num_votes'];

$num_results = mysql_num_rows($r);

 

}

}

 

$total_ratings = ($total_ratings+($_GET['rate']));

$num_votes = ($num_votes+1);

$total_rating = ($total_ratings / $num_votes);

 

$query = "UPDATE deepshares

SET total_rating='$total_rating'

AND num_votes='$num_votes'

AND total_rating='$total_ratings'

WHERE entryID={$_GET['id']} LIMIT 1";

 

if (@mysql_query($query))

{

print '<p>Thankyou for your vote.  The rating for this entry has been updated.</p>';

}

else

{

print '<p>There was a problem updating the record.</p>';

}

}

do_html_footer();

 

?>

Link to comment
https://forums.phpfreaks.com/topic/191679-help-with-updating-tables/
Share on other sites

It output

 

Thankyou for your vote. The rating for this entry has been updated.

 

I'm pretty sure it's in the updating, and I've recreated the complete table now and still nothing.  The weird thing is that it always says "Thankyou for your vote" but then it hasn't actually sent the data (or it has but it hasn't registered it).  Even when I ascribe integers to the fields it doesn't seem to take them.  I'm flummoxed.

 

Code used was:

 

//Connect to db

 

$dbc = mysql_connect('localhost', 'root', 'One4Two');

mysql_select_db('mds');

 

 

//if ((isset($_GET['id']) && is_numeric($_GET['id'])) && (isset($_GET['rate']) && is_numeric($_GET['rate'])))

 

 

if ((isset($_GET['id']) && is_numeric($_GET['id'])) && (isset($_GET['rate']) && is_numeric($_GET['rate'])))

{

$query = "SELECT total_rating, total_ratings, num_votes

FROM deepshares

WHERE entryID={$_GET['id']} LIMIT 1";

 

if ($r = mysql_query($query))

 

{

while ($row = mysql_fetch_array($r))

{

$total_rating = $row['total_rating'];

$total_ratings = $row['total_ratings'];

$num_votes = $row['num_votes'];

$num_results = mysql_num_rows($r);

 

}

}

else

{

echo "Wrong GET parameters";

}

 

 

 

Sorry - should have included rest of code otherwise output makes no sense:

 

$total_ratings = ($total_ratings+($_GET['rate']));

$num_votes = ($num_votes+1);

$total_rating = ($total_ratings / $num_votes);

 

$query = "UPDATE deepshares

SET total_rating='$total_rating'

AND num_votes='$num_votes'

AND total_rating='$total_ratings'

WHERE entryID={$_GET['id']} LIMIT 1";

 

if (@mysql_query($query))

{

print '<p>Thankyou for your vote.  The rating for this entry has been updated.</p>';

}

else

{

print '<p>There was a problem updating the record.</p>';

}

}

 

 

do_html_footer();

 

?>

what about change it a bit like this

 

$query = "UPDATE deepshares

      SET total_rating='$total_rating'

      AND num_votes='$num_votes'

      AND total_rating='$total_ratings'

      WHERE entryID={$_GET['id']} LIMIT 1";

 

echo $query;

 

if (@mysql_query($query))

{

//...

}

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.