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
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.