Jump to content

Insert into mysql table


teknospr

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/229991-insert-into-mysql-table/
Share on other sites

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.

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!)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.