Jump to content

Entering Data into SQL database


poleman

Recommended Posts

I hope you can help... I had this working a minute ago and now its gone and I'm getting

and error code: Duplicate entry '0' for key 1

 

I really hope you can help me. Thank you.

 

The php code is as follows:

 

<?php

$con = mysql_connect

("db778.oneandone.co.uk","dbo191523062","zfMcsqnB");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }mysql_select_db("db191523062", $con);$sql="INSERT INTO phpbb_users(username,

user_email)

VALUES

('$_POST[name]','$_POST[useremail]')";if (!mysql_query

($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

echo "1 record added";mysql_close($con)

?>

 

with the form html code as follows:

 

<form method="POST" action="newslettertest4.php">

                        Name: <input type="text" name="name" size="20">

 

            Email:  <input type="text" name="useremail" size="20">

 

         

 

                       <button name="B1">Subscribe</button></p>

          </form>

 

 

 

Thanks

 

Richard

Link to comment
Share on other sites

lol u got a messy way of doing it

ive made you the whole page

<?php
$host='db778.oneandone.co.uk';  
$username='dbo191523062'; 
$pass='zfMcsqnB'; 
$database='db191523062'; 

mysql_connect ($host, $username, $pass); 

mysql_select_db($database) or die('Could not connect to the Database'); 

if (isset($_POST["name"])) {
$useremail = $_POST["useremail"];
$name = $_POST["name"];
if($rsname==NULL) {
echo "some form of error";
}else{
$query = "INSERT INTO phpbb_users(`username`, `user_email`) VALUES('$name','$useremail')";
mysql_query($query) or die(mysql_error());
echo "succesfull";
}
}
?>
<form method="POST" action="newslettertest4.php">
                        Name: <input type="text" name="name" size="20">

            Email:  <input type="text" name="useremail" size="20">

           

                       <button name="B1">Subscribe</button></p>
          </form>

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.