Cant get field values with space from mysql using php - php

I am trying to pass variable that containing the values with space through href but I fail to get the expected output with space.
The code I used is:
print " <a href=update.php?id='$id'&name=$name&dob='$dob'&email='$email'>Update Details</a> <br>
Student ID: $id<br> Student Name: $name<br> Date Of Birth: $dob<br> Email ID: $email<br>";
In update.php I could see the link as
localhost/student_portal/update.php?id='abc'&name=Giridharan
and I didn't get the full name and dob and email
My variables with values are as follows:
$id=abc
$name=Giridharan Rengarajan
$dob=1993-07-22
$email=rgiridharan.93#gmail.com
What should I do to get all the four values in update.php?

Since spaces are not legal parts of the query string you have to encode them.
Eg:
Use rawurlencode / rawurldecode
<a href=update.php?id='$id'&name=rawurlencode($name)&dob='$dob'&email='rawurlencode($email)'>Update Details</a>

You can get the variables in update.php by:
<?php
$id = $_GET['id'];
$name = $_GET['name'];
$dob = $_GET['dob'];
$email = $_GET['email'];

For proper creation of url you can use http_build_query.
See examples here http://www.php.net/manual/en/function.http-build-query.php
Create array of your params, put it into this function and to your update script like a string.

Related

how can i append a $name variable inside a $lang variable?

i have a lang file with lots of pre-made statements
the one i'm working one is used as a template to email users
$lang['ADD_STORE_REQUEST_EMAIL_TITLE'] = " New store has been added";
as you guys can probably guessed, the code above is what would be the email title
my question is, how can i put variable in there? say i wanna have the email title as "hello john, new store has been added"
mail(ADMINISTRATOR_EMAIL,$lang['ADD_STORE_REQUEST_EMAIL_TITLE']"From: no-reply#gmail.com");
i tried adding the 'name' variable before and after the $lang, but it wont work. i tried appending it by name+$lang.... but still wont show up
You can do it like this:
$lang['ADD_STORE_REQUEST_EMAIL_TITLE'] = " New store".$yourVar." has been added";
or
$lang['ADD_STORE_REQUEST_EMAIL_TITLE'] = " New store has been added".$yourVar;
You can use the function sprintf to accomplish this.
Also. To concatenate strings in PHP, you need to use . instead of +
Ex:
mail('email#example.com', sprintf('This is a %s day', 'fine'), sprintf('Hello mr. %s', $name);
This will result in an email being sent to email#example.com with the subject "This is a fine day" and body "Hello mr. {some name from the variable"}

Show in the email from which page the form was submitted

I have a html form on every page and I need to be able to show in the receiver email from which page the visitor submitted the form. How can I achieve this in PHP? I have tried using $_SERVER['REQUEST_URI'] whatsoever, but it just simply doesn't output anything. I'm using Wordpress.
<?php
global $post;
$post_slug=$post->post_name;
$name = $_POST['firstname'];
$email = $_POST['email'];
$message="$name.$email";
mail('example#gmail.com', "Hello", "$name \n $email \n $_SERVER['REQUEST_URI']");
echo "works";
?>
Your code is fine except, you should enclose array variables inside strings with curled braces {}:
mail('example#gmail.com', "Hello", "$name \n $email \n {$_SERVER['REQUEST_URI']}");
If you check the official php documentation on: http://php.net/manual/en/language.types.string.php#language.types.string.parsing you can see in section "Complex (curly) syntax":
// Works, quoted keys only work using the curly brace syntax
echo "This works: {$arr['key']}";
you can get the actual url with :
$actual_link = "http(s)://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
You can try something this . Pass the title of your page ( or the permalink ) to a hidden html input and take the values as :
$titlePage = get_the_title($post->ID);
<input type="hidden" value="<?php echo $titlePage; ?>" name="pagetitle">
Then in your email code :
$pagetitle = $_POST['pagetitle'];
Now you have your parameter, use it in your email like you want.

How to output valid html5 with codeigniter

i'm trying to properly validate external url from a codeigniter 3 view.
I have in my db an url like this :
http://www.example.com/content.php?id=test&article=3
and i want to make a link like this one ->
http://www.example.com/content.php?id=test&article=3
I tried this :
<?php
if (isset($c_url_redir)){
$c_url_redir = 'http://www.example.com/content.php?id=test&article=3';
echo anchor(htmlspecialchars($c_url_redir), "go", 'class="pure-button pure-button-primary" target="_blank"');
}
?>
but i have the same url as the first one.
Could you help me?
Try using url_encode() on just the get variables. Personally, I'd have the first part of the URL assigned to a variable then tack on the url_encoded get variables e.g.
$c_url_redir = 'http://www.example.com/content.php';
$get_variables = url_encode('id=test&article=3');
echo anchor($c_url_redir . '?' . $get_variables, "go", 'class="pure-button pure-button-primary" target="_blank"');

Alternative to $_GET["param"] to keep %0A line breaks?

I am sending info from an HTML form through the URL to be used at the destination web page.
One of these bits of info is a user defined message from a textarea, potentially with line breaks. I've encoded the linebreaks as %0A.
I wanted to use $var = $_GET["param"] to retrieve the message and store in a variable, but of course $_GET strips the %0A and replaces with spaces, which is killing the user formatting.
Is there someway I can get this into the variable either with the %0A in tact, or converted to <br>'s.
Thanks for you help.
UPDATE: Here's the code
Example URL:
http://blahblahblah.com/thankyou.php?type=e&gift=1&remail=simon#shokstudio.com&rname=Simon&demail=simon#shokstudio.com&dname=Simon&msg=e.g.%20Dear%20Bob,%20%0A%0AMerry%20Christmas%20and%20a%20Happy%20New%20Year%20to%20you.%20I%20hope%202014%20brings%20you%20much%20joy%20and%20happiness%20to%20you%20and%20your%20loved%20ones.%0A%0ABest%20Wishes,%0A%0ADave%0A%0A%20
PHP processing URL:
<?php
if ( "e" == $_GET["type"]) :
$gift_type = "Ecard";
else :
$gift_type = "PDF";
endif;
$gift_number = $_GET['gift'];
$donor_name = $_POST['dname'];
$donor_email = $_GET['demail'];
$recipient_name = $_POST['rname'];
$recipient_email = $_GET['remail'];
$custom_text = $_POST['msg'];
echo $_POST['msg'];
Use POST instead of GET. This works fine.
form.php
<form method="POST" action="my_form.php">
<input type="text" name="param">
<input type="submit">
</form>
my_form.php
<?php
echo $_POST['param'];
?>
you can either use nl2br or str-replace or preg_replace. But to use POST instead of GET that would be a better and safe solution solution.
Since you are using a web-form with a text-area, i would suggest using the POST method and then using the $_POST (or $_REQUEST) variable instead. All entered data should be in there, with enters and all special characters.

MySQL value embedded within HTML and PHP

I am trying to open a page and send $username (which I got from MySQL) through a URL parameter. The value is not sent to AddPage.php as it is embedded in the PHP/HTML. I think there is something wrong with the syntax but i could not figure it out.
The following is the code of the hyperlink:
<?php
echo"<h2 > Please try to <a href='AddPage.php?id=" . $username . "'>Add</a> again</h2>";
?>
Can someone look at it and tell me where is the problem?
1 - Are you sure $username is populated by the mysql query? Try a var_dump($username) just before your link to see what and better, if the variable is populated.
2 - Is the variable send in the URl?
3 - A typo: there is no space between echo and "
4 - In AddPage.php did you use $_GET['username'] to get the username?
On the side: why do you call you variable user- name when in fact it's an id ?
At first get the value from url parameter like:
<?php $username = $_GET['username']; ?>
<?php
echo '<h2 > Please try to Add again</h2>';
?>
OR
<h2 > Please try to Add again</h2>

Categories