teknospr Posted March 8, 2011 Share Posted March 8, 2011 Im trying to insert some values automatically into a table once the form loads, but Im getting an error. Here is the code <?php $aid = $_GET['aid']; $sd = $_GET['sd']; ?> <style> #message {margin:20px; padding:20px; display:block; background:#cccccc; color:#cc0000;} </style> <div id="message">Your notification has been submitted.</div> <div style="text-align:center "> <?php $connection = mysql_connect("localhost", "username", "password"); mysql_select_db("articles", $connection); $query="INSERT INTO broken_links (articleid, article) VALUES ('$aid', '$sp')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Submitted"; mysql_close($con) ?> <table border="0" cellpadding="3" cellspacing="3" style="margin:0 auto;" > <input type="submit" id="Login" value=" Thank you. Please press to close " onclick="tb_remove()"></td> </tr> </table> </div> Any help will be appreciated Quote Link to comment https://forums.phpfreaks.com/topic/229991-insert-into-mysql-table/ Share on other sites More sharing options...
HuggieBear Posted March 8, 2011 Share Posted March 8, 2011 The error would help. Quote Link to comment https://forums.phpfreaks.com/topic/229991-insert-into-mysql-table/#findComment-1184532 Share on other sites More sharing options...
teknospr Posted March 8, 2011 Author Share Posted March 8, 2011 mysql_query(): supplied argument is not a valid MySQL-Link resource in /mounted-storage/home7/sub007/sc30390-PTUD/xxxxxxxxxxxxx.com/form2.php on line 26 Quote Link to comment https://forums.phpfreaks.com/topic/229991-insert-into-mysql-table/#findComment-1184533 Share on other sites More sharing options...
HuggieBear Posted March 8, 2011 Share Posted March 8, 2011 That means that your database connection failed, or you're specifying the wrong connection handle. In your case it's the latter. Change: mysql_query($sql,$con) To: mysql_query($query,$connection) As those are the variable names you've used earlier in your script. Quote Link to comment https://forums.phpfreaks.com/topic/229991-insert-into-mysql-table/#findComment-1184536 Share on other sites More sharing options...
Mahngiel Posted March 8, 2011 Share Posted March 8, 2011 Look at your code more thoroughly: you defined $sd = $_GET['sd']; ... $query="INSERT INTO broken_links (articleid, article) VALUES ('$aid', '$sp')"; Quote Link to comment https://forums.phpfreaks.com/topic/229991-insert-into-mysql-table/#findComment-1184539 Share on other sites More sharing options...
teknospr Posted March 8, 2011 Author Share Posted March 8, 2011 Fixed that too. Now Im getting this error: Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /mounted-storage/home7/sub007/sc30390-PTUD/***********.com/form2.php on line 31 Quote Link to comment https://forums.phpfreaks.com/topic/229991-insert-into-mysql-table/#findComment-1184541 Share on other sites More sharing options...
HuggieBear Posted March 8, 2011 Share Posted March 8, 2011 Fixed that too. Now Im getting this error: Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /mounted-storage/home7/sub007/sc30390-PTUD/***********.com/form2.php on line 31 Why do you think that is? Look at what I asked you to change (Connection variable name!) Quote Link to comment https://forums.phpfreaks.com/topic/229991-insert-into-mysql-table/#findComment-1184542 Share on other sites More sharing options...
teknospr Posted March 8, 2011 Author Share Posted March 8, 2011 Yes I changed. Also changed the mysql closing statement and it fixed the last error. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/229991-insert-into-mysql-table/#findComment-1184554 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.