Jump to content

Recommended Posts

Hi,

​On the below script I get this error

Warning mysql_result() expects parameter 1 to be resource, object given in data.php on line 33

 

On another page there is a text box and button,when button is pressed the below file checks if there's a value in the text box, if it's in the database and if it is in the database it displays the results. The below case results being the name and age.

 

In the below I tried to change the MSQL to MSQLI as much as I could except I'm stuck with line 33 which contains

 

$age = mysql_result($age, 0);

Any help with this would be much appreciated. Thanks
 

 

This is the Data.php that the error is contained

<?php

$db = new mysqli('localhost','user','pass,'testing');

if($db->connect_errno) {

//echo $db->connect_error;
die('<br>Oops! we are having some problems, this is currently being fixed.');
}



$name = mysqli_real_escape_string($db,$_POST['name']);
 

if($name==NULL)
     echo "Please enter a name!";
else
   
{
   
       $age  = mysqli_query($db,"SELECT age FROM rates.People2 WHERE name='$name'");
       $age_num_rows = mysqli_num_rows($age);
       

 
       if($age_num_rows==0)
          echo "Name does not exists!";
       else

        {

      $age = mysql_result($age, 0);

      echo "$name's age is $age";

      }


    }

?>
Link to comment
https://forums.phpfreaks.com/topic/300633-using-mysqli-instead-of-mysql/
Share on other sites

Thanks for your reply :)

 

 

I understand I can not mix them, I'm just trying to figure out what I should write using Mysqli for the below code,

 

$age = mysql_result($age, 0);

 

 

Any ideas?

 

Thanks again

Edited by headrush

There is no direct equivalent of mysql_result(), which was inefficient anyway.

 

You would fetch the row then reference that to get the data

$row = mysqli_fetch_row($age);
echo $row[0];

Bad idea to have your age variable and your query result both with the same "$age".

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.