storing url in db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
maverickman55
Forum Newbie
Posts: 15
Joined: Sat Dec 14, 2002 10:22 pm

storing url in db

Post 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
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

function

Post 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...
maverickman55
Forum Newbie
Posts: 15
Joined: Sat Dec 14, 2002 10:22 pm

Post by maverickman55 »

how would i do that?
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post 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 :)
maverickman55
Forum Newbie
Posts: 15
Joined: Sat Dec 14, 2002 10:22 pm

Post 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&#1111;'recipiant'];
$sender = $_POST&#1111;'sender'];
$email = $_POST&#1111;'email'];
$image = $_GET&#1111;'image'];
function CreateID($length=16)&#123;
$Pool = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$Pool .= "1234567890wwwdesign";
for($index = 0; $index < $length; $index++)&#123;
$id .= substr($Pool,(rand()%(strlen($Pool))), 1);
&#125;
return($id);
&#125;
$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)&#123;
    echo " ";
  &#125;
  else&#123;
    echo mysql_errno().": ".mysql_error()."<BR>";
  &#125;
$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&#1111;sender] for sending $row&#1111;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&#1111;'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&#1111;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>
Post Reply