Errors when Hosting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tito85
Forum Contributor
Posts: 104
Joined: Sat Mar 13, 2010 11:26 am

Errors when Hosting

Post by tito85 »

Hi,

I uploaded my site to a free hosting and all is working apart for one feature. The feature is to get the rating. Using wamp server locally, everything is working fine. However on the uploaded site it is not...

The error I get is:

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/a1024187/public_html/moviedetails.php on line 190

The code in line 190 is:

Code: Select all

echo "<b>" . mysql_result($count, 0, 'ratingsgiven') . "</b> user/s submitted their rating to this movie<hr style=\"border: 1px solid #06C\" />";
Any help Please?
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Errors when Hosting

Post by flying_circus »

tito85 wrote:The error I get is:

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/a1024187/public_html/moviedetails.php on line 190
$count is not a valid sql resultset. Something is wrong with the query.
User avatar
mecha_godzilla
Forum Contributor
Posts: 375
Joined: Wed Apr 14, 2010 4:45 pm
Location: UK

Re: Errors when Hosting

Post by mecha_godzilla »

Have you checked to see how many rows your query returns? Use mysql_num_rows() to see what values you get - remembering to echo out the mysql_result() first.

HTH,

Mecha Godzilla
tito85
Forum Contributor
Posts: 104
Joined: Sat Mar 13, 2010 11:26 am

Re: Errors when Hosting

Post by tito85 »

Hi,

This is the code I am using... I am confused because on the locally wamp server it is working...

Any help please?

