Weird problem
Posted: Sat May 10, 2003 9:10 am
I use this code to insert new users, but when I click submit they are not added to the database. Can anyone please tell me whats wrong with this code ? I use almost the similar code to inserts cd's and that works..
Thanks in advance
ampersand
Code: Select all
<?php require_once('Connections/cds.php'); ?>
<?php
$db_connection = mysql_connect($hostname_cds , $username_cds , $password_cds) or die ("Could not connect to database");
mysql_select_db ($database_cds , $db_connection) or die ("Could not find database")
?>
<form action="<?php echo $PHP_SELF?>" method="post" name="form1" target="_self">
<table border="0" cellpadding="2" cellspacing="0">
<tr>
<td>Insert user:</td>
<td><input class="x" name="insert_user" type="text" id="user_name" size="32"></td>
</tr>
<tr>
<td>Delete user:</td>
<td><select class="x" name="delete_user">
<option>Choose</option>
<?php
$category_query = "SELECT * FROM user ORDER BY user_id DESC";
$query_result = mysql_query ($category_query, $db_connection);
while ($row = mysql_fetch_object ($query_result))
{
print "<option value="" . $row->user_id . "">" . $row->user_name . "</option>";
}
?>
</select></td>
</tr>
<tr>
<td align="center"> </td>
<td><input name="Submit" type="submit" value="Submit"></td>
</tr>
</table>
</form>
<?php
if ($insert_user <> " ")
{
$result = mysql_query("INSERT INTO user(user_name) VALUES '$insert_user'", $db_connection);
}
if ($insert_user == "")
{
$result = mysql_query("DELETE FROM user WHERE user_id LIKE '$delete_user'", $db_connection);
}
?>ampersand