You are here: Re: redirect.php?redirID=1 « All PHP « IT news, forums, messages
Re: redirect.php?redirID=1

Posted by J.O. Aho on 12/18/06 11:20

David PurpleBerry ASP PRO wrote:

> Parse error: syntax error, unexpected T_BREAK in
> /home/matemati/public_html/redirect.php on line 25
> The problem in the message containing the error is solved.

There was only a ?> tag missing from the code and it's just 17 lines long, so
I do not know what may have been fault in your code.


> But how do I add url's?

This depends on how you want to do, if you want to use the static way (based
on the code I posted in my previous post in this thread), then just add into
your switch statement

case X:
header("Location: http://where.ever.you.want.com");
break;

Where X is the value provided in the redirID variable.


If you want to use a database, then you need to query the data from it

We assume you have the following table:

URLs(redirID int, pageName varchar(30), address varchar(255))

CREATE TABLE URLs(
redirID INT NOT NULL AUTO_INCREMENT,
pageName varchar(30),
address varchar(255) NOT NULL
);

Then you can insert the URL with

INSERT INTO URLs(pageName,address)
VALUES('MyHomePage','http://www.example.net/~me');

And you get the url with

SELECT address FROM URLs WHERE redirID='1';

Then the redirect.php file will look a bit different

--- redirect.php ---
<?PHP
/* We include a file where you have done the connection to the
sql server and selected the right database to use, we assume
you are using MySQL, as it's one of the most common and fastest
sql-databases to use
*/
include('database_connect.php');
$query="SELECT address FROM URLs WHERE redirID='{$_REQUEST['redirID']}'";
$res=mysql_query($query);
if(mysql_num_rows($res)) {
/* There was a such redirID in the table */
$row=mysql_fetch_array($res);
header("Location: {$row['0']}");
exit;
} else {
/* Someone tried to use a redirID that isn't in the table */
header("Location: http://www.example.com");
exit;
}
/* in case something gone really wrong */
echo "Ops, we didn't get redirected!!!";
?>
--- eof ---


--- inserturl.html ---
<form action="inserturl.php">
PageName:<input type="text" name="pn"><br>
URL:<input type="text" name="u"><br>
<input type="submit" name="Submit">
</form>
--- eof ---

--- inserturl.php ---
<?PHP
/* We include a file where you have done the connection to the
sql server and selected the right database to use, we assume
you are using MySQL, as it's one of the most common and fastest
sql-databases to use
*/
include('database_connect.php');
$query="INSERT INTO URLs(pageName,address)
VALUES('{$_REQUEST['pn']}','{$_REQUEST['u']}')";
mysql_query($query);
echo "Added the URL {$_REQUEST['u']} to the table";
?>
--- eof ---

Take note that these small examples don't take care of value checking or error
checking of the use of database, you have to do that yourself.

Good pages to read:
http://www.php.net/manual/en/function.mysql-connect.php
http://www.php.net/manual/en/function.mysql-select-db.php
http://www.php.net/manual/en/function.mysql-query.php
http://www.php.net/manual/en/function.mysql-num-rows.php
http://www.php.net/manual/en/function.mysql-fetch-array.php
http://www.php.net/manual/en/function.header.php
http://www.php.net/manual/en/control-structures.switch.php
http://www.php.net/manual/en/function.include.php

--

//Aho

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация