Jump to content

wrong data type has got me in knots!


DLR

Recommended Posts

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

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
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

Archived

This topic is now archived and is closed to further replies.

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