Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How to trigger a web page from a mysql table field
Old 05-23-2006, 01:05 PM How to trigger a web page from a mysql table field
Experienced Talker

Posts: 37
Trades: 0
Greetings Forum.

I am trying to get a web page to load into the browser using a php script. This web page is in a table field in a msyql db.

Can anyone tell me if this is possible and if so, how do I achieve this.

The code I am using is...........................
PHP Code:
<?php
include ("../config/config.inc");
// start this field in a session
$s_app_link $row['app_link'];
session_register('$s_app_link');
 
// validate data
// start session and bring in session variables
session_start();
@
$link mysql_connect(SYSTEM,USERNAME,PASSWORD);
if(!
$link)
{
    echo 
"Database seems to be down";
    exit;
}
mysql_select_db(DATABASE) or die( "Unable to select database");
$query "SELECT * FROM booth where app_link = '$s_app_link' ";
$result mysql_query($query);
if(!
$result)
{
     echo 
"Error - Could not get booth information from database.";
     
mysql_close();
    exit;   
}

$row mysql_fetch_object($result);
echo
"
$app_link
 
"
;
?>
app_link is a field in a table called booth. In that field I have www.mywebsite.com.

When a user clicks on the link to this script, is there a way to get www.mywebsite.com. to load into the browser??

Any suggestions any one???
bmalex is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-23-2006, 01:16 PM Re: How to trigger a web page from a mysql table field
AliKat's Avatar
Extreme Talker

Latest Blog Post:
Save the Children
Posts: 176
Location: MS
Trades: 0
You can use

PHP Code:
<?php
header
("Location: $app_link");?>
Just make sure that before you use the header you don't output any text to the screan. If you do even put <html> then you will get an "already sent header" error.
AliKat is offline
Reply With Quote
View Public Profile Visit AliKat's homepage!
 
Old 05-23-2006, 03:37 PM Re: How to trigger a web page from a mysql table field
Experienced Talker

Posts: 37
Trades: 0
Thanks AliKat,
When I use ....................
<?php
header
("Location: $app_link");?>

it loads the root url into the browser and not the url string that is in the app_link field.

Any other suggestions
bmalex is offline
Reply With Quote
View Public Profile
 
Old 05-24-2006, 02:52 AM Re: How to trigger a web page from a mysql table field
Novice Talker

Posts: 6
Trades: 0
try to echo the string that comes from the db and check whether it is really the url you wanna be directed to.
artViper is offline
Reply With Quote
View Public Profile
 
Old 05-24-2006, 09:22 AM Re: How to trigger a web page from a mysql table field
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
Yea just echo it out.

I use XTemplate (Smarty been just too bulky) which builds up my page string bit by bit, adding a picture here and a menu there. Once its completed its simple, just echo it out.

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 05-24-2006, 11:14 AM Re: How to trigger a web page from a mysql table field
Experienced Talker

Posts: 37
Trades: 0
When I echo the string that's in the db, the correct url shows but for some reason................
<?php
header
("Location: $app_link");?>

displays the root website.

Any other suggestions???
bmalex is offline
Reply With Quote
View Public Profile
 
Old 05-24-2006, 04:37 PM Re: How to trigger a web page from a mysql table field
AliKat's Avatar
Extreme Talker

Latest Blog Post:
Save the Children
Posts: 176
Location: MS
Trades: 0
Can you show us what is being echo'd out?

I beleive Location is picky about what works with it.

Here's php.net documentation on the header function

http://us2.php.net/manual/en/function.header.php
AliKat is offline
Reply With Quote
View Public Profile Visit AliKat's homepage!
 
Old 05-24-2006, 05:31 PM Re: How to trigger a web page from a mysql table field
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
In your db query, you have where app_link = '$s_app_link', and then you want to redirect to the field result from app_link, is this nescessary? You could just redirect to $s_app_link since it carries the same value.

But, to make things a little more clear for you, you need redirect to the field result, not the sql object, also need to add http:// if it doesn't exists:

PHP Code:
<?php
  
include ("../config/config.inc");
  
// start this field in a session
  
$s_app_link $row['app_link'];
  
session_register('$s_app_link');
 
  
// validate data
  // start session and bring in session variables
  
session_start();
  @
$link mysql_connect(SYSTEM,USERNAME,PASSWORD);
  if(!
$link)
  {
    echo 
"Database seems to be down";
    exit;
  }
  
mysql_select_db(DATABASE) or die( "Unable to select database");
  
$query "SELECT app_link FROM booth WHERE app_link = '$s_app_link' ";
  
$result mysql_query($query);
  if(!
$result)
  {
    echo 
"Error - Could not get booth information from database.";
    
mysql_close();
    exit;   
  }
  
$row mysql_fetch_object($result);
  
  if(
$row['app_link'] != '') {
  
    
header('Location: ' strstr($row['app_link'], 'http://') ? $row['app_link'] : 'http://' $row['app_link'] );
  }
?>
PS - In your above first example, $app_link was never defined so thats why it was redirecting to the root.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.

