PHP - Getting Url Parameter .. Not As Easy As It Seems
Hey guys,
I'm dealing a url that is similar to hxxp://domain/directory/?#{$id}. What I'm trying to do is extract $id from that. Its not available as a $_GET variable and $_SERVER['REQUEST_URI'] comes up as "/directory/?". Does anyone know how I could retrieve $id ? Thanks Similar TutorialsI have the following code just to insert a username and hashed password into the database but somehow I am getting this error and I couldn't find out where I am doing it wrong...can someone please give me a hand?
I tried it in two ways and both errors...
the first few lines are just connecting database which worked fine and a password.php so I can use password_hash() with my php version
$hash = password_hash('xx', PASSWORD_BCRYPT, array('cost' => 10)); $username = 'xx'; $insertQuery = $db->prepare(" INSERT INTO et_todo (username, password) VALUES (:username, :hash) "); $insertQuery->execute(array( 'username' => $username, 'password' => $hash ));also tried $hash = password_hash('xx', PASSWORD_BCRYPT, array('cost' => 10)); $insertQuery = $db->prepare(" INSERT INTO et_todo (username, password) VALUES ('xx', :hash) "); $insertQuery->execute(array( 'username' => 'xx', 'password' => $hash )); Hello,
I recently posted here about an issue I was having with my database orientated products page.
I have now run into another problem where say if, /db.php was typed or /db.php?p=IDoNotExist was typed, it returns blank.
I have in my code the desired content to be displayed, but it just doesn't seem to want to make a show.
I was also wondering if it is possible to show different content for whatever the URL is, so for no parameter, the content about the products, and a non existent one, maybe "Product not found"?
Here is my code:
<?php $db=mysql_connect ("localhost", "webwibco_charlie", "Hello123") or die ('I cannot connect to the database because: ' . mysql_error()); $mydb=mysql_select_db("webwibco_products"); include("header.php"); $status = htmlspecialchars( @$_GET ['p'] ); if ($status == "floorpuzzles") { echo "<h1>Our Floor Puzzles</h1>"; $sql="SELECT ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" . FloorPuzzles . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; echo "<div class=\"box\">"; echo "<h1>$Name</h1>"; echo "<div class=\"floorbox\"><a href=\"?p=$ID\"><img src=\"images/products/catalogue/big/floorpuzzles/$ID.jpg\" class=\"small\"></a></div>"; echo "<h2>$Description</h2>"; echo "</div>"; } ?> <? }else{ if ($status == $_GET["p"]) { $sql="SELECT ID, Name, Tags, Description, Pieces, Size, Barcode, Category FROM products WHERE ID = '" . $_GET['p'] . "'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; $Pieces =$row['Pieces']; $Size =$row['Size']; $Barcode =$row['Barcode']; echo "<div class=\"1\">"; echo "<h1>$Name</h1>"; echo "<div class=\"bigbox\">"; echo "<div class=\"floorbox\"><img src=\"images/products/catalogue/big/floorpuzzles/$ID.jpg\" class=\"big\"></div>"; echo "</div>"; echo "</div>"; echo "<div class=\"2\">"; echo "<p>Puzzle Pieces: $Pieces</p> <p>Puzzle Size: $Size</p> <p>Barcode: $Barcode</p>"; echo "</div>"; } }else{ ?> <? echo"<h1>Our Products</h1> <p>Our jigsaw puzzles are hand cut by skilled craftsmen and therefore each one is unique with self-correcting pieces. There is a strict quality control process at all stages by our highly experienced staff. The puzzles are durable and provide fun and excitement, enhancing learning and a child’s development.<p> <p>All of our jigsaws are made using materials from sustainable resources grown in managed forests. Where possible we support companies in the UK and source our components locally, most of our suppliers are in the East Midlands, many in Derbyshire and Nottinghamshire. We keep packaging to a minimum and take our environmental and ethical responsibilities very seriously.</p> <p>Reducing waste and recycling was a way of life for us before it became fashionable. We are constantly searching for new ideas and consult teachers when developing our jigsaws, which are often used within the national curriculum.</p> <p>As well as making our own range, we manufacture for leading suppliers to the education market. Check for \"Made in Britain\" and it is probably made by us.</p> <p>We have a wide variety of products available for viewing, from classic floor puzzles to innovative inset trays. You can take a look at all our products on this page, simply use the navigation buttons to your left.</p>"; }} include("footer.php"); ?>The final echo is what I wish to be displayed on the URL without or with an invalid parameter. Here is my site URL: http://www.webwib.co...saws/search.php (note that only the "Floor Puzzles" category has content within it). Thank you in advance for assistance. Hi! Code: [Select] $url = "http://www.youtube.com/watch?feature=player_embedded&v=IwPHy17Iu6E"; I have code Code: [Select] if (preg_match("/http:\/\/www.youtube.com\/watch\?v=([0-9a-zA-Z-_]*)(.*)/i", $url, $matches)) { return '<object height="'.$embed_height.'" width="'.$embed_width.'">'. '<param name="movie" value="http://www.youtube.com/v/'.$matches[1].'" />'. '<param name="wmode" value="transparent" />'. '<embed src="http://www.youtube.com/v/'.$matches[1].'&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" height="'.$embed_height.'" width="'.$embed_width.'" />'. '</object>'; }How to remove feature=player_embedded& from $url ? Hi guys, please help me to solve my problem. i want to get the url parameter using /
for now i use index.php?category_id=14
how can i change the ?category_id=14 to index.php/14
thank you so much.
I have a pagination class that uses PHP_SELF to display the proper URLs when generating the pagination buttons. I need PHP_SELF to be a class parameter so that if the page is not defined in the parameter, then use PHP_SELF. The reason for this is because I generate the class in an ajax file and it is returning the URL of the ajax file, not of the page I am running the ajax on. I just don't know how to add the parameter to the class. The class is below: Code: [Select] <?php class Paginator{ var $items_per_page; var $items_total; var $current_page; var $num_pages; var $mid_range; var $low; var $high; var $limit; var $return; var $default_ipp; var $querystring; function Paginator() { $this->current_page = 1; $this->mid_range = 7; $this->items_per_page = (!empty($_GET['ipp'])) ? $_GET['ipp']:$this->default_ipp; } function paginate($default_ipp) { if((isset($_GET['ipp'])) && ($_GET['ipp'] == 'All')) { $this->num_pages = ceil($this->items_total/$default_ipp); $this->items_per_page = $default_ipp; } else { if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $default_ipp; $this->num_pages = ceil($this->items_total/$this->items_per_page); } if(isset($_GET['page'])) { $this->current_page = (int) $_GET['page']; // must be numeric > 0 } if($this->current_page < 1 Or !is_numeric($this->current_page)) $this->current_page = 1; if($this->current_page > $this->num_pages) $this->current_page = $this->num_pages; $prev_page = $this->current_page-1; $next_page = $this->current_page+1; if($_GET) { $args = explode("&",$_SERVER['QUERY_STRING']); foreach($args as $arg) { $keyval = explode("=",$arg); if($keyval[0] != "page" And $keyval[0] != "ipp") $this->querystring .= "&" . $arg; } } if($_POST) { foreach($_POST as $key=>$val) { if($key != "page" And $key != "ipp") $this->querystring .= "&$key=$val"; } } if($this->num_pages > 1) { $this->return = ($this->current_page != 1 And $this->items_total >= 1) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$prev_page&ipp=$this->items_per_page$this->querystring\">« Previous</a> ":"<!--<span class=\"inactive\" href=\"#\">« Previous</span>-->"; $this->start_range = $this->current_page - floor($this->mid_range/2); $this->end_range = $this->current_page + floor($this->mid_range/2); if($this->start_range <= 0) { $this->end_range += abs($this->start_range)+1; $this->start_range = 1; } if($this->end_range > $this->num_pages) { $this->start_range -= $this->end_range-$this->num_pages; $this->end_range = $this->num_pages; } $this->range = range($this->start_range,$this->end_range); for($i=1;$i<=$this->num_pages;$i++) { if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " ... "; // loop through all pages. if first, last, or in range, display if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range)) { $this->return .= (($i == $this->current_page) And (isset($_GET['page'])) And ($_GET['page'] != 'All')) ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> "; } if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-1]) $this->return .= " ... "; } $this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 1) //And ($_GET['page'] != 'All') ) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$next_page&ipp=$this->items_per_page$this->querystring\">Next »</a>\n":"<!--<span class=\"inactive\" href=\"#\">» Next</span>-->\n"; //$this->return .= ((isset($_GET['page'])) And ($_GET['page'] == 'All')) ? "<a class=\"current\" style=\"margin-left:10px\" href=\"#\">All</a> \n":"<a class=\"paginate\" style=\"margin-left:10px\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\">All</a> \n"; } else { for($i=1;$i<=$this->num_pages;$i++) { $this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> "; } $this->return .= "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\">All</a> \n"; } $this->low = ($this->current_page-1) * $this->items_per_page; if(isset($_GET['ipp'])) { $this->high = ($_GET['ipp'] == 'All') ? $this->items_total:($this->current_page * $this->items_per_page)-1; $this->limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this->low,$this->items_per_page"; } else { $this->high = ($this->current_page * $this->items_per_page)-1; $this->limit = " LIMIT $this->low,$this->items_per_page"; } } function display_items_per_page() { $items = ''; $ipp_array = array(10,25,50,100,'All'); foreach($ipp_array as $ipp_opt) $items .= ($ipp_opt == $this->items_per_page) ? "<option selected value=\"$ipp_opt\">$ipp_opt</option>\n":"<option value=\"$ipp_opt\">$ipp_opt</option>\n"; return "<span class=\"paginate\">Items per page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page=1&ipp='+this[this.selectedIndex].value+'$this->querystring';return false\">$items</select>\n"; } function display_jump_menu() { for($i=1;$i<=$this->num_pages;$i++) { $option .= ($i==$this->current_page) ? "<option value=\"$i\" selected>$i</option>\n":"<option value=\"$i\">$i</option>\n"; } return "<span class=\"paginate\">Page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page='+this[this.selectedIndex].value+'&ipp=$this->items_per_page$this->querystring';return false\">$option</select>\n"; } function display_pages() { return $this->return; } } Hello I am experiencing some issues with a function and I cannot identify the problem. The function is not receiving any parameter. The URL values are passed correctly. I used echo to display the parameters outside the function and that worked. I also used echo to display the parameters inside the function and no parameter were displayed. So the function is not receiving parameters. Code: [Select] <?php $find = $_REQUEST['u_find']; $field = $_REQUEST['u_field']; $searching = $_REQUEST['u_search']; echo"(1a)$find, (1b)$field, (1c)$searching";//outside function function test_display($searching, $field, $find) { echo"(2a)$find, (2b)$field, (2c)$searching";//inside function } ?> Code: [Select] function fetch_feedback_best() { $sql = "SELECT `like` FROM `feedback` GROUP BY `page` asc LIMIT 10"; while($row = mysql_fetch_assoc($sql)) { $results[] = $row; } return $results; } This doesn't work. My error is "Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in /blah.inc.php on line 105 ". Code: [Select] <?php $results = fetch_feedback_best(); foreach ($results as $result) { ?> echo $result['page']; } ?> Hi all I have an SQL database with products in and I need to write the PHP script to select from the SQl based on values in the URL. The URL looks like this: product.php?category=32&type=90&colour=10 So I can do the script: if (isset($_GET['category']) && isset($_GET['type']) && isset($_GET['colour'])){ $sqlCommand = "SELECT * FROM products WHERE category = '$category' AND type = '$type' AND colour = '$colour'"; } Which works great, I have also got the other versions if the type and colour are empty. What I can't do is get it to select all from the database where the category = 32 and the type = 90 if the URL looks like this: product.php?category=32&type=90&colour= In other words where the colour is set but is empty. I want the script to show all products that have the category of 32 and the type of 90 if this is the case Please help! Many thanks Pete I am trying to create a simple voting form. Everything goes well until I submit and then I get a Warning: mysqli_error() expects exactly 1 parameter, 0 given on line 79 error. I am assuming it is not pulling the ID correctly but as I am new to php and mysqli I cannot exactly say if it the way the code is written or if I am calling the parameter incorrectly in the query. Again I am new to to this so please be gentle. Below is my code. It pulls the drop down list correctly and echo's correctly but I believe my post query to be a little out of wack. Could someone point me in the correct direction? It would be very appreciated.
<form action="businesstype_update.php" method="post"> <?php if(isset($_POST['voteall'])){ $vote_lg = "update membertest where id={$row_lg['id']} set vote=vote+1"; $run_lg = mysqli_query($con, $vote_lg) or die(mysqli_error()); } $result_lg = mysqli_query($con, "SELECT id, business FROM membertest WHERE businesstype='large'"); echo "Vote for large business of the year! <SELECT name='business'>\n"; echo "<option>Select a large business</option>"; while($row_lg = $result_lg->fetch_assoc()) { echo "<option value='{$row_lg['id']}'>{$row_lg['business']}</option>\n"; } echo "</select></br></br>\n"; echo "<input type='submit' name='voteall' value='voteall'>"; $result_lg->close(); $con->close(); Hi all
Is it possible to have a function with two parameters but and then check if one is passed before using it.
In this code here I want to remove spaces and change to lowercase.
If the $extra parameter is set I want to add that to the end of the string.
function className($nametoUse, $extra){ ob_start(); include('file.php'); $content = ob_get_clean(); ok so this is the code i found for adding a file to a variable.. now how would i use it in term of this: <?php $id = NULL; if(isset($_GET['id']) && $_GET['id'] == "1"){ $id = 'Marc'; } else if(isset($_GET['id']) && $_GET['id'] == "2"){ $id = 'Glenn'; } else if(isset($_GET['id']) && $_GET['id'] == "3"){ $id = 'Nathan'; } else if(isset($_GET['id']) && $_GET['id'] == "4"){ $id = 'Scott'; } ?> ok so the get variable checks to see whose id youve requested. then when for example id = 4 i want to display an include file somewhere else on the page so i would use.. <?php echo $id; ?> now insted of it being "nathan" i want it to be a file i didnt really understand the first code i found Hi all I am working on a filter system that when a user selects a drop down menu item it automatically updates the page taking the value from the form and sending it through the URL parameter to update the page accordingly: <form id="category_filter" name="category_filter" method="post" action=""> <label for="category_filter"></label> <select name="category_filter" id="category_filter" style="width: 160px" onchange="this.form.submit();" > <option value="" selected class="meter-calc-text">Category</option> <?php $fetchcategories=mysql_query("SELECT * FROM `categories` ORDER BY position ASC"); while($returnedcategories=mysql_fetch_array($fetchcategories)) { echo "<option value=\"".$returnedcategories['name']."\" >".$returnedcategories['name']."</option>"; } ?> </select> </form> The only thing is, it doesn't pass the value to the url, it remains blank Many thanks for your help. Pete May I know what does this mean, this is the code which they are referring to. I have tried troubleshooting, still could not find the cause, appreciate if anyone can help? Thanks Warning: mysqli_error() expects exactly 1 parameter, 0 given in D:\inetpub\vhosts\championtutor.com\httpdocs\inc\elements\t_reg_post1.php on line 204 /**INSERT into tutor_musical_background table**/ foreach($musics as $music) { $query6 = "INSERT INTO tutor_musical_background (tutor_id, musical_instrument_id) VALUES ('$tutor_id', '$music')"; $results6 = mysqli_query($dbc, $query6) or die(mysqli_error()); $file = 'includes/views.txt'; $f = fopen($file, 'w+'); $views = fread($f, filesize($file)); fwrite($f, $views+1); fclose($f); The contents of views.txt is: Code: [Select] 1 Why is it returning it needs to be greater than 0?...The file isn't empty. Hello all, I'm an absolute Newbie to PHP. I'm struggling with a problem that I think is extremely basic to you experts but I just can't get it to work. In short, I have an application that has a link that goes to: Site1/dir/admin?id=(text)&page=(number) I want to redirect to a link that's identical except it's Site2 at the beginning instead of Site 1. What I've attempted so far is this: <?php $GLOBALS[$passid]=$_GET['id']; $GLOBALS[$passpage]=$_GET['page']; header( 'Location: http://site2.com/dir/admin/?page=$passpage&id=$passid'); ?> But it just redirects to http://site2.com/dir/admin/?page=$passpage&id=$passid (with all of that text being literally what is in the URL, not the variable values) I have a feeling I'm doing something small but very basic wrong. The $GLOBALS thing was an afterthought. Outcome is the same with or without that. Any help much appreciated!!! Hi all I am building a page to filter SQL values but I'm not sure how to write the code for the query. My URL looks like this: stone.php?category=Wood&type=4&colour=1&Submit=Submit Firstly, can I remove the submit from the URL? Then I have my code to create the query: $fetchData=mysql_query("SELECT * FROM `products` WHERE category = "'.$_GET'category.'""); Can I combine this for the type and colour? Many thanks Pete Hi all I am trying to write a piece of code that selects different products from the database based on the URL parameter. There are 3 fields; category, type and colour. My URL will look like this if there is all three selected: product.php?category=31&type=74&colour=3 Basically, if what ever is set in the url I need this to be selected from the database. Here's my code: if (!isset($_GET['category']) && !isset($_GET['type']) && !isset($_GET['colour'])){ $fetchproducts = mysql_query(" SELECT * FROM `products` "); $lightboxcount = 0; while($returnedProduct = mysql_fetch_array($fetchproducts)) { $lightboxcount ++; include('product-cell.php'); } } Although if there is no colour or the colour is blank like this: product.php?category=31&type=74&colour= I want it to select the items from the database just where the category and type are set. Please help! Many thanks Hi Chaps, I have a while loop which produces a couple of variables: do { $L_NAME.$i = 'Item 1'; $L_NUMBER.$i = '0001'; $L_QTY.$i = '1'; $L_AMT.$i = 10.50; $NVP.$i = "L_NAME.$i.= .$L_NAME.$i.&L_NUMBER.$i. = .$L_NUMBER.$i.&"; } while($i == $items); Basically what I need to do is contruct a parameter made up of all the $NVP variables. I've a feeling that I would need to add each variable to an array and then use a foreach statement, but I'm not 100% sure. I'd be interested in the correct way to go about this, any comments welcome! This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358276.0 Hello, I want to use this function in form. How can I pass parameter in form ? please help me. Thanks <?php function displayName($fetch) { echo "your Name is ".$fetch; } ?> |