lovephp Posted July 12, 2016 Share Posted July 12, 2016 (edited) ok im trying to make seo url im creating slug ok but how do i insert along the id of that post? doing this following is definitely wrong im sure because i get 0 instead $id = $db->lastInsertId('id'); $stmt->execute(array( ':poster' => $uid, ':title' => $title, ':mobile' => $mobile, ':email' => $email, ':seourl' => ''.$id.'/'.$seourl how on earth i can acheive that? Edited July 12, 2016 by lovephp Quote Link to comment https://forums.phpfreaks.com/topic/301467-how-to-insert-the-post-id-along/ Share on other sites More sharing options...
Muddy_Funster Posted July 12, 2016 Share Posted July 12, 2016 sorry....what? Quote Link to comment https://forums.phpfreaks.com/topic/301467-how-to-insert-the-post-id-along/#findComment-1534436 Share on other sites More sharing options...
lovephp Posted July 12, 2016 Author Share Posted July 12, 2016 ok while inserting can i get the inserted id so that i could add the whatever inserted id to the seo url? Quote Link to comment https://forums.phpfreaks.com/topic/301467-how-to-insert-the-post-id-along/#findComment-1534437 Share on other sites More sharing options...
Solution Muddy_Funster Posted July 12, 2016 Solution Share Posted July 12, 2016 ok, change the following and let us know what it gives you: $id = $db->lastInsertId('id'); becomes $id = $db->lastInsertId(); var_dump('last-insert-id = '.$id); 1 Quote Link to comment https://forums.phpfreaks.com/topic/301467-how-to-insert-the-post-id-along/#findComment-1534438 Share on other sites More sharing options...
lovephp Posted July 12, 2016 Author Share Posted July 12, 2016 ok, change the following and let us know what it gives you: $id = $db->lastInsertId('id'); becomes $id = $db->lastInsertId(); var_dump('last-insert-id = '.$id); i did this $id = $db->lastInsertId(); var_dump('last-insert-id = '.$id); $stmt->execute(array( ':poster' => $uid, ':title' => $title, ':mobile' => $mobile, ':email' => $email, ':seourl' => ''.$id.'/'.$seourl but still 0 gets added in db not the id an also in browser i get this printed string 'last-insert-id = 0' (length=18) Quote Link to comment https://forums.phpfreaks.com/topic/301467-how-to-insert-the-post-id-along/#findComment-1534441 Share on other sites More sharing options...
ginerjm Posted July 12, 2016 Share Posted July 12, 2016 So - did you look at your db table to visually see what the value of id was? Quote Link to comment https://forums.phpfreaks.com/topic/301467-how-to-insert-the-post-id-along/#findComment-1534442 Share on other sites More sharing options...
lovephp Posted July 12, 2016 Author Share Posted July 12, 2016 yes bro in db the posted id is 8 here is how i exactly tried $stmt = $db->prepare('INSERT INTO table (poster,title,mobile,email,seourl) VALUES (:(poster, :title, :mobile, :email, :seourl)'); $id = $db->lastInsertId(); var_dump('last-insert-id = '.$id); $stmt->execute(array( ':poster' => $uid, ':title' => $title, ':mobile' => $mobile, ':email' => $email, ':seourl' => ''.$id.'/'.$seourl )); Quote Link to comment https://forums.phpfreaks.com/topic/301467-how-to-insert-the-post-id-along/#findComment-1534443 Share on other sites More sharing options...
lovephp Posted July 12, 2016 Author Share Posted July 12, 2016 what i am trying to acheive is like in here this topic has url like this phpfreaks.com/topic/301467-how-to-insert-the-post-id-along/ i am also trying to add the id like 301467 to the url Quote Link to comment https://forums.phpfreaks.com/topic/301467-how-to-insert-the-post-id-along/#findComment-1534444 Share on other sites More sharing options...
Jacques1 Posted July 12, 2016 Share Posted July 12, 2016 So you're trying to get the ID of the record you're just inserting? That's impossible. MySQL cannot predict the future. What's the whole point of the seourl field, anyway? If it's just the ID and the slugified title, then you can create the URL dynamically. There's no need to physically store it in the database. Quote Link to comment https://forums.phpfreaks.com/topic/301467-how-to-insert-the-post-id-along/#findComment-1534445 Share on other sites More sharing options...
lovephp Posted July 12, 2016 Author Share Posted July 12, 2016 yes bro guess you are right but how are you guys doing it on this forum added the 301467 to the url? Quote Link to comment https://forums.phpfreaks.com/topic/301467-how-to-insert-the-post-id-along/#findComment-1534446 Share on other sites More sharing options...
Jacques1 Posted July 12, 2016 Share Posted July 12, 2016 I'm not your bro. The URLs in this forum are probably generated dynamically. As I already said, it's just the ID concatenated with a URL-friendly version of the title: function get_topic_url($topic_id) { $title = get_topic_title($topic_id); return $topic_id.'-'.slugify($title); } 1 Quote Link to comment https://forums.phpfreaks.com/topic/301467-how-to-insert-the-post-id-along/#findComment-1534447 Share on other sites More sharing options...
lovephp Posted July 12, 2016 Author Share Posted July 12, 2016 I'm not your bro. The URLs in this forum are probably generated dynamically. As I already said, it's just the ID concatenated with a URL-friendly version of the title: function get_topic_url($topic_id) { $title = get_topic_title($topic_id); return $topic_id.'-'.slugify($title); } i tried something like this and seems to be working $stmt = $db->prepare('INSERT INTO table (poster,title,mobile,email,seourl) VALUES (:(poster, :title, :mobile, :email, :seourl)'); $stmt->execute(array( ':poster' => $uid, ':title' => $title, ':mobile' => $mobile, ':email' => $email, ':seourl' => ''.$id.'/'.$seourl )); $id = $db->lastInsertId(); $seturl = ''.$id.'/'.$seourl.''; $qry = "UPDATE jobs SET seourl = :seourl WHERE id = :id"; $stmt = $db->prepare($qry); $stmt->bindParam(':seourl', $seturl); $stmt->bindParam(':id', $id); $stmt->execute(); does it makes sense or should i remove it? do you think i should do it like this? Quote Link to comment https://forums.phpfreaks.com/topic/301467-how-to-insert-the-post-id-along/#findComment-1534448 Share on other sites More sharing options...
lovephp Posted July 12, 2016 Author Share Posted July 12, 2016 I'm not your bro. The URLs in this forum are probably generated dynamically. As I already said, it's just the ID concatenated with a URL-friendly version of the title: function get_topic_url($topic_id) { $title = get_topic_title($topic_id); return $topic_id.'-'.slugify($title); } and sorry bout the (Bro) apology if it offended you in any ways. Quote Link to comment https://forums.phpfreaks.com/topic/301467-how-to-insert-the-post-id-along/#findComment-1534449 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.