DLR Posted January 27, 2007 Share Posted January 27, 2007 Hi all,The following code seeks to check input against existing values on a database. But I get the error message "Wrong datatype for second argument " in the line starting [color=red]if( ! in_array . . . . etc)[/color] .I have changed everything I can think of but cannot solve this.Your help will be appreciated.[code] //check selection against table data //information from table "category" $query = "SELECT category_id,category FROM categories"; $result = mysql_query($query) or die(mysql_error());if (! in_array($_POST['top_category'], $result)) { header ("Refresh: 0; URL='admin.php'"); } [/code] Link to comment https://forums.phpfreaks.com/topic/35952-wrong-data-type-has-got-me-in-knots/ Share on other sites More sharing options...
kenrbnsn Posted January 27, 2007 Share Posted January 27, 2007 The variable $result holds a pointer to the result data set, you need to use one of the mysql_fetch functions to actually retrieve the data.Probably something like:[code]<?php$result = mysql_query($query) or die(mysql_error());$rw = mysql_fetch_assoc($result);if (! in_array($_POST['top_category'], $rw['catagory'])) header ("Refresh: 0; URL='admin.php'");?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/35952-wrong-data-type-has-got-me-in-knots/#findComment-170518 Share on other sites More sharing options...
DLR Posted January 27, 2007 Author Share Posted January 27, 2007 Great Ken,Almost there! When I run the code with the first item selected (i.e. the key =1 ), it works fine. (the first item in the dta base is key=1, data=Advertising)As soon as I choose any other one from my select box it tells me this si not in he array. I assume that the array is limited to the first line from the database, OR my code[code]$info = mysql_fetch_assoc($result);[/code]is faulty in some way.Any suggestions?Thanks,David Link to comment https://forums.phpfreaks.com/topic/35952-wrong-data-type-has-got-me-in-knots/#findComment-170523 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.