Code: Select all

          //Rating
          echo "<div class=\"blog2\"><h4 style=\"margin: 0\">Average User Rating</h4><hr style=\"border: 1px solid #06C\" />";
          $query = "SELECT SUM(Rating)/COUNT(0) AS averagerating FROM ratings r WHERE r.MovieID = '" . $_GET['id'] . "'";
          $averagerating = mysql_query($query);
          $query = "SELECT COUNT(0) AS ratingsgiven FROM Ratings r WHERE r.MovieID = '" . $_GET['id'] . "'";
          $count = mysql_query($query);
          echo "The average user rating of this movie is: <b>";
          if (mysql_result($averagerating, 0, 'averagerating')) {
              echo round(mysql_result($averagerating, 0, 'averagerating'), 1);
          } else
              echo "0";
          echo "/10</b><p />";
          echo "<b>" . mysql_result($count, 0, 'ratingsgiven') . "</b> user/s submitted their rating to this movie<hr style=\"border: 1px solid #06C\" />";
          //Checking if user submitted his rating already
          if (isset($_SESSION['user'])) {
              $query = "SELECT * FROM ratings WHERE UserID = '" . $_SESSION['userinfo']['id'] . "' AND MovieID = '" . $_GET['id'] . "'";
              $result = mysql_query($query);
              if (mysql_num_rows($result) > 0) {
                  echo "You already submitted your rating to this movie<p />";
                  echo "Your Rating is: <b>" . mysql_result($result, 0, 'Rating') . "/10</b>";
              } else {
                  echo "<p /><b>Submit your rating:</b>";
?>
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Errors when Hosting

Post by mikosiko »

Code: Select all

$query = "SELECT COUNT(0) AS ratingsgiven FROM Ratings r WHERE r.MovieID = '" . $_GET['id'] . "'";
this query is not returning any rows.... try to write it in this way:

Code: Select all

$query = "SELECT COUNT(0) AS ratingsgiven FROM ratings r WHERE r.MovieID = '" . $_GET['id'] . "'";
and... if you allow me to contribute to your code...
- you can improve it writing both sql sentences in just one like this

Code: Select all

  $query = "SELECT COUNT(0) AS ratingsgiven, ROUND(AVG(rating),1) AS averagerating FROM ratings r WHERE r.MovieID = '" . $_GET['id'] . 
and then display the results

Code: Select all

  $row = mysql_fetch_assoc($query);   // This will replace the 2 mysql_result that you are using
   echo "The average user rating of this movie is: <b>" . $row['averagerating']. "<br />";
   echo "<b>" . $row['ratingsgiven'] . "</b> user/s submitted their rating to this movie<hr style=\"border: 1px solid #06C\" />";
tito85
Forum Contributor
Posts: 104
Joined: Sat Mar 13, 2010 11:26 am

Re: Errors when Hosting

Post by tito85 »

Hi there tnx for your help. I did not notice that it was so case sensitive...

However i have encountered another problem in anothor thing...

Parse error: syntax error, unexpected $end in /home/a1024187/public_html/addnews.php on line 12

Cannot understand what is the error too... Hope it is a small mistake like the other one...

Code: Select all

<?php
  session_start();
  require('dbconnect.php');
  include('securitycheck.php');
  if ($isAdmin) {
      if (isset($_POST['btnCancel'])) {
          header('Location: index.php');
      } elseif (isset($_POST['btnAddNews'])) {
          $title = $_POST['txtTitle'];
          $body = $_POST['txtBody'];
          if (strlen(trim($title)) > 0 && strlen(trim($body)) > 0) {
              $insert = "INSERT INTO news (Title, Body, PostDateTime, UserID) VALUES ('" . mysql_real_escape_string($title) . "', '" . mysql_real_escape_string($body) . "', '" . date("Y-m-d H:i:s") . "', '" . $_SESSION['userinfo']['id'] . "')";
              mysql_query($insert) or die(mysql_error());
              header('Location: index.php');
          } else {
              $message = "Error: Both <b>Title</b> and <b>Body</b> are mandatory";
          }
      }
  } else {
      header('Location: index.php');
  }
?>
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Errors when Hosting

Post by mikosiko »

check your dbconnect.php and securitycheck.php files for the variable $end
tito85
Forum Contributor
Posts: 104
Joined: Sat Mar 13, 2010 11:26 am

Re: Errors when Hosting

Post by tito85 »

I have no variables $end used in the site. I don't know why it is saying this...
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Errors when Hosting

Post by flying_circus »

tito85 wrote:Parse error: syntax error, unexpected $end in /home/a1024187/public_html/addnews.php on line 12
This usually indicates a syntax error, such as a misplaced semicolon or missing closing brackets. Please post all of your code.
tito85
Forum Contributor
Posts: 104
Joined: Sat Mar 13, 2010 11:26 am

Re: Errors when Hosting

Post by tito85 »

Hi,

This is all the code of the page.

Thanks for any help!

Code: Select all

<?php
  session_start();
  require('dbconnect.php');
  include('securitycheck.php');
  if ($isAdmin) {
      if (isset($_POST['btnCancel'])) {
          header('Location: index.php');
      } elseif (isset($_POST['btnAddNews'])) {
          $title = $_POST['txtTitle'];
          $body = $_POST['txtBody'];
          if (strlen(trim($title)) > 0 && strlen(trim($body)) > 0) {
              $insert = "INSERT INTO news (Title, Body, PostDateTime, UserID) VALUES ('" . mysql_real_escape_string($title) . "', '" . mysql_real_escape_string($body) . "', '" . date("Y-m-d H:i:s") . "', '" . $_SESSION['userinfo']['id'] . "')";
              mysql_query($insert) or die(mysql_error());
              header('Location: index.php');
          } else {
              $message = "Error: Both <b>Title</b> and <b>Body</b> are mandatory";
          }
      }
  } else {
      header('Location: index.php');
  }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="CSSWebStyles/style.css" />
<title>Add News</title>
</head>
<body>
<div id="website">
<?php
  include('banner.php');
?>
<?php
  //checking if the user is an administrator
  if (isset($_SESSION['superadmin'])) {
      if ($_SESSION['superadmin'])
          include('adminmenu.php');
  }
?>
<div id="content">
<div id="contentleft">
<h2>Add News</h2>
<?php
  if (isset($message)) {
      echo "<center>$message</center>";
      unset($message);
  }
?>
<form method="post">
<table>
<tr>
<td>
Title
</td>
<td>
<input type="text" style="width: 300px;" name="txtTitle" />
</td>
</tr>
<tr>
<td valign="top">
Body
</td>
<td>
<textarea name="txtBody" rows="7" cols="45"></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="btnAddNews" value="Add" />&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="btnCancel" value="Cancel" />
</td>
</tr>
</table>
</form>
</div>
</div>
<?php
  //will include the code from footer.php file
  include('footer.php');
?>
</div>
</body>
</html>
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Errors when Hosting

Post by flying_circus »

I don't see anything out of the ordinary in this file, but I suspect the culprit might be in one of the includes:
  • dbconnect.php
  • securitycheck.php
  • banner.php
  • adminmenu.php
  • footer.php
tito85
Forum Contributor
Posts: 104
Joined: Sat Mar 13, 2010 11:26 am

Re: Errors when Hosting

Post by tito85 »

What i did is that in the following line...

'" . date("Y-m-d H:i:s") . "'

I changed it to: '" . date('Y-m-d H:i:s') . "'

It seems to be working...
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Errors when Hosting

Post by flying_circus »

Interesting... thanks for posting the solution.
Post Reply