Passing a user-entered input value to another php page - php

I have an input box in index.php which takes some user input and queries a database using that input field as an attribute. This input is stored in $arrInput[0].
I also have a link to inspect.php which, when clicked, takes me to inspect.php but I need to pass $resultArr[0] to inspect.php so that I can use that variable to continue doing other things within inspect.php. How can I achieve this? \
Currently this is what I have:
/* inspect.php */
// Create a table with some rows. Then create this
// column which has the inspect link
echo "<td> <a href='inspect.php?id=<?php echo $resultArr[0]; ?>'>Inspect</a>
</td>";
...
But I don't know how to access $resultArr[0] within inspect.php. I was told $_GET[] would help, but I'm not sure how and googling the subject hasn't been much help.
Can anyone please help?
Thank you

echo "<td><a href='inspect.php?id=".$resultArr[0]."'>Inspect</a></td>";
I think you are using wrong syntax. Please check above code. You can the access 'id' key inside $_GET.

Not that hard. use $_GET['id'].

Related

Is it possible to add GET statements to a URL when submitting a form to self?

Is it possible to have a link submit to self with GET variables in it?
<a href='#?id=1234&c=2' data-toggle='modal' data-target='#mymodal'></a>
Then when clicked the URL would look like this -
example.com/test.php?msg=hello#?id=1234&c=2
But it doesn't work / PHP doesn't see any of the variables after the #.
I have the following code on the same page (for testing) -
echo $_GET['id'];
And I want it to echo 1234
Is there another way to do this?
Thanks!
If you want the query params you should put them before "#" and not after. When You put them after it, then your php script "won't see" them. Check out this answer on superuser for more.
Also your url example "example.com/test.php?msg=hello#?id=1234&c=2" has 2 "?" in it and it should not.

Session variable passing

I've got a php script which builds a html table via echoing data, But i want to add a link onto one of the values and pass that value to the next page.
<td><a href='redirect.php'><?php $_SESSION['WR'] = $row['WorkOrdRef'];echo $row['WorkOrdRef'];?></a></td>
is the line in question but this will only pass the last value added to the table.
Oh, it doesnt work like this. the php code gets executed no matter if you click the link.
I guess the easiest way to do this is to pass it as a get parameter.
html page:
<?=$cellContent?>
redirect.php:
$clickedcell = $_GET['clickedcell']
now the $clickedcell will have the data from the previous page about what cell did the user click.
If you want to use session for some reason, you still have to pass it with GET or POST and store it after the user clicks.
hopefully this is understandable and good luck with your project.
you can change the session by get method also it is possible building by javascript
in the same page add this
if(isset($_GET["clicked"])){
$_SESSION['WR'] = $row['WorkOrdRef'];
$redirect'<META HTTP-EQUIV="REFRESH" CONTENT="0;URL='.$adres.'/"> ';
return $redirect;
}
and then change your url
<td><?php echo $row['WorkOrdRef'];?></td>

passing values from radiobutton?

I have a radiobutton list in yii php,but I don't know how to access the value from this it doesn't contain any name or identity
<?php
echo $form->radioButtonList($model,'priority',
array('C'=>'CRITICAL','H'=>'HIGH','L'=>'LOW')
array('separator'=>''));
?>
Please help me to sort out this. thanks
you need to do this to see the value
<?php echo $form->error($model, 'priority'); ?>
For your help
When you use the form builder in Yii it sets the names and ids in a certain way. Lets say your $model is an instance of User, in this case your html name attribute would be User[priority] and can be accessed as $_POST['User']['priority']. The html id attribute doesn't use arrays so it is User_priority. So one of the radio buttons would look like this:
<input type='radio' name='User[priority]' id='User_priority' value='C'> CRITICAL
You can always look at the html source code generated to see this.

Passing data from an echoed php

I am currently trying to pass data from my server to my main page. I currently have my php echoing for each returned result:
while($row = mysql_fetch_array($result))
{
echo "<img class='s' id=" . $row['id'] . " src=QR/" . $row['src'] ".png>";
}
when i tried adding a field, num, after id:
<img class='s' id=(rowid) num=".$row['num']." .......
I get undefined when i use
alert(this.num)
but
alert(this.id)
works. How can I pass the num value too?
EDIT:
Hey Everyone, thanks for you help, I have included a jsfiddle on how i solved this problem.
http://jsfiddle.net/3yzcx/4/
I had to use jQuery and used .attr() to define my own attribute called num and called that out.
Very simple. id is a valid property for the img tag. num is not. You can't assign arbitrary properties to a tag and expect it to work.
If you want to pass your PHP data to javascript, using a hidden form element or even more simply something like this:
<?php
echo '<script type="text/javascript">';
echo 'var num = ' . $num . ';';
echo '</script>';
?>
Of course I know you're in a loop, this is just an example. You could easily make it an array or something.
Adding properties doesn't work. You'll want to add an <input type=hidden value='num'> or something inside the <div> where num is your number data. You'll need to make the input field addressable by giving it an ID as well:
echo("<input type=hidden id=\"$row[id]-num\" value='num'>");
Also, I see a closing div tag but no opening tag. You'll want to fix that!
Technically you are not supposed to assign custom attributes. Jcolebrand's original post is worth an upvote due to the discussion about the data prefix. However, even though it is technically not correct, you should be able to get the value with the getAttribute() function.
this.getAttribute("num");
That will work in Firefox, but no guarantees in other browsers.
I've not tried this outside of jQuery, but within that framework you would use
alert(this.attr("num"));
to retrieve non-standard attributes. May work with plain javascript as well, but I've not tried it.

Submitting GET data with no input field?

I've never really thought about this, but it helps with some security of something I'm currently working on. Is it possible to submit GET data without an actual input field, and instead just getting it from the URL?
If so, how would I go about doing this? It kind of makes sense that it should be possible, but at the same time it makes no sense at all.
Perhaps I've been awake too long and need some rest. But I'd like to finish this project a bit more first, so any help you can offer would be appreciated. Thanks
Yes. If you add some query-string to yourl url, you can obtain that in php using $_GET without form submitting.
Going to this URL adress http://yoururl/test.php?foo=bar cause echoing foo (if there will be no foo query string, you'll get warning).
# test.php
echo $_GET['foo'] # => bar
Is this what you mean?
Link
// page.php
echo $_GET['type']; // foobar
This is what I understand of your question:
You have a <form method="get" action="foo.php">-like tag on your page
You have a series of <input type="text" name="bar"/> in your page
You want to pass additional GET parameters that are not based on an input from the form
If so, it is possible, but I hardly see how it could help with security. Input from a client cannot be trusted, so even if you hardcode the GET value, you have to check it serverside against SQL injection, HTML injection/XSS, and whatnot.
You have two ways:
Use a hidden input: <input type="hidden" name="myHiddenGetValue" value="foobar"/>
Add the GET parameter to the form action: <form method="get" action="foo.php?myHardcodedGetValue=foobar">
If what you meant is that you want to have a GET request without a form, you just need to pass all the GET parameters to the href of a link:
Click here!
Yes it's possible. Just append the GET data to the link.
For example:
<a href="main.htm?testGet=1&pageNo=54>Test</a>
You can also use Javascript to build the url.
If you happen to be using jQuery and want to build the GET data dynamically you can do this:
var getParams = { testGet:1, pageNo:54 };
$(".myLink").attr("href", url + "?" + $.param(getParams));

Categories