RichiT81 Posted July 16, 2009 Share Posted July 16, 2009 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 $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 Quote Link to comment https://forums.phpfreaks.com/topic/166184-solved-supplied-argument-is-not-a-valid-mysql-link-resource/ Share on other sites More sharing options...
kickstart Posted July 16, 2009 Share Posted July 16, 2009 Hi Looks like the parameters are the wrong way round on the mysql_query:- Try this:- $result = mysql_query($query,$dbc) or die('Error querying database.'); All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/166184-solved-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-876343 Share on other sites More sharing options...
RichiT81 Posted July 16, 2009 Author Share Posted July 16, 2009 Thanks Keith, I have tried your suggestion and now get the following message: Error querying database. Quote Link to comment https://forums.phpfreaks.com/topic/166184-solved-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-876345 Share on other sites More sharing options...
RichiT81 Posted July 16, 2009 Author Share Posted July 16, 2009 Forget that, got it working! Thanks very much for your help! Quote Link to comment https://forums.phpfreaks.com/topic/166184-solved-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-876347 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.