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
https://forums.phpfreaks.com/topic/37658-entering-data-into-sql-database/
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>

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.