Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    North East England
    Posts
    853
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Problem with INSERT

    I have a form:
    <html>
    <head>


    <link href="style.css" rel="stylesheet" type="text/css">


    </head>

    <body>

    <form method="post" name="form" action="addremove.php">

    <p>Name: <input name="name"></p>
    <p>Email address: <input name="email"></p>

    <p><input type="radio" name="radio" value="add" checked> Add to list <input type="radio" name="radio" value="remove"> Remove from list</p>

    <br/>
    <p><input type="submit" name="submit" value="submit"> <input type="reset" name="reset"></p>

    </form>

    </body>
    </html>
    And a php script to process it:
    <?

    include("connection.php");

    if($radio == "add"){

    mysql_query("INSERT INTO $table SET name=$name, email=$email)");

    }

    if($radio == "remove"){

    mysql_query("DELETE FROM $table WHERE name=$name AND email=$email");

    }

    ?>

    <a href="index.html">To index</a>
    The table has been created with the following query:
    $query=mysql_query("CREATE TABLE newsletter (ID INT (5) not null AUTO_INCREMENT, name VARCHAR (20) not null , email VARCHAR (30) not null , PRIMARY KEY (ID))");
    Can anyone see why this isn't working from the above? It doesn't seem to be a connection problem, the table has been created okay but adding names to the database doesn't work.

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    The problem you have here is you are using commands to do an update but trying to do it with an INSERT statement:

    UPDATE $table SET name=$name, email=$email

    Would be correct. What you want to do is insert values:

    $query = "INSERT INTO '$table' (name, email) VALUES('$name', '$email')";
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Posting Permissions

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