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
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
Link to comment
Share on other sites

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
Share on other sites

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.