0

I have create a table in wordpress existing database in which i have insert a url. Now i have used update query for updation of the url.

Insertion and updation query are like this..

if(isset($_POST))
{
    $x=$_POST['url'];   
    global $wpdb;
    $wpdb->insert('wp_xml_url', array(
        'url' => $x,
        'update_date' => current_time('mysql', 1),
));
}

and

$x=$_POST['url'];
global $wpdb;
$wpdb->update( 
'xml_url', 
array( 
    'url' => $x,    
    'update_date' =>  current_time('mysql',1)    
), 
array( 'url' => $x ), 
array( 
    '%s',   
    '%s'    
), 
array( '%s' ) 
); 

now i want that, when we insert same url in database it will update the url with same url and different date and time.for this i have used the check condition like this..

    $name=xmlfeeds_select();
    $url=$_POST['url'];
    $url1=parse_url($name);
    $url2=parse_url($url);
    if($name == $url)
    {
        xmlfeeds_update();

    }
        xmlfeeds_insert();

But this condition is not working for me.Is there any other condition for checking the url value? coz at any condition it's inserting the url in database not updating it even it same or different.

Any help will be appreciated.

Thanks in advance...

0

Try using $wpdb->replace(); method. It updates a row if it exists and inserts a new one if it doesn't. See the documentation. Is that what you are looking for?

  • ..It's also not working for me.Actually in my code neither update query nor replace query being executed.can you please tell me what's my problem and what m leaving for executing query. – user6891871 Nov 3 '16 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.