I've written a script, which inserts data in a new column every time something new is submitted. the problem is that it also creates a new row, so the second time data is submitted, the data is inserted in second column and row Nr. 2, the third time it's column Nr. 3 and row Nr.3, but it should be always only one row, and everytime a new column, i.e., only one row in every table, but many columns. For the whole script see below, but actually it is the following line which seems not to work properly, because it is responsible for creating new columns, while creating new columns and new rows instead:
$sql = "ALTER TABLE javascripts ADD COLUMN $scriptname TEXT";
Also the problem with the script below is that I cannot use numbers for column names, only letters, otherwise no new column is created in the database. Also several words don't work, only one word as a name for a column. Is this due how mysql works, or can this be corrected
The whole script is:
<?php
global $gesendet;
global $scriptname;
global $jscripts;
if ($gesendet)
{
$db = mysql_connect("localhost", "root", "");
$condatabase = mysql_select_db("javascript", $db);
if (!$condatabase) {
@mysql_create_db ("javascript", $db); //creating database
mysql_select_db("javascript", $db);
$sql_query = "CREATE TABLE " . "javascripts" . " ($scriptname TEXT)";
@($sql_query);
}
else
{
mysql_select_db("javascript", $db);
$sql = "ALTER TABLE javascripts ADD COLUMN $scriptname TEXT";
mysql_query($sql, $db);
}
$sqlab1 = "insert javascripts"; $sqlab1 .= "($scriptname) values ";
$sqlab1 .= "('$jscripts')";
mysql_select_db("javascript");
mysql_query($sqlab1, $db);
mysql_close($db);
}
?>
<form action = "<?php $PHP_SELF ?>" method = "post">
<br>Please insert the script name:</br>
<br><input type="text" size="40" name="scriptname"></br>
<br>Please insert the Javascript:</br>
<TEXTAREA name=jscripts ROWS=10 COLS=70></TEXTAREA>
<BR> <input type = "submit" name = "gesendet" Value="Insert a new JavaScript"></BR>