i have a form which asks the user to enter a username ,
once the user enters the username,
the program will check if the username entered by the user is a new username
or an old one from the database 'testdb' and table 'test'.
if it is a new username , it will add the new record to the database,
for some reason even the program will notify me that a new record has been added,
but when i check my table 'test' within phpmyadmin i cannot see the new record.
// testing3 does not work....
// the idea was to have the user enter
a UserName and check if the UserName is allready
contained within the UserNames in table test from
dataset testdb.
<?php
if ($_POST){
$adding = mysql_escape_string($_POST['UserName']);
echo "Adding ".$adding ." to products...<br />";
$mysql_connection = mysql_connect("localhost", "root", "fireman9");
if (!$mysql_connection) die("<font color='red'><b>MySQL connection error, process halted!</b></font>");
if (!mysql_select_db("testdb", $mysql_connection)) die ("Unable to select database, process halted!");
$get_categories = mysql_query("SELECT * FROM test ");
$name = array();
while ($row = mysql_fetch_assoc($get_categories)){
$name[] = $row['UserName'];
echo $row['UserName'];
}
// check if the entered username is equal to the UserName at the current row in datatable
// if they are not equal
// insert values $adding and create new table producs.adding
// if username $adding is not within the array $name..
// add the new record and create the table
if (!in_array($adding, $name))
{
echo "Category does not exist...<br /> ;
Adding...<br />";
$add_categories = mysql_query("INSERT INTO test VALUES ('','', '$adding')");
echo "Successfully inserted into database...<br />" ;
$create_table = mysql_query(" CREATE TABLE `products`.`$adding` (
`item_#` VARCHAR( 9 ) NOT NULL ,
`name` VARCHAR( 1000 ) NOT NULL ,
`price` VARCHAR( 9 ) NOT NULL ,
`description` VARCHAR( 9999999 ) NOT NULL ,
`short_description` VARCHAR( 50000 ) NOT NULL ,
`image` VARCHAR( 9999999 ) NOT NULL
) ENGINE = MYISAM ;");
echo "Successfully created table...<br />";
} else {
echo " <font color='red'>Category exists, process halted...</font><br />
<a href='index.php?page=login'>Click here to return to the form.</a>";
};
}
?>
<form name='test' method='POST' action='' accept-charset='UTF-8'>
<table cellspacing='0' cellpadding='10' border='0' bordercolor='#000000'>
<tr>
<td>
<table cellspacing='2' cellpadding='2' border='0'>
<tr>
<td align='right' class='normal_field'>Name</td>
<td class='element_label'>
<ol><li><input type='text' name='UserName' size='20'></li></ol>
</td>
</tr>
<tr>
<td align='right' class='normal_field'>Email</td>
<td class='element_label'>
<input type='text' name='Email' size='20'>
</td>
</tr>
<tr>
<td align='right' class='normal_field'>Address</td>
<td class='element_label'>
<input type='text' name='Address' size='20'>
</td>
</tr>
<tr>
<td align='right' class='normal_field'>City</td>
<td class='element_label'>
<input type='text' name='City' size='20'>
</td>
</tr>
<tr>
<td colspan='2' align='left' valign='bottom' class='normal_field'>Comments</td>
</tr>
<tr>
<td>
</td>
<td class='element_label'>
<textarea name='Comments' cols='50' rows='8'></textarea>
</td>
</tr>
<tr>
<td colspan='2' align='center'>
<input type='submit' name='Submit' value='Submit'>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
my datatable
testing with username 234
as u can see 234 is not within the database table 'test'