Click to See Complete Forum and Search --> : Argument Not Valid PHP/SQL


jsbert
06-12-2009, 06:22 PM
I've been busting my head looking a this simple code and I can't find why I keep on getting a warning that stops the form from displaying, although it inserts the query in the DB fine? I guess I need a pair of fresh eyes, Before hand thank you much.

<?php // This Php Script actually inserts the info & shows its results.

$con = mysql_connect("localhost","root");
if (!$con) { die('Could not connect: ' . mysql_error()); }

mysql_select_db("lab", $con);

//foreach ($_POST as $field => $value){ echo $field. ' = ' .$value. '<br>'; }

$query = "INSERT INTO lab.ambulatorio (id, date, billNum, client, amount)
VALUES ('$_POST[id]', '$_POST[date]', '$_POST[billNum]', '$_POST[client]', '$_POST[amount]')";

//echo $query;

$result = mysql_query($query);

include("outPatientResults.ini");

while(@$row = mysql_fetch_array($result)){
include("outPatientResults.ini");
}

//$result = mysql_query($query,$con);
//$nrows=mysql_num_rows($result);

mysql_close($con);

?>

------------------------------------------------------

OUTPUT

id = 6
date = 2009-06-10
billNum = 00405
firstName = María
lastName = Rincón
client =
amount = 75
submit = Enviar


INSERT INTO lab.ambulatorio (id, date, billNum, client, amount) VALUES (' 6 ', '2009-06-10', '00405', '', '75')

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\Muestrario\demo\outPatientResults.php on line 21

-------------------------------------------------------------
DB TYPES

id int, date date, billNum int, client string, amount int

hawken
06-12-2009, 07:59 PM
try this:

while($row = mysql_fetch_assoc($result)){

svidgen
06-12-2009, 08:09 PM
An INSERT statement will not return a result set that you can call mysql_fetch_assoc() on. Rather, it returns TRUE/FALSE: http://us2.php.net/function.mysql-query

Or are we missing some of the queries you're performing ... ? (I think yes)

jsbert
06-12-2009, 08:11 PM
I am going to try it. But what's the difference, if I may ask? I thought mysql_fetch_array retrieved an associative array, doesn't it?

jsbert
06-12-2009, 08:14 PM
I don't think I am missing anything, but I am going to check and if I do I will post it. Thanks

hawken
06-12-2009, 08:15 PM
I think Svidgen is the one you should listen to here. I'm a newbie so this might be a bit over my head right now.

jsbert
06-12-2009, 08:46 PM
I just check. That's the entire script and query. I can't find the reason why it doesn't let me show outPatientResults.ini. Do you have any ideas?

svidgen
06-12-2009, 09:07 PM
Take a look at that error one more time ...

... Now, per my previous hint, may we see the contents of outPatientResults.ini, please?

jsbert
06-17-2009, 07:34 PM
Svidgen, sorry.

I've been pretty busy, so I didn't connect.
I found out what the problem with the script was. I guess I was way to tired to realize it at that time.

The problem is that I was inserting data, and I was trying to retrieve the results, but I wasn't using a select query.

Thanks anyway to everyone.

Anyway does any one know how to verify whether an insertion was succesful with out having to use a select statement?