473,549 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Display web page in php on click of submit Button

63 New Member
Hi to all and sundry. I'm Atif a newbie to this forum

I've a question regarding php. if anyone could answer it i would be hononured.
thanx in advance.
---------------------------------------------------------------

I have a table in MYSQL named product.
Columns in product are named as pcode(product code ) and purl (product url).

i have to generate a search code such that,

if i enter the pcode in the search text for the corresponding purl,

the webpage corresponding to that url gets displayed as i click the submit
button.
I tried out my best ,in the end i was able to display the url only and not the web page corresponding to that url.

here is the code i tried:.
-------------------------------------------------------------------------
Productmanage.p hp
-----------------------------
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <title>Product CMS: Search Products</title>
  3. <body>
  4. <h1>Manage Products</h1>
  5.  
  6. <?php
  7.  
  8. include "dbconnect.php";
  9.  
  10. // The basic SELECT statement
  11. $select = 'SELECT DISTINCT pcode,purl ';
  12. $from = ' FROM product';
  13. $where = ' WHERE 1=1 ';
  14. $searchtext = $_POST['searchtext'];
  15.  
  16.     if ($searchtext != '') 
  17.     { // Some search text was specified
  18.     $where .= " AND pcode  LIKE '%$searchtext%'";
  19.     }
  20.  
  21. ?>
  22. <table>
  23. <tr> <th>Product url</th></tr>
  24.  
  25.  
  26. <?php
  27.  
  28. $url = @mysql_query($select . $from . $where);
  29.  
  30.     if (!$url) 
  31.     {
  32.     echo '</table>';
  33.     exit('<p>Error retrieving urls from database!<br />'.
  34.     'Error: ' . mysql_error() . '</p>');
  35.     }
  36.  
  37.     while ($pdurl = mysql_fetch_array($url)) 
  38.     {
  39.     echo "<tr valign='top'>\n";
  40.     $id = $pdurl['pcode'];
  41.     $purl = htmlspecialchars($pdurl['purl']);
  42.     //echo "<td>$id</td>\n";
  43.     echo "<td> <a href='link:$purl'>$purl</a>";
  44.     echo "</tr>\n";
  45.     }
  46. ?>
  47. </table>
  48. <p><a href="productsearch.html">New search</a></p>
  49.  
  50. </body>
  51.  
  52. </html>
  53.  
----------------------------------------------------------------------------------------
Productsearch.h tml
-----------------------------
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <title>Joke CMS:URL Search </title>
  4.  
  5. <body>
  6.  
  7. <h3>Search Product URLs from Product Code</h3>
  8.  
  9. <form action= "productmanage.php" method="post">
  10.  
  11.  
  12. <label>Containing ProductCode: <input type="text" name="searchtext" />
  13.  
  14. </label><br />
  15.  
  16. <input type="submit" value="Search" />
  17.  
  18. </form>
  19.  
----------------------------------------------------------------------------------------

Please help me to sort out this problem as eary as possible, i have to report to boss to the earnest regarding this work.

Thanx.........y ours .........Atif
Sep 25 '07 #1
15 6501
nathj
938 Recognized Expert Contributor
Hi TechnoAtif,

I think you are heading along the right lines, though next time please use the code tags to display your code - it makes it easier to read.

Back to the problem.

I think what you need to do is set the header once you have the location. The process would be:
1) A page with the form on for the user to enter to product code and then click search.
2) The seacrh (submit) button would go to a php page that queries the database based on the $_POST[] data
3) If the record is foudn the set the header
[php]
header("Locatio n:$URL"); // where $URL is a variable containing the FULL url required
[/php]
4) If the record is not found then you need to display some text instead that indicates this problem - possibly returning the user to the search form.

I think the code you have is pretty close it's just a case of the missing step and ensuring the logic is right. I'm sure there are many ways to solve this problem and this is just the way I would tackle it.

Cheers
nathj
Sep 25 '07 #2
TechnoAtif
63 New Member
hi nathj and thanx for such immdiate reply.
your statement upto step 2 is very much clear to me.
How ever in the step 3 u r saying to include a header :

[PHP]header("Locatio n:$URL");[/PHP] // where $URL is a variable containing the FULL url required.

can u plz tell me where to include this tag. i mean the exact location in the productmanage.p hp script.

Thanx
Sep 26 '07 #3
nathj
938 Recognized Expert Contributor
hi nathj and thanx for such immdiate reply.
your statement upto step 2 is very much clear to me.
How ever in the step 3 u r saying to include a header :

[PHP]header("Locatio n:$URL");[/PHP] // where $URL is a variable containing the FULL url required.

