laflair13 Posted March 29, 2012 Share Posted March 29, 2012 Well I am looking to change this url http://website.com/product.php?Item=2369 to http://website.com/product.php?Item=Item-Name Heres a snip of the code that handles that. <?php include_once('mysql_connect.php'); $id = (int)$_GET['Item']; ?> any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/259912-changing-item-to-item-name-in-url/ Share on other sites More sharing options...
kazymjir Posted March 29, 2012 Share Posted March 29, 2012 I guess you use ID with SQL WHERE clause, yes? Instead of something like $id = (int)$_GET['Item']; $query = "SELECT * FROM Table WHERE id = {$id}"; you can use $name = $_GET['item']; "SELECT * FROM Table WHERE name = {$name}" Btw, always use mysql_real_escape() while inserting POST/GET data into SQL queries. Quote Link to comment https://forums.phpfreaks.com/topic/259912-changing-item-to-item-name-in-url/#findComment-1332152 Share on other sites More sharing options...
laflair13 Posted March 29, 2012 Author Share Posted March 29, 2012 Well it changed it but its coming in product.php?Item=Inline%20Tray%20Wrapper Quote Link to comment https://forums.phpfreaks.com/topic/259912-changing-item-to-item-name-in-url/#findComment-1332153 Share on other sites More sharing options...
laflair13 Posted March 29, 2012 Author Share Posted March 29, 2012 I am also trying to do it by changing the .htaccess file but it isn't working either. Trying to use RewriteEngine on RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1 Quote Link to comment https://forums.phpfreaks.com/topic/259912-changing-item-to-item-name-in-url/#findComment-1332155 Share on other sites More sharing options...
abrahamgarcia27 Posted March 29, 2012 Share Posted March 29, 2012 the thing is that this will not do your query, you are probably have to modify your code a bit <?php $word="this is the spaced word"; $word2 = str_replace( ' ', '', $word ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/259912-changing-item-to-item-name-in-url/#findComment-1332240 Share on other sites More sharing options...
abrahamgarcia27 Posted March 29, 2012 Share Posted March 29, 2012 Try this <?php $word="this is the spaced word"; $word2 = str_replace( ' ', '-', $word ); echo $word; echo "<br />"; echo $word2;echo "<br />"; ?> <a href="?id=<?php echo $word2; ?>">click</a><br /> <?php $string = $_GET[id]; $string2 = str_replace( '-', ' ', $string ); echo $string2; //use string two to query your data ?> Quote Link to comment https://forums.phpfreaks.com/topic/259912-changing-item-to-item-name-in-url/#findComment-1332242 Share on other sites More sharing options...
laflair13 Posted March 29, 2012 Author Share Posted March 29, 2012 Sorry for the dumb question, but where would I put that? At the very top? Quote Link to comment https://forums.phpfreaks.com/topic/259912-changing-item-to-item-name-in-url/#findComment-1332346 Share on other sites More sharing options...
abrahamgarcia27 Posted March 29, 2012 Share Posted March 29, 2012 well i think you have a page where it displays all the products which they have a link to the product_name=item-name correct ? so before we do this we will change all the products link to this <?php $word = $row['itemname']; $word2 = str_replace( ' ', '-', $word ); ?> <a href="?id=<?php echo $word2; ?>">See Product</a><br /> <?php //this is the other page $string = $_GET[itemname]; $string2 = str_replace( '-', ' ', $string ); echo $string2; //use string two to query your data "SELECT * FROM Table WHERE name = {$string2}" ?> Quote Link to comment https://forums.phpfreaks.com/topic/259912-changing-item-to-item-name-in-url/#findComment-1332444 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.