PHP - $_get Not Working
Hello, I am working on a cms site but I am having trouble with retrieving some info by id. I followed a tutorial on youtube and my code looks correct but my ID string is empty. Any help would be greatly appreciated. Class with functions
class Article {
$query= $pdo->prepare("SELECT * FROM article"); ************************************* Call to functions
include_once('includes/connection.php'); $article = new Article;
var_dump($_GET, $_POST);
if (isset($_GET['id'])){
print_r($data); When I var_dump the get and post I get array(0) { } array(0) { }. fetch all works great but fetch data does not and I am not sure where the post id is pulling from since there isn't a prior connection. Thank You, Devin Similar TutorialsI run into this every now and again and wonder if someone knows what I could be doing wrong. Using a simple $ClientID = $_GET['ID']; is not working on a certain page, I can see the ID=193 value in the address field but $ClientID remains an empty variable. I even try $_REQUEST instead, still nothing. I'm puzzled. I am attempting to insert data into a db via '?' in the url. The demonstration I've seen appears to work fine.
I am using Wamp 2.2, Apache 2.2.22, PHP 5.4.3 and MySQL 5.5.24.
My efforts merely take me off on a standard search.
Has the global $_GET changed.
My code.
<?php //error_reporting(0); require 'db/connect.php'; echo 'Connected'; //Added to be sure to be sure connected if(isset($_GET['first_name'])) { $first_name = trim($_GET['first_name']); if($insert = $db->query(" INSERT INTO people(first_name, last_name, bio, created) VALUES ('{$first_name}', 'Garrett', 'I\'m a web developer', NOW()) ")) { echo $db->affected_rows; } } ?> After the file is initiated the idea is to enter into the url ?first_name=Whatever press enter, the file should run and at the same time update the db. What am I missing. kev Okay im trying to make it so when some is on this link ("?serv=del&id=$ID") it displays a portlet of a yes/no form. onces yes/no is picked it goes to ("?serv=del&id=$ID&del=true"). I have no idea if im doing this right or if theres a better way of doing it. But trying to fix this problem has almost made me throw my computer threw my window. Thanks in advanced. <?php if(isset($_GET['serv']) && $_GET['id'] == $serverid && $_GET['del'] == 'true') { if($_POST['ture']) { mysql_query("DELETE FROM `notifications` WHERE `id`='$msgid'"); Echo "<center>Message Deleted</center>"; } else { Echo "<center>Message delete request has been canceled.</center>"; } } elseif(isset($_GET['serv']) && $_GET['id'] == $serverid) { ?> <div class="usercp_body"><!-- UserCP Notification Manage Start --> <div id="dash_chart" class="portlet" style="width:100%;margin: 0 auto;"> <div class="portlet-header"> <h4><center>All Servers For <?php echo $username; ?></center></h4> </div> <div class="portlet-content"> <form action="manage.php?serv=del&id=<?php echo $serverid; ?>&del=true" method="post"> <input type="submit" class="bgbtn blue" value="Yes" name="true" /> <input type="submit" class="bgbtn blue" value="No" name="false" /> </form> </div> </div> </div> <?php } ?> soory guys .. actually i am trying to add pagination in script.. but its not pagging.
but when i tried without isset($_get the code worked fine and then i tried to doing with isset($_get for a perticular cat
but its not working. can someone see my code and tell me whats worng i have done.
<!DOCTYPE HTML> <html> <head> </head> <body> <?php // include database connection include 'libs/db_connect.php'; // page is the current page, if there's nothing set, default is page 1 $page = isset($_GET['page']) ? $_GET['page'] : 1; // set records or rows of data per page $recordsPerPage = 1; // calculate for the query LIMIT clause $fromRecordNum = ($recordsPerPage * $page) - $recordsPerPage; // select all data $query = "SELECT * FROM posts ORDER BY post_id desc LIMIT {$fromRecordNum}, {$recordsPerPage}"; /* page and its LIMIT clause looks like: 1 = 0, 5 2 = 5,10 3 = 10,15 4 = 15, 20 5 = 20, 25 */ $stmt = $con->prepare( $query ); $stmt->execute(); //this is how to get number of rows returned $num = $stmt->rowCount(); //check if more than 0 record found if($num>0){ $cat=1; if(isset($_GET['cat'])){ $cat_id = $_GET['cat']; $get_posts = "select * from posts where category_id = '$cat_id'"; $run_posts = mysql_query($get_posts); while($row_posts = mysql_fetch_array($run_posts)){ $post_id = $row_posts['post_id']; $post_title = $row_posts['post_title']; $post_date = $row_posts['post_date']; $post_author = $row_posts['post_author']; $post_image = $row_posts['image']; $post_content = substr($row_posts['post_content'],0,80); echo " <div class='post_area'> <h4> <a href = 'details.php?post=$post_id'>$post_title</a> </h4> <div class='date'><div id='com'> Date</div>$post_date</div><span style='font-size:12px'><i style='color:grey;font-size:10px'>Posted By</i> </b>$post_author</span> <content><img src = '123dondadatest/news_images/$post_image' width = '100' height='100'/> <div>$post_content <br/><a id='rmlink' href = 'details.php?post=$post_id'> Read More...</a></div><br /><br/><br/><br/> </div> "; } } // *************** <PAGING_SECTION> *************** echo "<div id='paging'>"; // ***** for 'first' and 'previous' pages if($page>1){ // ********** show the first page echo "<a href='" . $_SERVER['PHP_SELF'] . "' title='Go to the first page.' class='customBtn'>"; echo "<span style='margin:0 .5em;'> << </span>"; echo "</a>"; // ********** show the previous page $prev_page = $page - 1; echo "<a href='" . $_SERVER['PHP_SELF'] . "?page={$prev_page}' title='Previous page is {$prev_page}.' class='customBtn'>"; echo "<span style='margin:0 .5em;'> < </span>"; echo "</a>"; } // ********** show the number paging // find out total pages $query = "SELECT COUNT(*) as total_rows FROM posts"; $stmt = $con->prepare( $query ); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); $total_rows = $row['total_rows']; $total_pages = ceil($total_rows / $recordsPerPage); // range of num links to show $range = 2; // display links to 'range of pages' around 'current page' $initial_num = $page - $range; $condition_limit_num = ($page + $range) + 1; for ($x=$initial_num; $x<$condition_limit_num; $x++) { // be sure '$x is greater than 0' AND 'less than or equal to the $total_pages' if (($x > 0) && ($x <= $total_pages)) { // current page if ($x == $page) { echo "<span class='customBtn' style='background:red;'>$x</span>"; } // not current page else { echo " <a href='{$_SERVER['PHP_SELF']}?page=$x' class='customBtn'>$x</a> "; } } } // ***** for 'next' and 'last' pages if($page<$total_pages){ // ********** show the next page $next_page = $page + 1; echo "<a href='" . $_SERVER['PHP_SELF'] . "?page={$next_page}' title='Next page is {$next_page}.' class='customBtn'>"; echo "<span style='margin:0 .5em;'> > </span>"; echo "</a>"; // ********** show the last page echo "<a href='" . $_SERVER['PHP_SELF'] . "?page={$total_pages}' title='Last page is {$total_pages}.' class='customBtn'>"; echo "<span style='margin:0 .5em;'> >> </span>"; echo "</a>"; } echo "</div>"; // ***** allow user to enter page number echo "<form action='" . $_SERVER['PHP_SELF'] . "' method='GET'>"; echo "Go to page: "; echo "<input type='text' name='page' size='1' />"; echo "<input type='submit' value='Go' class='customBtn' />"; echo "</form>"; // *************** </PAGING_SECTION> *************** } // tell the user if no records were found else{ echo "<div class='noneFound'>No records found.</div>"; } ?> </body> </html> Okay I have index.php in which i used <?php echo $_GET['name']; ?> and its working fine all over the page except a wizard form that loads on a button click. <?php echo $_GET['name']; ?> is working on entire page text (wherever i have used this) except a wizard form which loads on a button click. All the files of that wizard form are located in my website folder (e.g. wizard.php, wizard.js & wizard.css). here's how wizard.php code starts: <div class="wizard-container"> <div class="card wizard-card" data-color="green" id="wizardProfile"> <form action=""> <div class="wizard-header"> <h3 class="wizard-title"> GENERATE A FRESH <?php echo $_GET['name']; ?> CODE </h3> <h5 style="margin-left: 10px; margin-right: 10px;">Our interactive generator will guide your through the process</h5> </div> i want that <?php echo $_GET['name']; ?> should also work in wizard form but it shows the following error: C:\xampp\htdocs\NameGenerator\content\hbox\html\wizard.php on line 7 Sorry for my bad explanation i don't know much about php so i explained it like this Please help... A few months ago, and a good amount of time before that, I had people telling me to use isset() instead of performing to see if the variable is empty, such as: !$_GET[''] I know the differences in the function and what they do, but when could isset() be used in a situation where it's better/more efficient then: !$_GET[''] I do use isset(), though. I never really thought about it before, but recently I visited a site with a url like: www.example.com/?OR Which made me wonder how you would go about getting that keyname since it is without a value. Any ideas? I have javascript to load to my div the contents from php files something like this: QueryString is an addon javascript file loaded above so it works.. var get_id = $.QueryString["id"]; switch(get_id){ case 'page1': $('#div').load('php.php'); break; } on php.php when i try to get the $_GET['id']; which is obviously 'page1' it cant display it... i get nothing , i use switch in order to create dynamic div so i can click in my links and just load the divs content thanks. I am seen people have dynamic pages that loads the information from a database and then displays that information from the url. EG domain.com/somedirectory/something I have a website that does this but uses domain.com/something.php?id=something . This works great but when I go to try and get the statistics for that page from facebook for number of people that have liked that page. When I go to: http://graph.facebook.com/http://likebook.cz.cc/ It shows me the information: Code: [Select] { "id": "**************", "name": "LikeBook", "picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs178.ash2/41817_130259343675613_3465_s.jpg", "link": "http://www.facebook.com/pages/LikeBook/130259343675613", "category": "Website", "description": "Collect every like at LikeBook.cz.cc", "fan_count": 3 } But when I try and go to: http://graph.facebook.com/http://likebook.cz.cc/like.php?id=31 It shows me: Code: [Select] { "id": "http://likebook.cz.cc/like.php" } So what I need to do is. Make a dynamic page within that sub directory. So that http://likebook.cz.cc/like/31 does grabs the information from line 31 of my database, like http://likebook.cz.cc/like.php?id=31 would do. Thank you ~AJ Hello can any one help me with this question iv only just started to use the get function like <code> if (isset($_GET['pageID'])){ echo $row['content']; } </code> can any one if me info how to make it safe I have some javascript for a tabbed interface in index.php. The content of each tab is in content.php which uses $_GET to define which tab is selected. But i want to include queries based on variables from index.php how would i do this? here is the code for the tabbed interface: <script language="JavaScript" type="text/javascript" src="<?php echo SITE_ROOT; ?>/js/ahahLib.js"></script> <script language="JavaScript" type="text/javascript"> function makeactive(tab) { document.getElementById("tab1").className = ""; document.getElementById("tab2").className = ""; document.getElementById("tab3").className = ""; document.getElementById("tab"+tab).className = "active"; callAHAH('includes/content.php?content= '+tab, 'content', 'Loading...', 'Error'); } </script> <ul id="tabmenu" > <li onclick="makeactive(1)"> <a class="" id="tab1">Account Information</a> </li> <li onclick="makeactive(2)"> <a class="" id="tab2">Second Page</a> </li> <li onclick="makeactive(3)"> <a class="" id="tab3">Third Page</a> </li> </ul> <div id="content"></div> and the code in content.php if ($_GET['content'] == 1) { echo 'Content for Page 1'; } if ($_GET['content'] == 2) { echo 'Content for Page 2'; } if ($_GET['content'] == 3) { echo 'Content For Page 3'; } ive tried adding the variable $user_id to the content.php url as follows: callAHAH('includes/content.php?user=$user_id&content= '+tab, 'content', 'Loading...', 'Error'); } but that just brought up an error. Please i will like to know what this variable $_GET['id']is used for and how to use it Thanks I cannot seem to get my link to work.. I want to build a php script that has more than one $_GET command.. The link I want to make is: index.php?section=tutorial&viewing=18-classes_or_ids. Here is my PHP code.. <?php $section = $_GET['section']; switch ($section) { case "home": include("home.html"); break; case "register": include("register.html"); break; case "tutorial_home": include("tutorial.html"); break; default: include("home.html"); } $tutorial = "?section=" . urlencode('tutorial&viewing') . $_GET['tutorial&viewing']; switch ($tutorial) { case "18-classes_or_ids": include("classesorids.html"); break; } ?> Please help me!! Hi I am trying to use 2 codes to get a url link. code1 (test.php): <form action="test1.php" method="GET" /> link: <input type="text" name="link" /><br /> <input type="submit" value="Submit" /> </form> code2 (test1.php) <?php $link = $_GET['link']; echo $link; ?> If I input a link as a text such as "Yahoo" it works. But if I input a link as "http://yahoo.com", it didn't work . I have a link (http://site.com/user/redirect). This link directs me to "site.com/user.php?level=site.com/123.php?hp=1" How can I echo just "site.com/123.php?hp=1"? I know how to use $_GET but I don't know how I can apply it to this. How to find the name value using php or $_GET here is the url header("Location:http://localhost:8666/OnlineBookingsPhp/index.php?name=Next"); Thanks Hi there, I am new to this forum want to say Hi to everyone . I just learn a little bit of PHP. I couldn't figure this out. Could someone please help me? Many thanks. 1. when I ran the 1st code below, it showed me "thank you" in the browser. <?php $title=$_GET[title]; echo $title; ?> 2. when I ran the 2nd code below, I got what I wanted. <?php $sql = "SELECT * FROM mytable WHERE title='thank you' "; ... ?> 3. when I ran the 3rd code below, it showed me a blank page . <?php $title=$_GET[title]; $sql = "SELECT * FROM mytable WHERE title='<?php echo $title; ?>' "; ... ?> How to make the 3rd code work like the 2nd one? It seems a php code under php is NOT working. how would i get this to work if they have click on the add page and the action is add i want it to do something how would i do it Code: [Select] <?php if(isset($_GET['action'])){ } ?> <a href="pages.php?action=add">Add Page</a> I am a new programmer. I am working on a personal project for my portfolio, it is a simple blog. I am trying to give the user the ability to delete a blog entry. It works fine, the problem is that when you refresh the page, with out clicking 'delete' the entry is still deleted. $_GET is passing the $id to my function and it is executing. The code I have posted is my effort to fix the problem. How can I connect $_GET to the delete button ? I have tried using a hidden value but this is not working. Any help would be greatly appreciated. AL Code: [Select] // code to display message before deletion if($_GET['T']) { echo("<div style='float:right; width:25%; height:100px; position:absolute; top:150px; right:15%;'>"); echo("<h2>Are you sure you want to delete:<h2>"); echo $_GET['T']; echo("<form method='get' action='?'>"); echo("<input type='submit' name='button' value='Delete'>"); echo("<input type='hidden' name='submit_check' value='1'>"); echo("</form>"); echo("<form action='http://nuke.industry.com/Blogspiracy/UserPage/index.php'>"); echo("<input type='submit' value='Cancel'/>"); echo("</form>"); echo("</div>"); } // code to delete a selected blog entry function delete_blog($id) { global $dbh; $sql = "DELETE FROM tblBlog WHERE tblBlog.id = '$id' LIMIT 1;"; $sth = $dbh->prepare($sql); $sth-> execute(); return; } if (isset($_GET['id']) && ($_GET['submit_check'])) how do I "GET" the hidden value? { $remove = delete_blog($_GET['id']); } [code] I am really confused about how people use $_GET to give a page a link so far what I understand is that $_GET grabs the information from a link So if my link was http://localhost/stargate/users/profile.php?goauld=Sam how do I turn this into viewing Sams profile soon as i type in that link with out having to hit a search button first would really appreciate if someone help me understand this please cause it appears i really need to know how to do this. Code: [Select] <?php if(isset($_POST['search'])) { // searches goaulds then displays them $search3 = "SELECT goauld,id FROM users WHERE goauld='".mysql_real_escape_string($_POST['goaulds'])."'"; $search2 = mysql_query($search3) or die(mysql_error()); WHILE($search1 = mysql_fetch_array($search2)){ $grab_goauld = $search1['goauld']; echo '<table width="300" height="5" border="1" align="center">'; echo '<th><center>Goauld Statistics</center></th>'; echo "<tr><td height='340'>$grab_goauld</td></tr>"; } } echo '</table>'; ?> |