Database update problem
| From: | Martin Skjöldebrand | Date: | Sun, 15 Apr 2001 17:16:47 +0000 |
| Subject: | Database update problem | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-8575@lists.php.net to get a copy of this message | ||
This form is calling it's own page. I want to add a record to the sec_types
table. What happens is that it increments the type ID (passing '' to
auto_increment) but doesn't add the variable $txtSec_type. It prints the
text after the INSERT INTO statement.
Changing the variable to a direct value (like VALUES('', 'testing') insert
the word 'testing'. Why isn't it passing the variable value??
Cheers,
Martin S.
<form action="admin.php?whattodo=admin/sec_types&action=add"
method="POST">
<table>
<tr>
<td><select name="lstSec_type">
<option>New security type</option>
<?
$sec_query = "select sec_types from sec_types";
$secquery_res = mysql_query($sec_query, $mysql_link);
while ($row = mysql_fetch_row($secquery_res)) {
print "<option>$row[0]</option>";
}
?>
</select> </td>
<td><input type="text" name="txtSec_type" size="5">
</td>
<td><?print "<a
href=\"".$g_base_url."admin.php?whattodo=admin/sec_types&action=add\">";?>Add</a></td>
<td><?print "<a
href=\"".$g_base_url."admin.php?whattodo=admin/sec_types&action=edit\">";?>Edit</a></td>
<td><?print "<a
href=\"".$g_base_url."admin.php?whattodo=admin/sec_types&action=delete\">";?>Delete</a></td>
</tr>
</table>
</form>
<? switch ($action) {
case "add":
$addquery ="INSERT INTO sec_types (id, sec_types) VALUES";
$addquery .="('', '$txtSec_type')";
$result = mysql_query($addquery, $mysql_link) or die("query failed, " .
mysql_error());
print "<h3>Done.</h3>";
print "<p>The security type $txtSec_type was added to database.</p>";
break;
etc etc
etc etc