0

i am retrieving data form database using a search query.

PHP code (which I'm using in search query to display search results)

echo "<span style='background-color= #FFFF00'>$query</span><br>";
$count=$dbo->prepare($query);
$count->execute();
$no=$count->rowCount();
if($no > 0 ){echo " <span>No of records = ".$no."</span>"; 
echo "<table><tr><th>PHONE NUMBER</th><th>OWNER NAME</th></tr>";
foreach ($dbo->query($query) as $row){
echo "<tr><td>$row[ROLLNO]</td><td>$row[CNAME]</td></tr>";
}
echo "</table>";

i want to do like this,

when a user clicks on a phone number, it should redirect to a new page and in that new page, my input box should be filled with this phone number and should be submitted.

Input Box Code (which I'm using in page 2)

<form name="phone_number_form" id="phone_number_form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onsubmit="return vali()" >
<input type="text" name="number" id="number" />
<input type="submit" name="submit" value="Submit" />
</form>
  • So whats your question? – Chris Moutray Mar 29 '13 at 17:52
  • when a user clicks on a phone number, it should redirect to a new page and in that new page, my input box should be filled with this phone number and should be submitted. –  Mar 29 '13 at 17:55
  • Please provide code that you have tried - what is your attempted context/code that does not presently provide the functionality you desire? - This site provides more "help" with code that you have attempted than it does "provide free code" from a description. – Mark Schultheiss Mar 29 '13 at 17:59
  • sorry mark, its just my requirement. but i didn't know php well. and i didn't have any code to do this functionality :( –  Mar 29 '13 at 18:03

1 Answers1

0

Looking at w3schools PHP has a $_POST variable which is used to collect values from a form sent with method="post". There's also $_GET and $_REQUEST which seems to merge both post and get data. http://www.w3schools.com/php/php_post.asp

There are a couple of options like making a request (get) from your first page or post the data from your first page.

REQUEST Method

Heres how I think the request way to do it would work

PAGE 1

Amend the foreach that renders the table row to include an hyperlink to your second page

foreach ($dbo->query($query) as $row){
    echo "<tr><td><a href="page2.php?phoneno=$row[ROLLNO]">$row[ROLLNO]</a></td><td>$row[CNAME]</td></tr>";
}

PAGE 2

Amend the textbox to be populated with the phone number from the request variable

<input type="text" name="number" id="number" value="<?php echo $_REQUEST["phoneno"]; ?>" />

POST Method

In your first page using javascript when the user clicks the phone number set a hidden field and submit the form to the second page. Again you should be able to read the hidden fields value from the $_REQUEST variable

Chris Moutray
  • 18,029
  • 7
  • 45
  • 66
  • You should pass variables in $_SESSION instead of the URL where the user can alter them – wilco Mar 29 '13 at 18:35
  • "I'd suggest using $_POST and $_GET explicitly. Using $_REQUEST should be unecessary with proper site design anyway, and it comes with some downsides like leaving you open to easier CSRF/XSS attacks and other sillyness that comes from storing data in the URL." - http://stackoverflow.com/questions/1924939/php-request-vs-get-and-post – wilco Mar 29 '13 at 18:38
  • @wilco if PHP is anything like ASP.Net I wouldn't like to rely on the session variable too much when IIS bounces you loose everything - is this the same with PHP? – Chris Moutray Mar 29 '13 at 18:44