GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Jul-2009, 05:17
RichiT81 RichiT81 is offline
New Member
 
Join Date: Jul 2009
Posts: 1
RichiT81 is on a distinguished road

supplied argument is not a valid MySQL-Link resource


Hi,

I am new to this, I am using a Head First PHP & MySQL book and am working on my second task which is inserting data entered via a web form into a MySQL database.

I have tested the MySQL statement direct in an SQL query and it works fine, but when ever i submit the form I get the following error:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/research/public_html/phptest/aliens/report.php on line 32
Error querying database.


Here is my php code:

PHP Code:

<?php 
$first_name = $_POST['firstname']; 
$last_name = $_POST['lastname']; 
$when_it_happened = $_POST['whenithappened']; 
$how_long = $_POST['howlong']; 
$how_many = $_POST['howmany']; 
$alien_description = $_POST['aliendescription']; 
$what_they_did = $_POST['whattheydid']; 
$fang_spotted = $_POST['fangspotted']; 
$other = $_POST['other']; 
$email = $_POST['email']; 

$dbc = mysql_connect('localhost', 'research_admin', '*****', 'research_aliendatabase') 
or die('Error connecting to MySQL server.'); 

$query = "INSERT INTO aliens_abduction (first_name, last_name, when_it_happened, how_long, " . 
"how_many, alien_description, what_they_did, fang_spotted, other, email) " . 
"VALUES ('$first_name', '$last_name', '$when_it_happened', '$how_long', '$how_many', " . 
"'$alien_description', '$what_they_did', '$fang_spotted', '$other', '$email')"; 

$result = mysql_query($dbc, $query) 
or die('Error querying database.'); 

mysql_close($dbc); 

echo 'Thanks for submitting the form.<br />'; 
echo 'You were abducted ' . $when_it_happened; 
echo ' and were gone for ' . $how_long . '<br />'; 
echo 'Number of aliens: ' . $how_many . '<br />'; 
echo 'Describe them: ' . $alien_description . '<br />'; 
echo 'The aliens did this: ' . $what_they_did . '<br />'; 
echo 'Was Fang there? ' . $fang_spotted . '<br />'; 
echo 'Other comments: ' . $other . '<br />'; 
echo 'Your email address is ' . $email; 
?>


Any help would be greatly appreciated as I am at a loss!

Thanks in advance.

Richi
  #2  
Old 16-Jul-2009, 07:12
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: supplied argument is not a valid MySQL-Link resource


The arguments to the mysql_query() call are reversed; the query is first, the link is second, so just swap the arguments.

Note that if you were using the mysqli_query() function (notice the 'i'), then the supplied arguments are in the correct order.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Str_Misaligned in Double Link List Peter_APIIT C Programming Language 1 29-Feb-2008 21:50
Cpanel downgrade MYSQL 4.1.X to MySQL 4.0.xx Webhosting-live Web Hosting Forum 1 01-Sep-2006 03:54
not a valid MySQL-Link resource phpnewbie MySQL / PHP Forum 1 24-Jun-2005 20:11
Not a Valid MySQL result phpnewbie MySQL / PHP Forum 9 22-Feb-2005 22:23
gzwrite(): supplied argument is not a valid stream resource in JdS MySQL / PHP Forum 2 24-Mar-2003 08:57

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:38.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.