can u plz tell me where to include this tag. i mean the exact location in the productmanage.p hp script.

Thanx
Sure thing, the plan is to code the line setting the header immediatley after you have found the URL for the product the user is searching for.

So in the code for the form you would set the action to search.php which would be structured as follows
[php]
// NOTE: this assumes you are using POST as the method on the form

// test the user entered something and search for it (this is your original code)
include "dbconnect.php" ;

// The basic SELECT statement
$select = 'SELECT DISTINCT pcode,purl ';
$from = ' FROM product';
$where = ' WHERE 1=1 ';
$searchtext = $_POST['searchtext'];

if ($searchtext != '')
{ // Some search text was specified
$where .= " AND pcode LIKE '%$searchtext%' ";
}

// execute the query
$url = mysql_query($se lect . $from . $where)

// test the result
if ($url)
{
// retreive the url from the result and set the variable $lcURL
// redirect using the header
header("Locatio n:$lcURL") ;
}
else
{
echo '<p> no product found</p>' ;

[/php]

This is only really psuedo code but it should explain a bit clearer what I was sugessting.

Have a go with this and if you get stuck post back with as much information as possible and the full code set again and I'll take another look for you.

Cheers
nathj
Sep 26 '07 #4
TechnoAtif
63 New Member
hi there . As per your able guidelines i 've edited a little bit of my code. But its now givinh the follwing error:
Parse error: parse error, unexpected T_IF in C:\Apache2\WWW\ localhost\searc h1.php on line 24
Here is the code:



// NOTE: this assumes you are using POST as the method on the form

// test the user entered something and search for it (this is your original code)

<?php
include "dbconnect.php" ;

// The basic SELECT statement
$select = 'SELECT DISTINCT pcode,purl ';
$from = ' FROM product';
$where = ' WHERE 1=1 ';
$searchtext = $_POST['searchtext'];

if ($searchtext != '')
{ // Some search text was specified
$where .= " AND pcode LIKE '%$searchtext%' ";
}

// execute the query
$url = mysql_query($se lect . $from . $where)

// test the result

if ($url)
{
while ($lcURL = mysql_fetch_arr ay($url))
{

$id = $lcURL['pcode'];
$purl = htmlspecialchar s($lcURL['purl']);
echo "<td> <a href='hyperlink :$lcURL'>$lcURL </a>";

}

header("http://localhost:8080/home.html:$URL" ) ;
}
else
{
echo '<p> no product found</p>' ;
}
?>



And sorry bcoz its too time consuming to enter all the codes within tags.
Sep 26 '07 #5
nathj
938 Recognized Expert Contributor
Hi,

It's even more time consuming to read code that is not formatted by the code tags so do please use them. Other people will beless polite and to continually and intentionally not use them is against the rules of the forum

As for the problem you get, I don't know which line is line 24 as there are no code tags and so no line numbers.

I did notice that you use the header() wrong. It needs to be header("Locatio n:$variable)

The word Location is needed that's how the header system knows what to do. If you are using an IDE there may be syntax checker built in that may help you. Alternativley post back using the code tags for php and I'll take another look

Cheers
nathj
Sep 26 '07 #6
TechnoAtif
63 New Member
Sorry for the convenience caused . and if it is so. then i have no qualms in sending the tagged code.it was just due to lack of knowledge of doing so. that's why i send it in crude form. never mind. here is the updated code.

Parse error: parse error, unexpected T_IF in C:\Apache2\WWW\ localhost\searc h1.php on line 20
[PHP]<?php
include "dbconnect.php" ;

// The basic SELECT statement
$select = 'SELECT DISTINCT pcode,purl ';
$from = ' FROM product';
$where = ' WHERE 1=1 ';
$searchtext = $_POST['searchtext'];

if ($searchtext != '')
{ // Some search text was specified
$where .= " AND pcode LIKE '%$searchtext%' ";
}

// execute the query
$url = mysql_query($se lect . $from . $where)

// test the result

if ($url)
{
while ($lcURL = mysql_fetch_arr ay($url))
{

$id = $lcURL['pcode'];
$purl = htmlspecialchar s($lcURL['purl']);
echo "<td> <a href='hyperlink :$lcURL'>$lcURL </a>";

}

header("http://localhost:8080/home.html:$URL" ) ;
}
else
{
echo '<p> no product found</p>' ;
}
?>[/PHP]
.
Sep 26 '07 #7
nathj
938 Recognized Expert Contributor
Hi ,

It would seem that the following line is the problem:
[php]
if ($url)
[/php]
I'm not sure what the trouble with is but lets try something different to test the result:
[php]
if (!$url)
{
echo'<p> no match </p>'
}
else
{
// redirect to the URL for the product
}
[/php]
This is just inverting the logic which should work. Give it a try and let me know, if this fails we may have a problem with the SQL and what, if anything, is being returned.

Cheers
nathj
Sep 26 '07 #8
TechnoAtif
63 New Member
Hi there! I've corrected previous errors and they are gone now .But here is a new
trouble. IT's Saying :


Parse error: parse error, unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Apache2\WWW\ localhost\searc h1.php on line 43
The updataed code is as follows:

[PHP]

<?php


include "dbconnect.php" ;

// The basic SELECT statement
$select = 'SELECT DISTINCT pcode,purl ';
$from = ' FROM product';
$where = ' WHERE 1=1 ';
$searchtext = $_POST['searchtext'];

if ($searchtext != '')
{ // Some search text was specified
$where .= " AND pcode LIKE '%$searchtext%' ";
}
?>
// execute the query

<?php

$url = mysql_query($se lect . $from . $where);

// test the result

if (!$url)

{

exit('<p>Error retrieving urls from database!<br />'.
'Error: ' . mysql_error() . '</p>');

echo '<p> no product found</p>' ;
}



while ($pdurl = mysql_fetch_arr ay($url))

{

$id = $pdurl['pcode'];
$purl = htmlspecialchar s($pdurl['purl']);
header("Locatio n:$pdurl['purl']");

}

?>




[/PHP]

Plz help If u can.
Sep 27 '07 #9
nathj
938 Recognized Expert Contributor
[PHP]

$id = $pdurl['pcode'];
$purl = htmlspecialchar s($pdurl['purl']);
header("Locatio n:$pdurl['purl']");

?>


[/PHP]
Hi,

Change the header line shown above to:
[php]
header("Locatio n:$purl");
[/php]
I think that should solve the problem.

If you get any errors about setting headers after they have already been set work through the code and remove blank lines as they count as output to the browser which sets the headers. That's more of a tip just in case really.

Cheers
nathj
Sep 27 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

13
40645
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div style="display:none"> can be displayed by setting the style attribute to "display:", or hidden with "display:none". This gives the illusion that the person...
10
13423
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group related to checkboxes. Thanks!!!
0
2343
by: dominosly | last post by:
Okay, this is a rather complicated problem, so here is the short of it: I am using a custom designed user control that simply writes out a plain old html submit button to the page. When the page posts back it will randomly (I'm talking a few out of a hundred times) not catch the System.EventHandler on the submit button click. Here are...
5
2134
by: Miguel Dias Moura | last post by:
Hello, i have an ASP.net / VB page with a Script (submitValues) and a Form. 1. The form has 20 input texts and a "Submit" button. 2. The script declares 20 variables. The value of each variable is taken from each of the 20 input texts. 3. When the button "Submit" is click the variable values are sent to an email address using AspNetEmail.
2
3102
by: Benedict Teoh | last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit is performed. How do I force the usercontrol to display the newly assigned date? I don't have this problem if I place the two dropdownlist and the...
4
10026
by: James | last post by:
Hello, I have a RequiredFieldValidator for several textbox controls on a form. Here's an example with the RequiredFieldValidator. EnableClientScript, Enabled, and Visible are set to true for the RequiredFieldValidator. <asp:textbox id="FirstName" MaxLength="25" runat="server"></asp:textbox>
3
10785
by: remya1000 | last post by:
i'm using ASP with MSAccess as database. i have two buttons and two textbox in my page. when i press my first button (First month) i need to display the current month in one textbox and last one months date in another textbox. and while pressing the second button (submit) i need to display the date displayed in the textbox as itself and the...
2
3243
by: wreed06 | last post by:
Hello, I have 2 problems. In my webpage, I have a dropdown list with a button that takes the user to a popup window specific to the option. I am using Firefox 2.0.0.13. I have successfully validated my HTML and CSS code. 1. When I clear cache and refresh my webpage, it takes 3 tries before the popup window displays - I click on the button...
5
1955
by: wreed06 | last post by:
I have 2 problems. In my webpage, I have a dropdown list with a button that takes the user to a popup window specific to the option. I am using Firefox 2.0.0.13. I have successfully validated my HTML and CSS code. 1. When I clear cache and refresh my webpage, it takes 3 tries before the popup window displays - I click on the button once, a...
1
2193
by: ponna | last post by:
u click submit button then display one input box.and then u click another submit button then display the value in previous box.now u click first submit button more than one time dislay more box.second submit button how to display these values.
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7715
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7469
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5087
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1057
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.