Page 1 of 1
storing url in db
Posted: Wed Dec 18, 2002 10:59 am
by maverickman55
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
function
Posted: Wed Dec 18, 2002 11:32 am
by AVATAr
you can make a function called ShowImage() in the page that receives de user.
this funcitons uses de unique id to search de DB and retreive the image...
Posted: Wed Dec 18, 2002 2:06 pm
by maverickman55
how would i do that?
Posted: Wed Dec 18, 2002 3:51 pm
by qads
well, first you need to make a table:
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;
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:
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....
?>
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:
Code: Select all
<?php
$sql = mysql_fetch_array(mysql_query("select url from links where id='$_GET[id]' limit 1");
header("location: $sql[0]");
?>
just make sure you don't have any thing before that code, like a include with some html init....enjoy

Posted: Wed Dec 18, 2002 8:14 pm
by maverickman55
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
Code: Select all
<html>
<body>
<a href="card.php?image=winter.jpg"><img src="images/winter.jpg"></a>
</body>
</html>
Form Page
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>
Submit Page
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 ();
?>
Viewcard Page
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>