...

View Full Version : Problem with INSERT



mouse
09-21-2002, 12:21 AM
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. :confused:

Spookster
09-21-2002, 12:44 AM
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')";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum