TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Can you use IGNORE in the update of a mysql row ? (http://www.talkphp.com/general/3613-can-you-use-ignore-update-mysql-row.html)

codefreek 11-16-2008 04:33 AM

Can you use IGNORE in the update of a mysql row ?
 
so yeah i am working on my news system so i am doing in the edit part that if someone lets say posted "R" as title then ok posted done, but if it has the
R already in recored then IGNORE, it , this works create in when posting something but have not tested in delete or update before :S


The code "Not working,.. Something i am not doing right ?, please let me know :P as i said never tried on update or delete..";

PHP Code:

function editnews($sname$uname$story) {
    
$sql sprintf(" UPDATE IGNORE
            `news`
        SET
            `sname` = '%s',
            `uname` = '%s',
            `story` = '%s',
            `pdate` = NOW()"
,
            
            
        
mysql_real_escape_string($sname),
        
mysql_real_escape_string($uname),
        
mysql_real_escape_string($story));
        
$res mysql_query($sql) or die(mysql_error());
        
              if(!
mysql_affected_rows())
            {
                echo 
'The Name: '.$sname.' is already taken!';
                exit;
        }
        
       if (
$res) {

echo 
"News Post Has Been Updated!";
} else {
echo 
"News post could not be updated.";
        
    }
    
    return 
$res;



Thank you!
:-P

codefreek 11-16-2008 02:24 PM

http://dev.mysql.com/doc/refman/5.0/en/replace.html

that did not work :/

codefreek 11-16-2008 05:18 PM

no one ?....

codefreek 11-16-2008 07:38 PM

Duplicate entry 'value' for key 2
now i get that error ? any ideas ?

codefreek 11-17-2008 12:40 AM

:::UPDATE:::
this is how it looks like now it echos out update complete but it's not working..
PHP Code:

function getrow($sname) {
 
$sql sprintf(" SELECT * FROM `news` WHERE `sname` = '%s'",
                
mysql_real_escape_string($sname));
                
$res mysql_query($sql) or die(mysql_error());
                if (
$res) {
 
                if(
mysql_affected_rows())
            {
               return 
true;
            }
else {
 
               return 
null;
 
}
}
}




function 
editnews($sname$uname$story) {


    
$sql sprintf(" UPDATE 
            `news`
        

        SET
            
            
            `uname` = '%s',
            `story` = '%s',
            `pdate` = NOW()
            
        WHERE `sname` = '%s'"
,
        

        
        
        
mysql_real_escape_string($uname),
        
mysql_real_escape_string($story),
        
mysql_real_escape_string($sname));
        
$res mysql_query($sql) or die(mysql_error());
        if (
$res) {

echo 
"Update complete";
} else {
echo 
"Did not update";
}
    
    return 
$res;



and in the editnews.php..
if(getRow($sname) == TRUE) {
echo $sname . ' already exists';
}else{
$eddn = editnews($sname, $uname, $story);
}

codefreek 11-17-2008 12:45 AM

...<solved>...


All times are GMT. The time now is 02:49 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0