Hello and welcome to our community! Is this your first visit?
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
    North East England
    Thanked 0 Times in 0 Posts

    Unhappy Problem with INSERT

    I have a form:

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



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

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


    And a php script to process it:


    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
    Marion, IA USA
    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')";
    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