Jump to content

ON DUPLICATE KEY UPDATE wont work?


Dusaro

Recommended Posts

I have this but it will not update, it inserts the entry still!

<?php
$member=$_POST['memberid'];
$status=$_POST['Status'];

$con = mysql_connect("host","user","pass");
if (!$con)
{
	die('Could not connect: ' . mysql_error());
}
mysql_select_db("a2186214_hbclan",$con);
$sql="UPDATE application SET Status = '$status' WHERE ID = '$member'";
$sql1="INSERT INTO table_members(name) SELECT application.Name FROM application WHERE application.ID = '$member' ON DUPLICATE KEY UPDATE table_members.name = application.Name";
if ($status == 'ACCEPTED')
{
	if(mysql_query($sql, $con) or die(mysql_error()))
	{	
		if(mysql_query($sql1, $con) or die(mysql_error()))
		{	
			echo 'Status Changed.<br /><a href="../applications.php">Return To Members List</a>';
		}
	}
	else
	{
		die('Could not submit: ' . mysql_error());
		}
}
else
{
	if(mysql_query($sql, $con) or die(mysql_error()))
	{
	echo 'Status Changed.<br /><a href="../applications.php">Return To Members List</a>';
	}
	else
	{
		die('Could not submit: ' . mysql_error());
	}
}
mysql_close($con);

?>

Link to comment
Share on other sites

I just realized that you have a select in the query, give this a try (I didn't try it, I don't even know if it is a valid query):

 

INSERT INTO table_members (name) values ((SELECT application.Name FROM application WHERE application.ID = '$member')) ON DUPLICATE KEY UPDATE table_members.name = values(table_members.name)

Link to comment
Share on other sites

In table_members I have "id","name". "id" being the unique index.

In application I have "ID","Name","Email","Clans","Xfire","Invited","Skills","Status","Date","Rules","Ip",Old","fuser".  "ID" being the unique index.

Is that what you wanted?

Link to comment
Share on other sites

well, i had a thread bout 1 or 2 weeks ago about this but people stopped answering...

 

INSERT INTO table_members(name) SELECT application.Name FROM application WHERE application.ID = '$member' ON DUPLICATE KEY UPDATE table_members.name = application.Name

 

Will not update, still makes a new entry...

 

Table Structures

In table_members I have "id","name". "id" being the unique index. and name being unique.

In application I have "ID","Name","Email","Clans","Xfire","Invited","Skills","Status","Date","Rules","Ip",Old","fuser".  "ID" being the unique index. and Name being unique.

Link to comment
Share on other sites

well, i had a thread bout 1 or 2 weeks ago about this but people stopped answering...

That's not a reason to start a new thread -- now merged.

 

INSERT INTO table_members(name) SELECT application.Name FROM application WHERE application.ID = '$member' ON DUPLICATE KEY UPDATE table_members.name = application.Name

 

Will not update, still makes a new entry...

 

Table Structures

In table_members I have "id","name". "id" being the unique index. and name being unique.

In application I have "ID","Name","Email","Clans","Xfire","Invited","Skills","Status","Date","Rules","Ip",Old","fuser".  "ID" being the unique index. and Name being unique.

If you want to share your table structures, post the CREATE TABLE syntax.

 

If you want to test your "unique" index, try to insert a hard-coded value twice -- if you don't get an error, then something else is wrong, and ON DUPLICATE KEY UPDATE won't work either.

Link to comment
Share on other sites

You Mean these?

 

CREATE TABLE  `a2186214_hbclan`.`table_members` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 15 ) NOT NULL ,
UNIQUE KEY  `id` (  `id` ) ,
UNIQUE KEY  `name` (  `name` )
) ENGINE = MYISAM DEFAULT CHARSET = latin1;

 

CREATE TABLE  `a2186214_hbclan`.`application` (
`ID` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`Name` VARCHAR( 30 ) NOT NULL ,
`Email` VARCHAR( 30 ) NOT NULL ,
`Clans` VARCHAR( 30 ) NOT NULL ,
`Xfire` VARCHAR( 30 ) NOT NULL ,
`Invited` VARCHAR( 30 ) NOT NULL ,
`Skills` VARCHAR( 255 ) NOT NULL ,
`Status` VARCHAR( 30 ) NOT NULL ,
`Date` DATE NOT NULL ,
`Rules` VARCHAR( 30 ) NOT NULL ,
`Ip` VARCHAR( 50 ) NOT NULL ,
`Old` INT( 30 ) NOT NULL DEFAULT  '0',
`fuser` VARCHAR( 50 ) NOT NULL ,
UNIQUE KEY  `ID` (  `ID` )
) ENGINE = MYISAM DEFAULT CHARSET = latin1;

Link to comment
Share on other sites

This is what I did.

I went into phpmyadmin, went into my tables, operations, copy tables. It then gave me those.

Then you created them incorrectly.

 

But that wasn't your problem -- your problem was that you think that you're getting duplicates.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.