storing url in db
Moderator: General Moderators
-
maverickman55
- Forum Newbie
- Posts: 15
- Joined: Sat Dec 14, 2002 10:22 pm
storing url in db
hey guys, on my ecard script i have the person choose an image on the index page, that image is then called "$image" and echoed on the card page. when the person submits the rest of there information i.e. recipiant, message, etc, how would i store the image url so when the they go to the unique id page to view their card, the correct image is shown? thanks in advance
well, first you need to make a table:
run that code above in phpmyadmin or what you use to make the table.
then put this code into the page where the user goes after giveing their full info:
when you need to send the id, just call '$linkid'.
now to show it...the user will have to come to your site..and to do that they need a url, so you send it to them in this form:
http://www.yoursite.com/page_name.php?id=$linkid
when they come to that page,use this code:
just make sure you don't have any thing before that code, like a include with some html init....enjoy 
Code: Select all
CREATE TABLE links (
ID int(11) NOT NULL auto_increment,
link text NOT NULL,
in_time int(30) NOT NULL default '0',
PRIMARY KEY (ID)
) TYPE=MyISAM;then put this code into the page where the user goes after giveing their full info:
Code: Select all
<?php
$in_time = time();
$sql = mysql_query("INSERT into links('','$url','$in_time')");
$idlink = mysql_insert_id();
$oldtime = time() - 604800;
$delete_old_ones = mysql_query("delete from links where in_time <='$oldtime'");
//rest of your code here....
?>now to show it...the user will have to come to your site..and to do that they need a url, so you send it to them in this form:
http://www.yoursite.com/page_name.php?id=$linkid
when they come to that page,use this code:
Code: Select all
<?php
$sql = mysql_fetch_array(mysql_query("select url from links where id='$_GET[id]' limit 1");
header("location: $sql[0]");
?>-
maverickman55
- Forum Newbie
- Posts: 15
- Joined: Sat Dec 14, 2002 10:22 pm
what is "in_time" and how does it know what url to store? i'm kinda confused...here is the code i have, maybe u can add your code onto to mine so i can see how its supposed to work. THANKS!
Index page
Form Page
Submit Page
Viewcard Page
Index page
Code: Select all
<html>
<body>
<a href="card.php?image=winter.jpg"><img src="images/winter.jpg"></a>
</body>
</html>Code: Select all
<?
session_start();
session_register("image");
?>
<html>
<head>
<title>PHPpostcard by - WWW Design</title>
<style type="text/css">
</style>
</head>
<body bgcolor="#999999" text="#000000" link="#000000" vlink="#000000" alink="#FFFFFF" >
<div align="center"><br><br><br><br><br>
<table style="border: 1px solid black" style="background: url(images/postcard.jpg)" style="color: #000000" width="660px" height="350px" cellspacing="0" cellpadding="2">
<tr>
<td name="image" width="26%" rowspan="3">
<table name="image" valign="top">
<tr>
<td name="spacer"></td><td valign="top"><img src="<?php echo ("images/".$image);?> "> </td>
</tr>
</table>
</td>
<tr>
<form method="post" action="submit.php">
<td name="information" width="175px"><div align="right"><br>
<input type="text" style="border: 0px solid black" style="font-size: 10" name="recipiant" style="background: transparent" height="10px">
<?escapeshellcmd($recipiant);?>
<br><br>
<input type="text" style="border: 0px solid black" style="font-size: 10" name="sender" style="background: transparent">
<?escapeshellcmd($sender);?>
<br><br>
<input type="text" style="border: 0px solid black" style="font-size: 10" name="email" style="background: transparent">
<?escapeshellcmd($email);?>
</td>
</tr>
<tr>
<td name="from" width="" height="20px" colspan="2" valign="bottom">
<br>
<div align="right"><input type="submit" value="Send!" style="border: 1px solid black" style="font-size: 10">
<input type="reset" value="Clear!" style="border: 1px solid black" style="font-size: 10">
</form>
</td>
</tr>
</table>
</body>
</html>Code: Select all
<?
session_start();
session_destroy();
include ("dbconnect.php");
mysql_select_db("maverick");
$recipiant = $_POSTї'recipiant'];
$sender = $_POSTї'sender'];
$email = $_POSTї'email'];
$image = $_GETї'image'];
function CreateID($length=16){
$Pool = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$Pool .= "1234567890wwwdesign";
for($index = 0; $index < $length; $index++){
$id .= substr($Pool,(rand()%(strlen($Pool))), 1);
}
return($id);
}
$id=CreateID();
$query = "create table information" . "(id varchar(16) NULL, recipiant varchar(255), sender varchar(255), email varchar(255))";
$result = mysql_db_query ("maverick", $query);
$query2 = "insert into information values ('$id','$recipiant','$sender','$email') ";
$result2 = mysql_db_query ("maverick", $query2);
if ($result2){
echo " ";
}
else{
echo mysql_errno().": ".mysql_error()."<BR>";
}
$mailTo = "$email";
$mailSubject = "You an ecard from WWW Design!";
$mailHeader = "From: $sender";
$message = "Hello $recipiant, $sender has sent u an Ecard. You can view this card at the following webpage: ";
$message .= "http://maverick.sifen7.com/card/viewcard.php?id=";
$message .= $id;
mail($mailTo, $mailSubject, $message, $mailHeader) or die (mysql_error());
$query3 = "SELECT * FROM information where id='$id'";
$result = mysql_query($query3);
$row = mysql_fetch_array($result);
echo "Thank you $rowїsender] for sending $rowїrecipiant] a greeting card.<br />";
mysql_close ();
?>Code: Select all
<?
include ("dbconnect.php");
mysql_select_db("maverick") or die(mysql_error());
$id = $_GETї'id'];
$query = "SELECT * FROM information WHERE id = '$id' " or die (mysql_error());
$result = mysql_query($query) or die (mysql_error());
$row = mysql_fetch_array($result) or die (mysql_error());
?>
<html>
<head>
<title>PHPpostcard by - WWW Design</title>
<style type="text/css">
</style>
</head>
<body bgcolor="#999999" text="#000000" link="#000000" vlink="#000000" alink="#FFFFFF" >
<div align="center"><br><br><br><br><br>
<table style="border: 1px solid black" style="background: url(images/postcard.jpg)" style="color: #000000" width="660px" height="350px" cellspacing="0" cellpadding="2">
<tr>
<td name="image" width="26%" rowspan="3">
<table name="image" valign="top">
<tr>
<td name="spacer"></td><td valign="top"><img src="<?php echo ("images/".$image);?> "> </td>
</tr>
</table>
</td>
<tr>
<td name="information" width="175px"><div align="right"><br>
<? echo $rowїrecipiant];?>
<?escapeshellcmd($recipiant);?>
<br><br>
<input type="text" style="border: 0px solid black" style="font-size: 10" name="sender" style="background: transparent">
<?escapeshellcmd($sender);?>
<br><br>
<input type="text" style="border: 0px solid black" style="font-size: 10" name="email" style="background: transparent">
<?escapeshellcmd($email);?>
</td>
</tr>
<tr>
<td name="from" width="" height="20px" colspan="2" valign="bottom">
<br>
</td>
</tr>
</table>
</body>
</html>