Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: Record Management Question
Hi Dan,

The only way out there that I know of is to check to see if the entry
exists.  If it does, extract the entry, increment it, then update it.
Like this:

<?
$result = mysql_query("SELECT * FROM `tools` WHERE toolname = '#10
Phillips'", $conn) or die(mysql_error());
if(mysql_num_rows($result) == 0)
{
mysql_query("INSERT INTO `tools` (toolID, toolname, numtools) VALUES ('',
'#10 Phillips', 0)", $conn) or die(mysql_error());
}
else
{
$row = mysql_fetch_assoc($result);
$oldNumTools = $row['numtools'];
$newNumTools = $oldNumTools + 1;

mysql_query("UPDATE `tools` SET numtools = '$newNumTools' WHERE toolname =
'#10 Phillips'", $conn) or die(mysql_error());
}
?>

I know it's a bit of a lengthy bit of code to make such a simple thing
happen, but it's all that is available.


Hope this helps...


Trev



D & T wrote:


> Hi,

>    very new to PHP / MySql,  had a quick question.

>    I am creating a database to track tools.  I only want there to be
> one
> entry for each type of tool (ie. #10 Phillips).  If there is already a
> record for a #10 Phillips, I do not want there to be a second one.  I
> just
> want to increase the quantity associated with the first record.

>    Is there a clean / simple way to verify whether or not an entry
> already
> exists in my database?

> Thanks,

> Dan.








##-----------------------------------------------##
Article posted from PHP Freaks NewsGroups
http://www.phpfreaks.com/newsgroups
Get Addicted:  alt.php.sql
##-----------------------------------------------##

Report this thread to moderator Post Follow-up to this message
Old Post
Trevor Llewellyn
11-25-04 08:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP SQL archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:52 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.