Need to start a new row in every new column (reset id for new column)

This will start a new column “$token_db” with values “$token” in table “token” but the id still incriments every time so there are hundreds of NULL rows in each. Need to “reset” or restart id for each new row so there isn’t hundreds of null rows in each column. Can you assist me I can’t find anything in the manual for this although I’m sure its there.

mysql_query(“ALTER TABLE token ADD “.$token_db.” CHAR(20)”);
mysql_query(“INSERT INTO token (”.$token_db.“) VALUES (‘$token’)”);
mysql_close();

From what you have said it isn’t even possible to work out what you are trying to do as it makes no sense at all. Why are you adding a new column to the existing table and then inserting new rows that just have a value in that column? Surely when you insert new rows you’d put values in all the columns. Also what about inserting values into the rows that were already in the table before you added the new column?

Adding a new column to a table should be a rare occurrence as if the table is designed properly in the first place it shouldn’t need new rows added except when you want to add an entire new layer of functionality and then once the functionality and the new column is added it should then remain unchanged until the next time you add further functionality to your script that requires extra columns.

The best I can figure out from what you have said is that you are trying to add a new column to an existing table for somethiong that should be handled by having a second table.

Can you post code that shows how your table is defined and explain what the relationship is supposed to be between what you have there and the new token column you are trying to add.

This bit of code works good for that issue, but now I have a NULL row in table “token” column “db” for every new column added. It should be easy to delete any row in column “db” that is NULL.

to create table “token” (runonce):

$con=mysql_connect($host,$user,$password);
mysql_select_db($database, $con) or die( “Unable to select database”);
mysql_query(“CREATE TABLE token (id MEDIUMINT NOT NULL AUTO_INCREMENT,UNIQUE KEY(id),db VARCHAR(124)) ENGINE=MyISAM”);
mysql_query(“INSERT INTO token (db) VALUES (‘1,2,3,4,5,6,7,8,9,0,q,w,e,r,t,y,u,i,o,p,a,s,d,f,g,h,j,k,l,z,x,c,v,b,n,m,Q,W,E,R,T,Y,U,I,O,P,A,S,D,F,G,H,J,K,L,Z,X,C,V,B,N,M,’)”);
mysql_close();

script to add columns and data to table “token”:

mysql_query(“ALTER TABLE token ADD “.$token_db.” VARCHAR(20) ENGINE=MyISAM DEFAULT CHARSET=utf8
AUTO_INCREMENT=0”);
mysql_query(“INSERT INTO token (”.$token_db.“) VALUES (‘$token’)”);
mysql_close();

if anything looks in error please tell me, I have only been at this a few days… Still learning.

Here is the code I have used and the results in phpmyadmin. This part of the site design has a token (cipher) sent to the preseeding page and a token generated on the present page with the use of a key (decription) if all is correct the page is shown otherwise only a forbidden 403 error page is viewed. Any attemp to get around this protective opperation, backing up or refreshing or going directly to the page, with result in a forbidden 403 error. It seems to work well so far. The test page for these first 3 pages using this cipher are located at: http://bizbook.softnetwd.com/test.php you may try it if you like to see that it does work.

  • creat table “token” setup (runonce):

$con=mysql_connect($host,$user,$password);
mysql_select_db($database, $con) or die( “Unable to select database”);
mysql_query(“CREATE TABLE token (id MEDIUMINT NOT NULL AUTO_INCREMENT,UNIQUE KEY(id),db VARCHAR(12) NOT NULL) ENGINE=MyISAM”);
mysql_query(“INSERT INTO token (db) VALUES (‘EMPTY COLUMN’)”);
mysql_close();

  • fetch table data:

$con=mysql_connect($host,$user,$password);
mysql_select_db($database, $con) or die($error);
$result=mysql_query(“SELECT id,”.$token_db." FROM token");
if ($result == “”) {

<—some php code—>

}
while($row = mysql_fetch_array($result, MYSQL_BOTH)) {
$token_forward=$row[$token_db];
}
mysql_free_result($result);
mysql_close();

  • insert table data:

$con=mysql_connect($host,$user,$password);
mysql_select_db($database, $con) or die($error);
mysql_query(“ALTER TABLE token DROP “.$token_db.”,AUTO_INCREMENT=0”);

<—some php code—>

mysql_query(“ALTER TABLE token ADD “.$token_db.” CHAR(20) NOT NULL,AUTO_INCREMENT=0,ENGINE=MyISAM”);
mysql_query(“INSERT INTO token (”.$token_db.“) VALUES (‘$token’)”);
mysql_close();

It bothers me that id keep icrementing to infinity, I see an error occurring eventualy from that, does any have a suggestion to solve that issue?

Here is the screenshot of phpmyadmin for this tableset ( column “iUHeP” is the last insert to table “token” and will be droped after leaving that page):

it bothers me that you keep altering your table

i’ve read over this thread a couple of times and i swear i still have no idea what you’re doing, but nevertheless i think you’re doing it wrong

adding and dropping columns on the fly is a very inefficient way of using a database

I have done away with adding new columns. I am using rows it does work much better.

:slight_smile: