TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-16-2008, 04:33 AM   #1 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Help 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!
codefreek is offline  
Reply With Quote
Old 11-16-2008, 02:24 PM   #2 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

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

that did not work :/

Last edited by codefreek : 11-16-2008 at 03:57 PM.
codefreek is offline  
Reply With Quote
Old 11-16-2008, 05:18 PM   #3 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

no one ?....
codefreek is offline  
Reply With Quote
Old 11-16-2008, 07:38 PM   #4 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

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

Last edited by codefreek : 11-16-2008 at 10:06 PM.
codefreek is offline  
Reply With Quote
Old 11-17-2008, 12:40 AM   #5 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

:::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 is offline  
Reply With Quote
Old 11-17-2008, 12:45 AM   #6 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

...<solved>...
codefreek is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:31 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design