Forum Moderators: coopster
A word in advance, i'm very sorry if this post is in the wrong topic. This is because i'm not sure if this is a html thing or php.
I have a question regarding id's in links. This is my situation.
I'm trying to forward letters from one file to another, for example:
letter.php contains a letter with php codings. Because of the different content and people i want to send a letter i need it to be displayed in case of errors. So when i click a link it needs to be sent to display.php.
My question is how to do this. Is this done in PHP or HTML?
Thanks in advance.
<?php
$codings = "whatever_the_codings_are";
echo '<a href="display.php?codings='.$codings.'>Link</a>
?>
display.php:
<?
$codings = $_GET['codings'];
echo $codings;
?>
Basically you're sending the variable in the URL and then pulling it out of the URL.
If you want the information to be hidden you can use POST instead and the html form tag.
However, i have one question. Isn't $_POST safer then $_GET? PHP scripting is one thing for me but security another. I read some tutorial about using POST and GET and it is stating that using POST is safer.
When accessing a database with these variables you will want to clear the variable of any bad characters no matter what method you use. Look up PHP functions stripslashes() and mysql_real_escape_string() for safe database queries.
I'm pleased to tell that it works, however i'm getting no letter. Maybe this helps a little:
<?php
//rootdir
$rootdir="../";//date
$date=date("d M Y");
//connection
include ($rootdir . "system/connect.inc.php");
$query="SELECT * FROM pdata";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close($db);
$i=0;
while ($i < $num) {
$name=mysql_result($result,$i,"name");
$address=mysql_result($result,$i,"address");
$zip=mysql_result($result,$i,"zip");
$place=mysql_result($result,$i,"place");
$mob=mysql_result($result,$i,"mob");
$i++;
}
?>
This code is used to extract information from the database. I already wrote the letter and fill in the places with the information from the database.
<table border="0" width="100%" height="100%" cellspacing="0" cellpadding="10">
<tr>
<td style="text-align: justify;" valign="top" align="center">
<?php echo $name?><br>
<?php echo $address?><br>
<?php echo $zip?> <?php echo $place ?><br>
<br>
<br>
<?php echo $place ?>, <?php echo $date ?><br>
<br>
<br>
Some text
<br>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="120">
Name:
</td>
<td width="120">
<?php echo $name ?>
</td>
</tr>
<tr>
<td width="120">
Address:
</td>
<td width="120">
<?php echo $adres ?>
</td>
</tr>
<tr>
<td width="120">
Zip:
</td>
<td width="120">
<?php echo $zip ?>
</td>
</tr>
<tr>
<td width="120">
Place:
</td>
<td width="120">
<?php echo $plaats ?>
</td>
</tr>
<tr>
<td width="120">
phonenumber:
</td>
<td width="120">
<?php echo $mob ?>
</td>
</tr>
</table>
<br>
Some text
<br>
<br>
<br>
<br>
<?php echo $name ?>
<input type="submit" name="submit" value="Check">
</form>
</td>
</tr>
</table>
This code is used to create the letter and "post" it to the next file so i can check on errors.
The link i need is to check the letter and if everything is correct i want to be able to print it from my printer.
Example:
letter.php
<FORM name="crew" ACTION="display.php" METHOD="POST">
<input type="text" size="10" name="name" value="<?php echo $name; ?>">
<input type="text" size="1o" name="address" value="<?php echo $address; ?>">
<input type="submit" name="submit" value="Check">
</form>
display.php
<?
$name = $_POST['name'];
$address = $_POST['address'];
echo "Name:".$name;
echo "Address:".$address;
?>
From this example you should be able to do the rest of it.