1

Really need help you again. I even don't know what type of question I'm facing right now. (even to add tags below this question).

enter image description here

This is the scenario:
Author wants to change the name of the category (where an article was successfully written under that category name) and update it.

Previous URL:

http://www.ramaacademy.org/programming/vb6-step-by-step.php

Need to change the URL into:

http://www.ramaacademy.org/vb6-programming/vb6-step-by-step.php

I got failed to change and update it with this follows:

$prev_url=='http://www.ramaacademy.org/programming/vb6-step-by-step.php';
$old_categ=='programming';
$new_categ=='vb6-programming';
$mod_url=substr($prev_url,0,27);

if (strpos($prev_url,$mod_url.$old_categ)) {
   $newURL==$mod_url.$new_categ;
   //UPDATING.................
   $sqlQ="UPDATE ra_articlez SET linkz=:newURL WHERE categoryz=:old_categ";
   $sth= $mydb->prepare($sqlQ);
   $sth->bindParam(':newURL', $newURL, PDO::PARAM_STR);
   $sth->bindParam(':old_categ', $old_categ, PDO::PARAM_STR);   
   $sth->execute();
   //msg
   echo "done successfully!";
}

I found no errors reported and still can not change the previous URL into new URL.
thanks for your help and suggestion!

Joe Kdw
  • 2,245
  • 1
  • 21
  • 38
  • What was the output? Please set - `$mydb->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );` and then after `execute` please do an - `if( $sth->execute()) { echo "done successfully!"; } else { echo $sth->errorInfo(); }` – Abijeet Patro Mar 15 '15 at 17:48
  • I've just done you suggested and I found no errors. It goes to last echo (success) but no changes with the link – Joe Kdw Mar 15 '15 at 17:51
  • What happens when you run the query directly on the MySQL server via phpMyAdmin or something? Can you do that for a single record? If the query executes successfully, then the issue might be with the `WHERE` clause. – Abijeet Patro Mar 15 '15 at 17:56
  • It's online try. I uploaded via filezilla when finished writing codes and try it. No errors or server issue in this case. All I need is just to change the URL from previous to new one as explained in my question by using PHP. – Joe Kdw Mar 15 '15 at 17:58
  • wait, I've just found something. Can it be done by regex? or any other best suggestion? – Joe Kdw Mar 15 '15 at 18:00
  • we'll have to know your DB structure, specifically this table - ra_articlez – Abijeet Patro Mar 15 '15 at 18:26

1 Answers1

1

I'm not sure that your question match to my try.
So far, I see no errors found in my localhost besides you just need to change old url to a new one.
but i'm trying to help you with this follows.

<?php
$datalink = "http://www.ramaacademy.org/programming/vb6-step-by-step.php";
$new_data = str_replace  ("programming", "vb6-programming", $datalink);
echo  $new_data;

?>

from the code, you can update your link:

<?php
$sqlQ="UPDATE ra_articlez SET linkz=:new_data WHERE categoryz=:old_categ";
$sth= $mydb->prepare($sqlQ);
$sth->bindParam(':new_data', $new_data, PDO::PARAM_STR);
$sth->bindParam(':old_categ', $old_categ, PDO::PARAM_STR);   
$sth->execute();
//msg
echo "done successfully!";
?>

Besides, you can get more expl. here: Stackoverflow_answer

Community
  • 1
  • 1
don magug
  • 332
  • 1
  • 12