Turn a info into a URL
Moderator: General Moderators
Turn a info into a URL
i am a new newbie so dont get upset with my naive questions..... i want to turn the info added by the users into a URL. Since i dont know what this "thing" would be called..can someone teel me what it is called and are there any snippets for them
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Do you mean adding input from a form to the query string?
http://www.something.com/yourpage.php?f ... itted_data
If that's what you're asking, just change make this your form opening tage:
http://www.something.com/yourpage.php?f ... itted_data
If that's what you're asking, just change make this your form opening tage:
Code: Select all
<form method="get" action="blabla">Code: Select all
<form action="test.php" method="get">
<input type="text" name="firstname" value="" />
<input type="text" name="lastname" value="" />
</form>Code: Select all
<?php
$firstname = $_GET['firstname'];
$lastname = $_GET['lastname'];
echo "Your name is $firstname, $lastname";
?>From phpbb code, I may have modified it slightly...
Code: Select all
function MakeClickable($String) {
$String = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $String);
$String = ' ' . $String;
$String = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $String);
$String = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $String);
$String = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $String);
$String = substr($String, 1);
return($String);
}I have 2 files---index.php(which fetches and outputs the queries) and insert.php(where users enter the links). Where am i supposed to enter that function---my best bet isindex.php.
Index.php
Insert.php
Index.php
Code: Select all
<html>
<head><title>Cool Links</title>
</head>
<body>
<?php
$link=mysql_connect("localhost", "root", "");
$db=mysql_select_db("chetan_db", $link);
?>
<table width="100%" align="center" border="1" cellspacing="0" cellpadding="0" style="border-collapse:collapse"
bordercolor="#808080">"
<tr>
<td width="4%" align="center"><b><font color="#FFB340">Id</font></b></td>
<td width="36%" align="center"><b><font color="#FFB340">URL</font></b></td
<td width="60%" align="center"><b><font color="#FFB340">Description</font></b></td>
</tr>
<?php
$sql = "select * from link";
$query = mysql_query($sql);
while($row=mysql_fetch_array($query))
{
?>
<tr>
<td align="center"><font color="#EBEBEB" size="2.5"><?=$row[0]?></font></td>
<td align="center"><font color="#EBEBEB" size="2.5"><?=$row[1]?></font></td>
<td align="left"><font color="#EBEBEB" size="2.5"><?=$row[2]?></font></td>
</tr>
<?php
}
?>
</table>
</body>
</html>Code: Select all
<html>
<head><title>Cool links</title>
</head>
<body bgcolor="#0A5C8E" link="#EBEBEB" vlink="#EBEBEB" alink="#FFB340">
<?php
$link=mysql_connect("localhost", "root", "");
$db=mysql_select_db("chetan_db", $link);
?>
<?php
$link_id = 0;
$link_name = '';
$link_desc = '';
if (isset($_POST['submit']))
{
if ( isset($_POST['id']) && !empty($_POST['id']) )
{
$link_id = $_POST['id'];
}
if ( isset($_POST['name']) && !empty($_POST['name']) )
{
$link_name = $_POST['name'];
}
if ( isset($_POST['desc']) && !empty($_POST['desc']) )
{
$link_desc = $_POST['desc'];
}
$sql = "insert into link values ('', '$link_name', '$link_desc')";
$query = mysql_query($sql) or die("Could not query the table: " . mysql_error());
}
?>
<form action="insert.php" method="post">
<table width="100%" align="center" border="1" cellspacing="0" cellpadding="0" style="border-collapse:collapse" bordercolor="#808080">
<tr>
<td width="10%" align="center"><font color="#FFB340" size="2.5">URL</font></td>
<td width="90%"><input type="text" name="name" value="" size="25"></td>
</tr>
<td width="10%" align="center"><font color="#FFB340" size="2.5">Description</font></td>
<td width="90%"><input type="description" name="desc" value="" size="65"></td>
</tr>
</table>
<br>
<div align="center"><input type="submit" name="submit" value="Submit"></div>
</form>
<br>
<div align="center"><a href="index.php"><font color="#FFB340" size="2.5">Back to Link</font></a> | <a href="http://127.0.0.1"><font color="#FFB340" size="2.5">Back to Forum</a>
</div>
</body>
</html>Index.php
Code: Select all
<html>
<head><title>Cool Links</title>
</head>
<body>
<?php
function MakeClickable($String) {
$String = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $String);
$String = ' ' . $String;
$String = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $String);
$String = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $String);
$String = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $String);
$String = substr($String, 1);
return($String);
}
$link=mysql_connect("localhost", "root", "");
$db=mysql_select_db("chetan_db", $link);
?>
<table width="100%" align="center" border="1" cellspacing="0" cellpadding="0" style="border-collapse:collapse"
bordercolor="#808080">"
<tr>
<td width="4%" align="center"><b><font color="#FFB340">Id</font></b></td>
<td width="36%" align="center"><b><font color="#FFB340">URL</font></b></td
<td width="60%" align="center"><b><font color="#FFB340">Description</font></b></td>
</tr>
<?php
$sql = "select * from link";
$query = mysql_query($sql);
while($row=mysql_fetch_array($query))
{
?>
<tr>
<td align="center"><font color="#EBEBEB" size="2.5"><?php echo MakeClickable($row[0]); ?></font></td>
<td align="center"><font color="#EBEBEB" size="2.5"><?php echo MakeClickable($row[1]); ?></font></td>
<td align="left"><font color="#EBEBEB" size="2.5"><?php echo MakeClickable($row[2]); ?></font></td>
</tr>
<?php
}
?>
</table>
</body>
</html>What is your database table structure? For example if you have an autoincrement field you could do..
which would put the last posted link first.
Code: Select all
$sql = "select * from link order by `id` desc";