View Full Version : Problem with INSERT

09-20-2002, 11:21 PM
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. :confused:

09-20-2002, 11:44 PM
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')";