Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Auto Increment + Deleting A User


On my User table, occasionally, I will have to delete a member. ID is set to auto_increment, so, each time information is imported, that number will increase by one...

However. There is one issue. When I delete a row from the table (so, I deleted a user), that ID becomes unavailable for use. So, there is three members. I delete the third one. When another user registers, I want them to have the ID that was deleted beforehand, which would be three. However, the user will have four.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Auto-Increment And Deleting
When i delete a record from my MySQL database it works fine, but then when i reload the form to Insert another record, it sticks the record into the database but at the position where i deleted the record. Can someone show me a way of keeping the autoincrement at the last record in the database even after i delete a record?

Auto Increment By More Than 1
I have a table that I want to automatically generate an account number. I previously developed a simple database using appleworks that allows one to enter the amount she needs to add to the ID field with each new record. MySQL does not allow for this so I figure I must add it to the PHP script. PHP Code:

What Will The Next Auto Increment Be?
I have a MYSQL table with a field that auto increments 'ID'. I need to know what the next ID will be. Is there a simple way to do this?

One solution I've thought of is to query all the records and sort it by ID, and then just take the last record +1. But that seems awfully inefficient. Does anybody have any other suggestions or know of any functions that will do this?

Auto Increment
how when you have an auto-incremented mysql list? And you know how when you delete an entry, the entry's auto-increment value just gets dropped and skipped? What I need to know is if there is a way to sort of re-number the list, preferably using a Query, such as an ALTER command or something. Code:

Getting Last Id Of The Auto-increment Key
I have two tables and I need to get the last id of the primary key in one of the tables. I did some searching and found a solution that works.

$sql=mysql_query("INSERT INTO (table) (column) VALUES ('test')") or die (mysql_error());
$insert_id=mysql_insert_id();
$num = $insert_id + 1;   //need to increase the last id by one to match new entry in other table

This works well. The downside is in order for this to work an actual value is filed into a new row of (table) after the last id found in (column) thus giving me a blank row. While this isn't too bad, I could imagine I'll end up with a bunch of empty rows in my table. Is there a way to prevent this from happening -- i.e., a bunch of empty rows?

Getting An Auto-increment Id?
When someone creates a topic, the following is executed:

$sql = mysql_query("INSERT INTO `reflexproj`.`topics` (`topic_name`, `topic_desc`, `poster`, `forumid`) VALUES ('". $posttitle ."', '". $desc ."', '". $sessionu ."', '". $forum ."');");

This inserts the topic into the topic table. However, then this is executed:

$sql = mysql_query("INSERT INTO `reflexproj`.`posts` (`poster`, `post`, `topicid`) VALUES ('". $sessionu ."', '". $fp ."' '". $id ."');");

This is meant to insert a post into the posts table that starts the topic. However, this is a problem. The problem is, that $id hasn't been defined.

My question is this, really: How do I get $id? Basically, I've got to find a way of getting an auto_increment value from a database. Anyone any ideas?

Get Last Auto-increment Number
I am inserting related data into 2 tables. The first table I insert into has an auto-incremented field. The second table i insert into has a field which needs to hold the same number as the number in the auto-increment field from the first table. I cannot auto-increment the field in the second table because the number will occur more than once in the second table.

How can I retrieve this auto-incremented number from the first table?

Auto-increment Field
I have query which returns the value of a auto-increment field last entered. That is:

$sqlquery = "SELECT MAX(field-id) from table";
$result = mysql_query($sqlquery);

The query itself seams to work fine alone, but when I run it in a php script and try to print $result it returns "Resource id #6" . No idea what this is or where it came from.

MySQL Auto Increment
I have a site that is about to go into production
and it has a couple of tables that it uses that
could get quite large once in full swing, most of
them have a column called "id" and it auto
increments every time a new row is added. When
setting this up, what do you recommend using at
the column type and size. atm I have gone for a
big-int with the size of 20. I wonder over time
will 20 be enough... Should I just think of a big
number and use it?

Anyone else in this situation and what would you do?

