mysql insertion problem!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pavanesh2009
Forum Commoner
Posts: 30
Joined: Wed Jan 13, 2010 7:24 am

mysql insertion problem!!

Post by pavanesh2009 »

Hello All,
I am getting value from a form & trying to insert it into database table called 'trees'.
everthing working fine except species_id into trees table.I am getting warning:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/seasonwatch/tracktrees.php on line 14

Please suggest what mistake i am doing?
Thanks in Advance!!

$specresult = mysql_query("SELECT * FROM Species_master WHERE species_id=".$_POST[species_master1].";");
while ($specdata = mysql_fetch_array($specresult))
{
}
$sql1 = "INSERT INTO trees
(tree_desc,is_fertilised,
is_watered,species_id,tree_location_id)
VALUES
('$_POST[tree_desc]',
'$_POST[is_fertilized]',
'$_POST[is_watered]',
'$specdata',
'$_POST[tree_location_id]'
)";
mysql_query($sql1,$link)or die("Insertion Failed:" .mysql_error());
User avatar
Grizzzzzzzzzz
Forum Contributor
Posts: 125
Joined: Wed Sep 02, 2009 8:51 am

Re: mysql insertion problem!!

Post by Grizzzzzzzzzz »

pavanesh2009 wrote:Hello All,
I am getting value from a form & trying to insert it into database table called 'trees'.
everthing working fine except species_id into trees table.I am getting warning:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/seasonwatch/tracktrees.php on line 14

Please suggest what mistake i am doing?
Thanks in Advance!!

$specresult = mysql_query("SELECT * FROM Species_master WHERE species_id=".$_POST[species_master1].";");
while ($specdata = mysql_fetch_array($specresult))
{
}
$sql1 = "INSERT INTO trees
(tree_desc,is_fertilised,
is_watered,species_id,tree_location_id)
VALUES
('$_POST[tree_desc]',
'$_POST[is_fertilized]',
'$_POST[is_watered]',
'$specdata',
'$_POST[tree_location_id]'
)";
mysql_query($sql1,$link)or die("Insertion Failed:" .mysql_error());
missing quotation marks within your POSTS?

eg:

Code: Select all

 
$_POST[species_master1] 
 
should be

Code: Select all

 
$_POST["species_master1"]
 
pavanesh2009
Forum Commoner
Posts: 30
Joined: Wed Jan 13, 2010 7:24 am

Re: mysql insertion problem!!

Post by pavanesh2009 »

Thank you vey much for your kind help!!

Grizzzzzzzzzz wrote:
pavanesh2009 wrote:Hello All,
I am getting value from a form & trying to insert it into database table called 'trees'.
everthing working fine except species_id into trees table.I am getting warning:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/seasonwatch/tracktrees.php on line 14

Please suggest what mistake i am doing?
Thanks in Advance!!

$specresult = mysql_query("SELECT * FROM Species_master WHERE species_id=".$_POST[species_master1].";");
while ($specdata = mysql_fetch_array($specresult))
{
}
$sql1 = "INSERT INTO trees
(tree_desc,is_fertilised,
is_watered,species_id,tree_location_id)
VALUES
('$_POST[tree_desc]',
'$_POST[is_fertilized]',
'$_POST[is_watered]',
'$specdata',
'$_POST[tree_location_id]'
)";
mysql_query($sql1,$link)or die("Insertion Failed:" .mysql_error());
missing quotation marks within your POSTS?

eg:

Code: Select all

 
$_POST[species_master1] 
 
should be

Code: Select all

 
$_POST["species_master1"]
 
Post Reply