Adding PHP parameters to a URL when page loads

Hi All.

I have been really struggling with this for a while! When a URL loads I wish to load with parameters entered & those parameters entered on a page but cannot get my head round it. Any help will be much appretiated…

So when a user navigates to www.test.com/page.php I wish to to actually pull back www.test.com/page.php?term=&submit=Go

Any help will be really really appretiated.

Hi there,

Is post data not of use to you? It means you have a simple url but you still pass the data (as suggested). You will need

<form action="post">

and
[php]<?php
$theterm = trim($_POST[‘term’]);
[/php]

instead of:
[php]<?php
$theterm = trim($_GET[‘term’]);
[/php]

Which is what you use with the form action “get” and urls such as “form.php?term=blah+blah&submit=Submit”

If i’ve completely misunderstood, please let me know!

Yup basically I wish the form to submit on page load & show all results from a SQL query - this works perfect if you click ‘go’ with no data, but want this to show as soon as the page loads!
Where on the page would I put this code??
Cheers for your help

Ok, so do you not actually need anything to have been entered by the user visiting the site?

If it is to be done automatically just run your sql query and print out the results?

How do I get the SQL to run automatically on page load without the user clicking submit?

Here’s a quick, basic example of how to use sql within your page (that runs automatically):

[code]<?php
error_reporting(E_ALL);
mysql_connect(“localhost”,“username”,“password”);
mysql_select_db(“database_name”);
?>

SQL Testing <?php $sql = "SELECT `id`,`otherfield` FROM `table_name`"; $query = mysql_query($sql); while(($row = mysql_fetch_assoc($query)) !== false) { echo "id = '".$row['id']."' and otherfield = '".$row['otherfield']."'"; } ?> [/code]

Hopefully this helps?

Sponsor our Newsletter | Privacy Policy | Terms of Service