dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: PHP sql errors

  1. #1
    Join Date
    May 2011
    Posts
    11

    PHP sql errors

    Hello,

    I have apache running locally and my website works fine, however, on the remote server it is not working....

    I get the error

    Warning: mysql_result(): supplied argument is not a valid MySQL result resource in //user.php on line 225


    I am not sure why I am getting this error, can someone please help?

    [code]
    <?php

    session_start();
    $connection = mysql_connect('localhost', 'root', '');

    //Let us know if something is wrong with the connection
    if(!$connection){
    die('Could not connect: ' . mysql_error());
    }

    //Puts Session values into variables
    $email=$_SESSION['email'];
    $password=$_SESSION['password'];
    $userId=$_SESSION['userId'];
    $username=$_SESSION['username'];


    //ensures session credentials have been entered./
    if(!isset($_SESSION['email']) || !isset($_SESSION['password'])){
    header("Location: ./login.html");
    }

    //Let us know if something is wrong with the connection
    if(!$connection){
    die('Could not connect: ' . mysql_error());
    }

    ?>

    <?php
    mysql_select_db("winelist",$connection);
    //select all the wines user has rated
    $userRatings="SELECT image,wineName,wineYear,varietal,appearance, aroma, body, taste, finish, ratings, wineId FROM wines
    WHERE userId='$userId'";
    $userQuery = mysql_query($userRatings);


    //display the wines

    //Gets us the number of ratings
    $numberOfRatings = "SELECT wineName FROM wines WHERE userid='$userId'";
    $ratingResult = mysql_query($numberOfRatings);
    $totalRatings = mysql_num_rows($ratingResult);


    echo ("<p> Number of Ratings: " . $totalRatings . "</p>");
    ?><table>
    <tr>
    <td>image</td>
    <td>Wine Name</td>
    <td>Wine Year</td>
    <td>Varietal</td>
    <td>Aroma</td>
    <td>Appearance</td>
    <td>Body</td>
    <td>Taste</td>
    <td>Finish</td>
    </tr>

    <?php


    for($i=0;$i < $totalRatings; $i++){

    echo("<form name='edit' action='editwine.php' method='post'>");
    echo("<input type='hidden' value='" . mysql_result($userQuery,$i,'wineId') . "' name='wineId'>");

    echo("<tr>" . "<td>");
    echo("<img src ='" . mysql_result($userQuery,$i,'image') . "'width=60 height=180>");

    echo("<td>");
    echo(mysql_result($userQuery,$i,'wineName'));

    echo("<td>");
    echo(mysql_result($userQuery,$i,'wineYear'));

    echo("<td>");
    echo(mysql_result($userQuery,$i,'varietal'));

    echo("<td>");

    echo(mysql_result($userQuery,$i,'aroma'));

    echo("<td>");
    echo(mysql_result($userQuery,$i,'appearance'));

    echo("<td>");
    echo(mysql_result($userQuery,$i,'body'));

    echo("<td>");
    echo(mysql_result($userQuery,$i,'taste'));

    echo("<td>");
    echo(mysql_result($userQuery,$i,'finish'));

    echo("<div id='edit'><td>");
    echo("<input type = 'submit' value='edit' style='width:50px;'>");


    echo("</form> </tr> </td>");
    }
    echo("</table>")



    ?>
    [CODE]

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,623
    That kind of error almost always means (when it's not just a simple typo) that MySQL was not able to process the query due to some syntax error or an invalid entity name. So check to see if any of the mysql_query() calls are returning false, and if so use mysql_query() to help find out what it's complaining about.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles