Re: I'm confused



"J.O. Aho" <user@xxxxxxxxxxx> wrote in message
news:4kje2gFcgc0qU1@xxxxxxxxxxxxxxxxx
You aren't giving any info on how your table looks like, so it's a bit
more guessing here.



Ok, the table is like so:

id auto_increment, not null, primary_key
uid int(5)
name varchar(255) not null

INDEXES:
keyname | type | field
PRIMARY | PRIMARY | id
name | UNIQUE | name


SAMPLE DATA IN TABLE:
1, 32, bill
2, 33, fred
3, 34, mark
4, 35, ralph
5, 36, jerry

#THE ACTUAL CODE:

$_GET['name'] = 'joe'; //From form

$sql = "SELECT MAX(uid) FROM mytable";
$query = mysql_query($sql);
$nextUID = mysql_result($query,0) + 1;

$nextUID = 37; //From query above

$sql = "INSERT INTO mytable (uid,name) VALUES ('" . $nextUID . "','" .
$_GET['name'] . "')";
$query = mysql_query($sql);
if(!$query){
$message = "<div align=\"center\"><strong>COULD NOT ADD " .
ucfirst($_GET['name']) . "!";
$message .= "The error was: " . mysql_error() ." The SQL was: " . $sql
.. "<br><br>";
$message .= "Affected Rows: " . mysql_affected_rows() .
"</strong></div><br><br>";
}else{
$message = "<div align=\"center\"><strong>" . ucfirst($_GET['name']) .
" Has Been Added!</strong></div><br><br>";
}


#OUTPUT FROM ABOVE:

COULD NOT ADD Joe! The error was: Duplicate entry 'joe' for key 2
The SQL was: INSERT INTO mytable (uid,name) VALUES (41,'joe')

Affected Rows: -1





Are all columns unique? then you limit quite much what you can enter into
your table, only the uid should be unique and a primary key.

No, only the name column is unique, except for the id col, which is primary
key and unique by default I believe


//Aho


.



Relevant Pages

  • RE: "The operation was cancelled at the users request" error during mass insertions
    ... | I am doing the insertions in a for loop, ... | setNextUid(nextUID); //update nextUid in the table Uid ... The error message suggests that the query being executed is simply taking ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: Bizarre subquery syntax problem
    ... With Access, the official syntax for a subquery always requires an alias, so ... SELECT p.AS UID, p.Firstname AS Firstname, p.Lastname AS Lastname, ... I am seeing bizarre problems with a subquery. ... core query runs fine- ...
    (microsoft.public.access.queries)
  • Re: RFC: Network privilege separation.
    ... RLIMIT_NETWORK in the following patch series. ... owner match and a suitable uid. ... random other parts of Joe User's software stack. ... -- something (with privilege) needs to install the firewall rules and needs ...
    (Linux-Kernel)
  • Re: Narrowing a QR Results Set
    ... a good practice is to query the Worklist SCP for the Scheduled Station ... Another implementation, query all for the specific modality type, is ... Parsing UIDs is the straight road to hell, ...
    (comp.protocols.dicom)
  • Re: Performance: Query optimizer producing sub-optimal result?
    ... Have you tried adding the query hint OPTION to your query ... Mark Ayliffe wrote: ... > SELECT UID, fnCheck ... > once per record in MyTable, not once per DISTINCT MainPart as I'd expected. ...
    (microsoft.public.sqlserver.programming)