Last edited by mgraphic; 05-24-2006 at 05:39 PM..
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 05-25-2006, 10:59 AM Re: How to trigger a web page from a mysql table field
Experienced Talker

Posts: 37
Trades: 0
To mgraphic,
After modifying the code and following your suggestion, I am now getting a blank page with no error messages. Do you have any idea as to what I am doing wrong here??
Code:
<?php
  include ("../config/config.inc");
  // start this field in a session
  $s_app_link = $row['app_link'];
  session_register('$s_app_link');
 
  // validate data
  // start session and bring in session variables
  session_start();
  @$link = mysql_connect(SYSTEM,USERNAME,PASSWORD);
  if(!$link)
  {
    echo "Database seems to be down";
    exit;
  }
  mysql_select_db(DATABASE) or die( "Unable to select database");
  $query = "SELECT app_link FROM booth WHERE app_link = '$s_app_link' ";
  $result = mysql_query($query);
  if(!$result)
  {
    echo "Error - Could not get booth information from database.";
    mysql_close();
    exit;   
  }
  $row = mysql_fetch_object($result);
  
  if($row['app_link'] != '') {
  
    header('Location: ' . strstr($row['app_link'], 'http://') ? $row['app_link'] : 'http://' . $row['app_link'] );
  }
?>
bmalex is offline
Reply With Quote
View Public Profile
 
Old 05-25-2006, 12:47 PM Re: How to trigger a web page from a mysql table field
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
You need to confirm if the sql result is returning what you are needing. To test, comment out the header() to avoid execution by placing // before it. Then you should use the line echo $row['app_link']; to view the row result.

If its not returning the desired result, you have found your problem.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 05-25-2006, 02:09 PM Re: How to trigger a web page from a mysql table field
Experienced Talker

Posts: 37
Trades: 0
To mgraphic,

I can't figure this one out. Even when I echo $app_link I still get a blank page. I checked the db and I know that the url string is in that table field. Is there anything esle that you could tell me that would help me fix this ???
bmalex is offline
Reply With Quote
View Public Profile
 
Old 05-25-2006, 02:22 PM Re: How to trigger a web page from a mysql table field
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Remember, $app_link is an undefined varible which will return nothing (except a warning). If you want to assign it, write $app_link = $row['app_link']; and that will assign it.

If no result still, print the array values to the screen using print_r($row);
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 05-25-2006, 03:15 PM Re: How to trigger a web page from a mysql table field
Experienced Talker

Posts: 37
Trades: 0
To mgraphic,
Ok, now the echo is working........................
I have
Code:
<?php
include ("../config/config.inc");
// start session and bring in session variables
session_start();
// forward to jobseeker menu page if the session is not valid
if(!isset($s_email))
{
        header("Location:jobseeker_menu.php");     
        exit();
}

@$link = mysql_connect(SYSTEM,USERNAME,PASSWORD);
mysql_select_db(DATABASE) or die( "Unable to select database");
$query = "SELECT app_link FROM booth ";
$result = mysql_query($query);
if(!$result)
{
echo mysql_error().'<br>';
   echo "Error - Could not get booth information from database.";
   mysql_close();
   exit;   
}
$app_link = $row['app_link'];
$row = mysql_fetch_object($result);
echo"
$row->app_link
"
?>
I did this just to see if I could get the script to echo the url string and it does. Now with this code, how can I get $row->app_link to parse that url string???
bmalex is offline
Reply With Quote
View Public Profile
 
Old 05-26-2006, 12:06 PM Re: How to trigger a web page from a mysql table field
Experienced Talker

Posts: 37
Trades: 0
To mgraphic,

Here is what I have now........................
Code:
<?php
  include ("../config/config.inc");
  // start this field in a session
  //$s_app_link = $row['app_link'];
  //session_register('$s_app_link');
 
  // validate data
  // start session and bring in session variables
  session_start();
  @$link = mysql_connect(SYSTEM,USERNAME,PASSWORD);
  if(!$link)
  {
    echo "Database seems to be down";
    exit;
  }
  mysql_select_db(DATABASE) or die( "Unable to select database");
  $query = "SELECT app_link FROM booth  ";
  $result = mysql_query($query);
  if(!$result)
  {
    echo "Error - Could not get booth information from database.";
    mysql_close();
    exit;   
  }
  $app_link = $row['app_link']; 
  $row = mysql_fetch_object($result);
echo"
$row->app_link";
  
?>
The result being echoed is........ http://www.legalcareerfair.com/register.htm and that is exactly what is in the table field in the db.

I can't figure out why your suggested code will not load this url into the browser???
bmalex is offline
Reply With Quote
View Public Profile
 
Old 05-26-2006, 12:40 PM Re: How to trigger a web page from a mysql table field
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
PHP Code:
header('Location: ' $row->app_link); 
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 05-26-2006, 02:03 PM Re: How to trigger a web page from a mysql table field
Experienced Talker

Posts: 37
Trades: 0
To mgraphic,

That got it!!! Thanks for your help.
bmalex is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to trigger a web page from a mysql table field
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.56652 seconds with 12 queries