unable to pass the imageid to the other page using get method - php

This might be a simple question but now i started working on GET method so I'm kinda new to it.
I have some images which are given some unique ids:
<imagetag>;
$b is the variable that stores the ID of the image.
Now I want to pass the $b variable value to imageid.php.
The link successfully opened imageid.php in my browser but the URL looks like imageid?id=. It does not display the id in the URL.
I also tried doing this:
echo $_GET['id']; // in my imageid.php
... but it's not printing the id that I just passed to imageid.php using the GET method? Why?

There isn't really enough information in your question to give a full answer, but have you checked that $b is really holding the image ID? Also, are you side "echo $var = $_GET['id'];" wouldn't just echo whether or not $var was assigned to? (i.e. false or true).
Please provide the full code so I can reply with a better answer.

Related

How to get value of Shortcode when its appended to URL and Stored in Database

I stored the url in Database
https://example.in/register/?ref=[affiliate_id]
and I tried to get the affiliate id of current logged in user.But I am unable to get the value when I print it.
But if I used as directly like using
$val = do_shortcode('[[affiliate_id]');
I am getting the value.
Please solve my issue
I am not sure but use below code it might be resolved your problem
add_action('init','runShortcode');
function runShortcode(){
$getCode = $_request['ref'];
If($getCode)
{
$shirtcodes = '['.$getCode.']';
echo do_shortcode($shirtcides);
}
Not sure with code

how to check if bookmarks exist in html document

I've just designed my first form in HTML and a PHP page to display the results. In the form the user inputs some codes in response to some questions, a bit like a multiple choice, so for example, these are "ABC". The PHP page displays the code to the user as a link, which when clicked will go to a bookmark (a link within the same page) with the ID #ABC. This was achieved with simple manipulation of the PHP variable as follows:
<?php
$code = "ABC"
$part1 = '<a href="mywebpage.php#';
$part2 = '">Go to this code</a>';
$string = $part1.$code.$part2;
echo $string;
?>
(i.e. Link in the page says "go to this code" and when clicked will go to section with bookmark ABC)
This all works fine, but I simply need to know if there is a way of error trapping so that if a bookmark does not exist for the code entered, a message can be displayed to the user instead? Can this be done using the PHP variable, or do I need to use JavaScript? One work around may be to search the web page for the ID "#ABC'. Is it possible to do this? Another option would be to store an array of valid codes on the server then query this before setting the bookmark, but I want to keep it as simple as possible. Any help appreciated, thanks.
What you call a "bookmark" we call a hash. And when you say "go to a bookmark" you mean a hash change. Hash changes do not make an additional request to the server, it is all handled on the client-side, therefore this must be done with JavaScript and not PHP.
So let's just do some simple JavaScript on hash change window.onhashchange that will search for an element with that ID and if it's not found alert something.
window.onhashchange = function(){
if(!document.getElementById(location.hash){
alert("not found");
}
}

echo function call 2 variables

Ok so I have the code for a form that is called and works but it needs two varibles grabbed from the string of a url. I have the first and the second is the same for what im doing on any page that I am creating which is alot. Here is the code at the url: collabedit.com/9g99j
Question if Get <?php echo $_GET['id']; ?> is grabbing my id string from the url how do I use this in the echo of my function I just defined at the bottom of the code? Instead of having this: echo DescriptionGet(1256124, 50874); can someone tell me how to put something like this: echo DescriptionGet(1256124, $id);
This would make it so i dont' have to enter that id value for every page I want to create.
Thanks,
Thanks everyone for your replies and I was able to figure it out on my own and actually used exactly what the first reply was.
Now I have a new question about this function. How do I make it grab the image from that same page its grabbing the form code from? I can't figure this part out and its keeping me from doing mass automation for this site.
Anyone help?
Try this:
$id = $_GET['id'];
echo DescriptionGet(1256124, $id);
You can change your function definition from:
function DescriptionGet($c, $id)
to
function DescriptionGet($c, $id=50874)
Each time when you will call DescriptionGet($c) it will behave as you passed $id=50874 but also if you need you can call DescriptionGet($c, 20) and $id in the function will be set to 20.
And in case you want to simple use $_GET['id'] as function parameter you can simple run
echo DescriptionGet(1256124, intval($_GET['id']));
you don't even need to use extra variable.

Get an id then put it into a href

I'm a bit new to this so sorry if this has been covered already but i'm going around in circles searching.
I've had a look around learn t how to edit htaccess and use the get function, I then even found a plugin called redirection that did similar.
What I would like to do is if I have a URL http://example.com/file.php?id=blue
is to grab the id which is "blue"
then in a href link dynamically add it to the end of another url
Link Example
If someone could help show me or point me in the right direction on how to get the id blue and add it into a href that would be great.
Many Thanks
You have to use $_GET. People might be dicks about it here - but I had a hard time when I was first learning to program too. You'll get it, don't worry.
This is how get works (at least, all you need to know about how it works):
if you have the file index.php
if you add a query string to the end of it like index.php?id=1
You can access id=1 by doing the following in your code:
$id = $_GET['id'];
Similarly if the query string contains the following index.php?id=1&page=5&par=3&club=putter&upnext=tigerwoods
On the left hand of the equal sign is the Key(id, page, par, club, upnext) and on the right side their value(1,5,3,putter,tigerwoods)
One thing to remember is that when retrieving numbers from the query string they will always be of the string type, so you cant do something like
if ( $_GET['page'] === 5 )
you'll have to do
if ( $_GET['page'] == 5 )
and to echo it into a link:
$club = $_GET['club'];
if ( $club == 'NRA' ) {
echo "Gun Show";
echo 'Buy tickets to my gunshow ^^';
}
Hope this helps!
You can also do things like set your website up so that it has one template and use the $_GET parameter to determine which files to include into the content sections of the site via a switch command. I do this, but not across my whole site. For my user control panel, I do this to simply include only the file necessary (change email, update password, delete account, update profile, etc)
Cah'piche?
Use the $_GET parameter.
YAY!!

mysql LAST_INSERT_ID() is causing some SQL problems when passing back value retrieved

I need some help figuring out why the following scenario does not work. I'm trying to retrieve a value from the last updated ID in mysql, then pass that value via javascript over to an ajax call which calls a .php page, which also calls another function "ZEND_emaiL" in a different php page.
In the very first php page that retrieves the id from mysql LAST_INSERT_ID(), if I hard code the value "100" it works, but if I use the value returned from LAST_INSERT_ID() it causes a failure.
Here's the php code for the LAST_INSERT_ID():
$sql='SELECT LAST_INSERT_ID();';
$last_updated_id = $db->get_var( $sql );
$last_updated_id = $last_updated_id+0;//make int
echo $last_updated_id; //send output back to the ajax call
var_dump($last_updated_id); ------------->RETURNS **int 149**
if I send back a hard coded "100" like this: echo 100; then it works.
Any ideas? Thanks for your help in advance.
The following are values retrieved from the php page that contains the ZEND_email() function. I grabbed these for debugging purposes hoping it would help.
RETURN VALUES for Hard Coded:
var_dump($n_id);---------->Returns **int 100**
var_dump($sqlresult);----->Returns **resource 24**
var_dump($row);----------->Returns **array of data to parse through**
RETURN VALUES FOR Passed in Variable (Fails):
function ZEND_email($to, $from="", $subject="", $msg="", $notif_id='', $root_dir="")
{
var_dump($notif_id);---------------------->RETURNS **string '100'**
$notif_id = $notif_id+0;//convert to int
var_dump($notif_id);---------------------->RETURNS **int 100**
$n_id = $notif_id;
$xsql = $sql_str->SQL_SELECT_all_notif_attachments($account_id, $n_id);
$sqlresult=mysql_query($xsql);
$row=mysql_fetch_row($sqlresult);
var_dump($n_id);---------------->RETURNS **int 100**
var_dump($sqlresult);----------->RETURNS **resource 24**
var_dump($row);----------------->RETURNS **boolean false**
}
you are aware that you could use mysql_insert_id() ?
see http://uk.php.net/manual/en/function.mysql-insert-id.php which would give you an INT value directly,
btw, to convert a variable to integer you can use:
$foo = (int) $bar
or
$foo = intval($bar);
or
$foo = settype($bar,'int');
Hard to tell from those code snippets. Better check what's going on on the client-side.
E.g. with firebug you can both check the actual response data and step into the javascript code.
Had to scrap this code...couldn't get it all to work with the feature for the app so we dropped it. Thanks for your help.

Categories