Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sites/miraclehosting.co.uk/public_html/scdc.php on line 169
---------------------------------------------------------------------------------------
Can anyone help here this is doin ma ed in!! gggrrrhhhhh
i get the above result when Load the script into the browser.
here is the form:

<form action="scdc.php" method="post" name="chooser">
  <label>Select Parish </label>     
  <select name="chooser" id="chooser">
    <option value="1">Abington Pigotts</option>
    <option value="2">Arrington</option>

    <option value="3">Barbraham</option>
    <option value="4">Balsam</option>
    <option value="5">Bar Hill</option>
    <option value="6">Barrington</option>
    <option value="7">Barton</option>
    <option value="8">Bassingbourn-Cum-Kneesworth</option>
</select>
  <input type="submit" name="select" value="select"> 
</form>

although there is 97 options i just havent given all of them for obvious reasons.
Here is the php:

<?php

// get variable after selecting something from the dropdown with name 'chooser'
$select = $_POST['select'];

// if something has been chosen
if (!empty($select)) {

// get the chosen value
$chooser = $_POST['chooser'];

// select the type from the database
// database connection details (change to whatever you need)
$HOST = 'localhost';
$DATABASE = '******';
$USER = '********';
$PASSWORD = '********';

// connect to database
if(!$conn=mysql_connect('localhost','web244-scdc','hartley07')) {
echo("<li>Can't connect to $HOST as $USER");
echo("<li>mysql Error: ".mysql_error());
die;
}

// select database
if (!mysql_select_db($DATABASE,$conn)) {
echo("<li>We were unable to select database $DATABASE");
die;
}

// if everything successful create query
// this selects all rows where the type is the one you chose in the dropdown
// * means that it will select all columns, ie name and type as i said above
$sql_query = "SELECT * FROM base_data WHERE type='$chooser'";

// get the data from the database
$result = mysql_query($sql_query,$conn);

// output data
while ($details = mysql_fetch_array($result, MYSQL_ASSOC)) {  
// print out the name
echo('Parish: '.$details['ParishName'].' - ');
// print out the type
echo('Owner Occupier Household: '.$details['OwnerOccupierHousehold'].'<br>');
}

// close mysql connection
mysql_close($conn);

}

?>

The line highlighted in red is causing the problems. please help?

try your query as:

$sql_query = "SELECT * FROM base_data WHERE type='".$chooser."'";

notice $chooser has been properly removed from the leteral sentence.

Your query might be failing. Use

$result = mysql_query($sql_query,$conn) or die('Invalid query: ' . mysql_error());

Your query might be failing. Use

$result = mysql_query($sql_query,$conn) or die('Invalid query: ' . mysql_error());

OK this correct but.........Now iget this error Invalid query: Unknown column 'type' in 'where clause'

what are the columns called in the database?

That error just told you it couldn't find the asked column? and what is you query right now? (SELECT....)

But i would like to bring to view a full row thatt i plan to display in a table? do you think i have used the right script or have a messedup?

Just look at the error

Invalid query: Unknown column 'type' in 'where clause'

There is no type column to perform the where clause against.
Show us the layout of the table( what are the columns in base_data?)

ok the table was too big to copy and paste so i decided to export it to word and make it downloadble hope this is enough for you
download here thanks again guys

All you had to post was the structure, not the dump of the database. I would explain to you how much is wrong with the design of the table but instead I'll give you the quick fix.

<form action="scdc.php" method="post" name="chooser">
  <label>Select Parish </label>
  <select name="chooser" id="chooser">
    <option value="Abington Pigotts">Abington Pigotts</option>
    <option value="Arrington">Arrington</option>
    <option value="Barbraham">Barbraham</option>
    <option value="Balsam">Balsam</option>
    <option value="Bar Hill">Bar Hill</option>
    <option value="Barrington">Barrington</option>
    <option value="Barton">Barton</option>
    <option value="Bassingbourn-Cum-Kneesworth">Bassingbourn-Cum-Kneesworth</option>
  </select>
  <input type="submit" name="select" value="select">
</form>
$sql_query = "SELECT * FROM base_data WHERE ParishName LIKE '$chooser'";

You my freind are an absolute GENIUS!! thanks for the help can i add you as a contact incase i ever get stuck? Also i saw what i did wrong in the script i get it now also what was wrong with the table breifly

This article has been dead for over six months. Start a new discussion instead.