headrush Posted January 23, 2016 Share Posted January 23, 2016 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"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/300633-using-mysqli-instead-of-mysql/ Share on other sites More sharing options...
Barand Posted January 23, 2016 Share Posted January 23, 2016 You cannot mix mysql_ and mysqli_ functions, Use just mysqli_ library. Quote Link to comment https://forums.phpfreaks.com/topic/300633-using-mysqli-instead-of-mysql/#findComment-1530270 Share on other sites More sharing options...
headrush Posted January 23, 2016 Author Share Posted January 23, 2016 (edited) 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 January 23, 2016 by headrush Quote Link to comment https://forums.phpfreaks.com/topic/300633-using-mysqli-instead-of-mysql/#findComment-1530271 Share on other sites More sharing options...
Barand Posted January 23, 2016 Share Posted January 23, 2016 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". Quote Link to comment https://forums.phpfreaks.com/topic/300633-using-mysqli-instead-of-mysql/#findComment-1530274 Share on other sites More sharing options...
headrush Posted January 23, 2016 Author Share Posted January 23, 2016 Hi Barand Thank you for your help In this matter It now works! I will have a look at the $age query and result Thanks again and have a great day! Quote Link to comment https://forums.phpfreaks.com/topic/300633-using-mysqli-instead-of-mysql/#findComment-1530275 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.