SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    database primary key not working

    ok i'm adding records fine without the primary key
    but It should have a primary key
    but when I try adding one it adds it fine but won't imput the data

    basically records get added only if i dont put in the primary key

    i'm using php 5
    database = email
    table = email
    primary key email_id
    fields name, email





    <?php
    if (strlen($_POST["name"]) > 0 && strlen($_POST["name"]) <= 70 && (strlen($_POST["email"]) > 0 && strlen($_POST["email"]) <= 70))
    {
    $name=$_POST['name'];
    $email=$_POST['email'];
    require_once ('mysql_connect.php');
    mysql_query("INSERT INTO `email` VALUES ('$name', '$email')");
    mysql_close();
    }
    ?>
    <font face="Arial" color="#FFFFFF" size="+1">
    <form action="index.php" method="post">
    &nbsp &nbsp &nbsp &nbsp Please Enter Your Details <br>
    &nbsp &nbsp Name: &nbsp <input type="text" name= "name"><br>
    &nbsp &nbsp Email: &nbsp <input type="text" name = "email"><br>
    &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
    <input type="submit" value="Click To Join"> <br></form></font>
    <font face="Arial" color="#000000" size="+1">
    </form>
    </left>
    </body>
    </html>

  2. #2
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    506
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $query =  "INSERT INTO table_name (name, email) VALUES ('$name', '$email')";
    $run_query mysql_query($query);
    if(!
    $run_query)
    {
     echo 
    mysql_error();



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •