There are several ways to concatenate two strings together. Show
Use the concatenation operator . (and .=)In PHP
If you want to append a string to another string you would use the
Complex (curly) syntax / double quotes stringsIn PHP variables contained in double quoted strings are interpolated (i.e. their values are "swapped out" for the variable). This means you can place the variables in place of the strings and just put a space in between them. The curly braces make it clear where the variables are.
Note: this will also work without the braces in your case:
You can also concatenate array values inside a string :
Use sprintf() or printf()
HeredocHeredocs can also be used to combine variables into a string.
Use a , with echo()This only works when echoing out content and not assigning to a variable. But you can use a comma to separate a list of expressions for PHP to echo out and use a string with one blank space as one of those expressions: I'm using PHP to create a link depending on a variable. Currently I have this line of code which I have used multiple times and works perfectly. Nội dung chính
The above is all on one line. On the receiving page I have
which retrieves the value from the URL. However I want to pass multiple variables through the link which I've attempted with
And received with
I get this error: " Notice: Undefined index: teacherYes in /Applications/XAMPP/xamppfiles/htdocs/Quests/specificAssignmentPage.php on line 13" I know that it's probably a basic syntax error with separating my statement but I would really appreciate some help. Thanks! I'm passing a variable to another page in a url using sessions like this but it seems that I can't concatenate another variable to the same url and retrieve it in the next page successfully Page 1 session_start(); $event_id = $_SESSION['event_id']; echo $event_id; $url = "http://localhost/main.php?email=" . $email_address . $event_id; Page 2 if (isset($_GET['event_id'])) { $event_id = $_GET['event_id'];} echo $event_id; echo $event_id shows an error Undefined variable on page 2 but if I use just the event_id in the $url like here $url = "http://localhost/main.php?event_id=" . $event_id; That works fine, but I need to be able to use both variables in the url so that page 2 can retrieve get them. 5 Years Ago I passed two parameters in the URL. Now I need to retrieve the parameters log_id and dogID onto the next page to process a form. Im using
Is there another way to get this? Edited 5 Years Ago by happygeek because: moved Recommended Answers
Jump to Post
Jump to Post All 6 Repliescereal 1,524 Nearly a Senior Poster Featured Poster 5 Years AgoHi, can you show the previous step, i.e. the code used to set the session variables? 5 Years Ago Hello there The previous step was this to get to the other page
I tried using this as well but nothing seems to work..
cereal 1,524 Nearly a Senior Poster Featured Poster 5 Years Ago5 Years Ago that still doesnt seem to work Column 'dog_reviewed' cannot be null. My code to insert into the db is : Where im getting the values from the url for the dog (dog_reviewed) thats being reviewed, and the user(id) that is revewing. Am I missing something? Or doing this completly wrong? Im new to php and learning as I go along. cereal 1,524 Nearly a Senior Poster Featured Poster 5 Years Ago
It's difficult to say because I don't see the current code you are using. On top of dogReview.php page, right after
You should be able to see what is sent through the GET request (appending the parameters to the url) and the contents of the current session. If it does not help show the code of this page. 5 Years Ago How about when you get to your page dogReview.php Reply to this topic Be a part of the DaniWeb community We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge. How can I pass two parameters in URL in PHP?$vars = array('email' => $email_address, 'event_id' => $event_id); $querystring = http_build_query($vars); $url = "http://localhost/main.php?" . $querystring; Additionally, if $event_id is in your session, you don't actually need to pass it around in order to access it from different pages. How do I pass multiple variables in URL?Any word after the question mark (?) in a URL is considered to be a parameter which can hold values. The value for the corresponding parameter is given after the symbol "equals" (=). Multiple parameters can be passed through the URL by separating them with multiple "&". How do you pass a href variable in HTML?href”, append the variable to it (Here we have used a variable named “XYZ”). Then we need to append the value to the URL. Now our URL is ready with the variable and its value appended to it. In the example below, we will append a variable named 'XYZ' and its value is 55. How can I get multiple parameters with same name from URL in PHP?Hello readers, Below example will help you to "Get Multiple Parameters with same name from a URL in PHP".. <? php.. $query = explode('&', $_SERVER['QUERY_STRING']);. $params = array();. foreach( $query as $param ). list($name, $value) = explode('=', $param, 2);. $params[urldecode($name)][] = urldecode($value);. |