PHP / MySQL - Auto Increment Id
I just did my first PHP/MySQL database (a simple survey) that works
fine. It is ordered by an id field that auto increments. Apparently, one
entry repeated (I'm thinking the user hit the submit button twice). So,
I deleted a record. My question is, how do I make it so the next entry
will use the id# that I deleted, so there won't be a gap in the id numbers?

Resetting Auto Increment
I have a table in MYSQL which has a row which is set to auto increment. Because I've been testing my system out so much the id is at around 100 or something.

I tried deleting everything from the table but then when I make a new news story the id carries on from where it left off, how can I make it start again from 1?

MySQL Auto-increment
When using an "INSERT INTO" statement, what should I put as the value for an auto incrementing cell?

ex: "INSERT INTO content VALUES (' [auto-incrementing field] ', '$content')";

Would I just leave it empty?

Auto Increment Updating...
I have a database with a table 'pages' in it. Inside pages is the row 'ID_MAIN'. It's got 5 entries in it with values of 1 to 5. I want to create a new entry in between entry 2 and 3 with a value of 3, there by updating 3 to 4 and so on.

This is the script I came up with, however I'm completely new with this and... well it didn't work. And info as to how to correct this would be greatly welcomed. Code:

Keep A Accurate Auto Increment In MYSQL
i'm wondering how to keep a accurate auto increment in MYSQL. For example say I had an ID field "INT" thats auto increment and I have 5 rows:

|ID 1| Row 1
|ID 2| Row 2
|ID 3| Row 3
|ID 4| Row 4
|ID 5| Row 5

Now say I delete "Row 4":

|ID 1| Row 1
|ID 2| Row 2
|ID 3| Row 3
|ID 5| Row 4

So my question is how do I keep the ID# with the corresponding row#? Is it possible to do this, and how so? If not is their another way to accomplish this?

Phpbb Auto Increment Question?
Is anyone familiar with the way phpbb works in terms of adding a new user to the database. If i am right it doesnt seem to auto increment?

When a new user registers fir my site, I also have an sql insert into the phpbb_user table too so they can then logon to the forum.

But the id seems to go in as just 0 and wont increment! Is there any reason for this?

Grabbing An Auto Increment Number??
I am entering information in to a database. Everything enters 100% fine, the first column is an auto_increment id number. What I want to do is enter information in to another table, but I need to use that id number that is generated in one of the columns. (and it has to be pretty much instant with the first one, its for a register form) Is this possible? If so, how would I do it?

PHP/mySQL Insert Into Statement With Auto Increment
When i use mysql from the linux command line it is just plain simple to add an row into a table, even with php this isn't a problem. But when the table has aan field with auto_increment php won't allow to insert a new row in the table. I'll get an invalid query back.. In don't understand how to insert a new row into a table with the auto increment. Btw this is also the primary key: Code:

Printing Mysql Auto-increment Key Value On A Form
i need to print off the auto increment key value on a form. How does the syntax go to accompish this. Field name is rrn. Output only.

Inserting Data Into A Table With Auto Increment In One Field
i have a table with several fileds in and with the first one being an auto increment field. I want to know what my SQL query should be when inserting data. Here's my current one: Code:

$SQL = mysql_query("INSERT INTO $usertable2 VALUES('$subject', '$newstext', '$date', '$usrname')";

The auto increment field is the first in the table and is called 'postid'. can someone give me the correct query please? also do i need the first entry in the table to be a blank one with just the postid entered at one?

Retrieve MySQL Row's Auto-increment In Query
I've only been working with PHP and MySQL for about the last month and half and have done fairly well but have run into a problem that I hope has an answer.

I'm working on a simple, small animation showcase site where people I know (animators) can post their animations/movies. Visitors can then "tag" their movies with descriptive words.

If I submit a form to insert the mysql row that has an auto-incrementing ID # on it into a table, is there a way to retrieve that ID immediately and use it in that same query to insert the ID # into another table (which I use to cross-reference the table that contains all of my movies's info and the table that contains the information I want to be able to relate to that user)?

SO, more plainly I want to:
 - Retrieve from a form/page the movieID and tag
 - Insert "tag" into "tags" table of my database, which automatically assigns each tag row an ID
 - Pull the tagID for the tag row that was just created from the tags table <- Where I need the help
 - Insert the tagID and movieID into a crossref table

Deleting Sessions If User Restarts
A user submits a form and thus a session has been created. What I want to do is if the user presses the back button or decides to re-submit another form, it'll overwrite the current one. How can I do this ?

Deleting User Account With PhpMyAdmin And PhpBB
I've got phpBB v2.0.4 (message board) running and I'd like to delete an account. The problem is...I've never used phpMyAdmin before and I'm a bit stuck.

Batch File Deleting And Folder Deleting
I have a folder in my web site where I used php to create and copy in files. but now I can't delete them easily. The only way I know how that is possible is through php. I get an error the following ftp error:

550 th: Permission denied
I had the chmod() set to 0777 on every file and folder. But I still seem to loss control over the files when I try and do things with them through other means.

I think it is because the user I use to access the files via ftp a diffrent user. So I tryed to add a function with chown() for the new files I was posting and uploading. It didn't work on those new files. so it looks like the only thing I can do is use the unlink() function which deletes the files fine.

The only problem is now I have something like 100 sub directories all with files in them. I need to figure out a way to batch delete them. I can't find a script that goes through and finds all file contents including all sub directories and unlink those things.

I found some that will use a for loop to list out the contents of a folder but it is just files. No sub directories. Any body got any ideas on which functions I should use or know where a script is that I can base mine off of.

I am not sure how to approach this since what I tryed with chown and chmod has failed thus far. I currently have no code and am starting from scratch on this batch flushing of my directory.

How Can I Increment Letters
I need to make a loop in php that will increase a letter each pass.for example

"a" increases to "b" during the first pass
"b" to "c" during the second... etc.

UPDATE And Increment By 10
i want to update each field in a database table and increment by 10.

so it will look like

10, 20, 30, 40, 50

Increment (++) Question
I'm using the following code

<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
error_reporting(0);
$incrementfilename = $_GET['textfilename'];
$handle = fopen($incrementfilename, 'w');
$incrementcontents = file_get_contents($incrementfilename);
$incrementcontents = $incrementcontents + 1;
fwrite($handle,$incrementcontents);
fclose($handle);
chmod($incrementfilename,0777);
?>

Increment Number
How do I create a link, that when clicked, increments a number value stored in a database?

Increment Numbers
i use a java scrip to expand content from a rss feed. It doesn't work because when all feed are showing, all javascrit have the same ID and each ID shoud be unique,
can i create with php or javascritp a new ID for each java script created in this php loop with my result? Like increment by one for each result?

I can add php into result because it's not inside javascript. like:

maintab1
maintab2
maintab3

But each element are not in the same php bloc code.

Date Increment
I have a value stored in variable $date and want to increment this date by one day, something like:

$date = $date + 1;

I cannot find a date increment function in the PHP help file.  I thought that this would be quite a commonly used function but maybe I am looking in the wrong place.

How To Increment Variables In Smarty
how to increment variables in smarty    

{assign var="i" value=$i|default:0}   {if $i lt 3} {$i|assign:$i+1} {/if}   if $i is lessthan 3, i want to increment $i . it is possible or not ...

Increment Counter Via GET-Request?
this is my situation:

I have a counter on my MAIN page. It is incremented by requesting a certain
"picture" which is the output of a script. I can do this manually with:

http://www.mydomain.com/script.php?id=123456&vid=987654

This increments the counter.

This is my wish:

I have another page with a discussion board. The address is something like
http://board.mydomain.com. Now I want to add these hits to those of the
counter.

My idea is to write a script which does something like:

<?php
send GET-request to increment the counter (invisible for the user);
redirect to the board;
?>

Is this possible? How do I do this?

Strange Date Increment Problem
The code below loops from a starting date, incrementing the date and
displaying date and day-of-week. Everything is fine until 2007-11-04 is
reached.

Increment A Text Field In A Form
I am creating an intranet which shows active projects and allows people to add new projects. If users want to add a new project, they fill in a form but what I want the form to display in the ProjectNumber field (which is a var char field & not the primarykey) is the last Job Number incremented by 1.

For example if the last ProjectNumber was TS0014, then the default value in the ProjectNumber field should be TS0015 - this way users know what the next job number is.
At present, the last job number in my table is TS0014. Below is the code i'm using but for some reason in the Job Number field in the form Im getting TS001? WHY? Code:

Session Variable Increment Problem
session_start();
$_SESSION['visits']++;
print 'You have visited here '.$_SESSION['visits'].' times.'

why the visit variable is not incremented the next time i enter.

Notice: Undefined index: visits in C:Program FilesApache
GroupApache2htdocssessioncookie2.php on line 3
You have visited here 1 times.

Session Counter Won't Increment But Registered Fine?
I eagerly started the devshed tutorial on sessions and discovered I cannot get the simple counter script to work. I have read a bunch of other posts and I am still not exactly sure why things aren't working. I have the session directory set in php.ini, I have cookies enabled in my browser.

Here are two files which I have changed around in various ways, paying attention to putting the session_register in different spots.

Increment A Counter In MySQL Every Time A Picture Is Viewed.
I have a picture heavy website that works from a MySQL database, pages are created on the fly as a thumbnail picture is clicked on.

Is there any way to increment a MySQL counter every time the thumbnail picture is clicked on, therefore giving an individual hit count for each large picture and it's automatically created page? If there is a way of doing this can someone please point me in the right direction with regards to coding this?

PHPmyadmin Access Denied For User 'user'@'localhost'
WinMe machine as server, with Apache 2 installed and working PHP4 installed and working ( had PHP 5.05 installed and working, but i couldnt get the mysql extensions to load - phpinfo() didnt list mysql :(, so i installed PHP4, which now lists mysql when i run phpinfo). MYSQL 4.1 installed and working. I dont know the console commands too well, but i know its working ok, cos I have used a few simple DOS prompt commands to check its alive and I can connect to the database using MyODBC frontend/driver 3.51 and also using Navicat 2004.

When i try to connect to the database via PHPmyadmin from another network PC I have an error:

#1045 - Access denied for user 'user'@'localhost' (using password: YES)

I have played around alot with different settings in the config.inc.php file.... nothing seems to work.

This almost appears to be a simple login problem ( probably is too), but I can access the database locally from the Winme machine with the username and password that wont work over the network!

I have tried not using 'localhost' as the host name but the IP address of the Winme PC but I get this error:

#1130 - Host 'MYSERVERNAME' is not allowed to connect to this MySQL server

Notice: Use Of Undefined Constant User - Assumed 'user'
I have a script for a shopsystem on a Linux. There it works fine.
But when I try to run it on my Windows machine, PHP says things like

Notice: Use of undefined constant dbname - assumed 'dbname' in
c:apachehtdocsaposhop estshopclassesxxx.clas s.php on line 77

On Windows I run PHP 4.3.2
On Linux runs PHP 4.3.1

Authenticating User Common User Names
I want to create a password protected page with PHP and Mysql. I have 2 groups User and Admin. The respective groups have a common user/password. The user/password are stored in a database. I want to authenticate the user through a login form and not through a pop-up ($PHP_AUTH_USER) way.

What I want is, if a user logs in and he moves from one page to another, he should not be asked for validity again. Is this possible only with scripting (without session and $PHP_AUTH...). If yes - how do I keep track of an authorised user and unauthorised user, so that he should not be validated again. Does setting the user variable to global in all the pages do the trick.?

User Authentication And PHP Saving As Specific User.
the users of my server had to upload their pages by sftp and only the user who uploaded a page was able to edit itafterwards.

I've been asked to make a secure way for users to log on through the web and edit their pages online. However, although using .htaccess to authenticate users, the script saves as user 'nobody' and is not able to edit pages previously uploaded (and saved as user 'john_doe'). What I am trying to do is make the script save using the same username as the user used to log on.

Fill Fields When User Selects User From DB
I have a field with a selectbox which contains a list of client names and several other fields which display information from the DB.

I need to be able to make the fields change to the appropriate information when a user is selected from the select box. Can anybody please give me an example of a bit of code that will do this?

How Do Remove A User From MySQL.user?
How do you permanently remove a user from the MySQL database.

Delete from MySQL.user where user="Unwanted User";

just seems to ignored.

Deleting
how could i delete everything from a table in a mysql db except for the 10 latest things ?

Auto-Tab
I have a page that has 5 input boxes, the first box holds 5 characters, the second holds 4 and carries on varying in length. I need to find a way so that when a user enters the 5th char in the first box, then the cursor moves to the second box and so on...

Deleting All Files
Is it possible to delete all files in a folder using unlink() or something similar?

Deleting The Saved Db The One Before?
I made a script that backups the database as sql file in the server. I mean script writes it into the harddrive, but everytime when i execute the script the harddrive loss another 3 mb. How can i modify the script to delete the one before when i execute it to write the new one?

Need Help With Deleting Records
I'm trying to add a link on the display of a record to delete that record.

The main part of the record is stored in pw_event, then there are several rating fields for that record stored in pw_rate, and there is also several records for the first record stored in pw_whois.

I need to have a link that will deleted everything for that record in all three tables.

Here is my display script:

PHP Code:

Deleting Last Comma
The code below displays pet names like so:

Fido, Bowser, Kittycat, Spot,

and I want to delete only the last comma. I tried 'substr' and 'rtrim' and both of those delete the space and comma between each name, not just the last name as I'd like, so I end up with:
Fido,Bowser,Kittycat,Spot,

How would I delete only the last comma, so that it is this instead?
Fido, Bowser, Kittycat, Spot

Even with trim and substr, I end up with:

Deleting A Session
I want to be able to delete a session so that the next time there's a call to session_start, it creates a new session ID. I don't want to destroy the session variables specifically (though this will be a side-effect of what I'm doing) so I know that session_destroy isn't what I want to do.

I presume I should just delete the session cookie manually. Is there a neater way? And if not, how do I do this?


Copyright © 2005-08 www.BigResource.com, All rights reserved