Jump to content

Pass variable value to another script?


rocky48
Go to solution Solved by rocky48,

Recommended Posts

I am trying to pass a value obtained by a php script that queries my database.

 

The database is to choose a greeting verse from the database using a tick box to choose:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- Generated by Avanquest Technology v:8.0. For information please visit: http://www.avanquestusa.com/ -->
<html lang="en">
<head>
<title> CVerses » Page 1 of 1 </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css;">
<link rel="stylesheet" href="1066mk2_g.css" type="text/css" media="screen,projection,print">	<!--// Document Style //-->
<link rel="stylesheet" href="VerseIDinput_p.css" type="text/css" media="screen,projection,print">	<!--// Page Style //-->
<script src="cverses_g.js" type="text/javascript"></script>		<!--// Document Script //-->
</head>


<body BGCOLOR="#00ff66">

<span id="e11"></span>
<span id="e12"></span>
<span id="e13"></span>
<span id="e14"></span>
<span id="e15"></span>
<span id="e16"></span>
<div id="e3" class="navigation">
	<a id="a3" class="navigation" href="index.html" target="Vframe5>index">
	Home</a>
</div>
<div id="e4" class="navigation">
	<a id="a4" class="navigation" href="1066mk2_002.htm" target="Vframe5>1066mk2_002">
	Links</a>
</div>
<div id="e5" class="navigation">
	<a id="a5" class="navigation" href="1066mk2_003.htm" target="Vframe5>1066mk2_003">
	Techniques</a>
</div>
<div id="e6" class="navigation">
	<a id="a16" class="navigation" href="topiclist_frame.html" target="Vframe5>topiclist_frame">
	Forum</a>
</div>
<div id="e7" class="navigation">
	<a id="a7" class="navigation" href="1066mk2_004.htm" target="Vframe5>1066mk2_004">
	Contact Us</a>
</div>
<div id="e8" class="navigation">
	<a id="a8" class="navigation" href="1066mk2_006.htm" target="Vframe5>1066mk2_006">
	Gallery</a>
</div>


<div id="e30">
<p>
</br>
You can filter the database, by checking the check box and clicking the submit button, to list all greetings of the same type of Event.</br>
</br>
</br>
Only check ONE box!
</div>	


<div id="e31">
<form action="showType.php" method="post">
  <input type="checkbox" name="Event_Type" value="1" /> Birthday<br />
  <input type="checkbox" name="Event_Type" value="2" /> Christmas <br />
  <input type="checkbox" name="Event_Type" value="3" /> Friends <br />
  <input type="checkbox" name="Event_Type" value="4" /> Wedding <br />
  <input type="checkbox" name="Event_Type" value="5" /> Anniversary <br />
  <input type="checkbox" name="Event_Type" value="6" /> Retirement <br /> 
  <input type="checkbox" name="Event_Type" value="7" /> New Baby <br />
  <input type="checkbox" name="Event_Type" value="8" /> New Job <br />
  <input type="checkbox" name="Event_Type" value="9" /> Get Well <br />
  <input type="checkbox" name="Event_Type" value="10" /> Valentine <br />
  <input type="checkbox" name="Event_Type" value="11" /> New Home <br />
  <input type="checkbox" name="Event_Type" value="12" /> Romantic <br />
  <input type="checkbox" name="Event_Type" value="13" /> Rhyme <br />
  <input type="checkbox" name="Event_Type" value="14" /> Religious <br />
  <input type="checkbox" name="Event_Type" value="15" /> Engagement <br />
  <input type="checkbox" name="Event_Type" value="16" /> Mothers Day <br />
  <input type="checkbox" name="Event_Type" value="17" /> Fathers Day <br />
  <input type="checkbox" name="Event_Type" value="18" /> Renewal of Vows <br />
  <input type="checkbox" name="Event_Type" value="19" /> Christening  <br />
  <input type="checkbox" name="Event_Type" value="20" /> Sympathy  <br />  
  <input type="checkbox" name="Event_Type" value="21" /> Leaving  <br />
  <input type="checkbox" name="Event_Type" value="22" /> Easter  <br />  
   <br />

  <input type="submit" value="Submit" />
</form>

</div>

</body>
</html>

Then a php script displays the result:

<?php
include("Loc_cverse_connect.php");
doDB();

//check for required info from the query string


//verify the Event exists
$verify_Event_sql = "SELECT ID, Event_Type FROM Events WHERE ID = '".$_POST["Event_Type"]."'";
$verify_Event_res =  mysqli_query($mysqli, $verify_Event_sql) or die(mysqli_error($mysqli));

//echo  $_POST["Event_Type"];

if (mysqli_num_rows($verify_Event_res) < 1) {
//this Event does not exist
$display_block = "<p><em>You have selected an invalid Event.<br/>
Please try again.</em></p>";
} else {
//get the Event ID
while ($Event_info = mysqli_fetch_array($verify_Event_res)) {
	$Event_ID = stripslashes($Event_info['ID']);
	$Event_Name = ($Event_info['Event_Type']);
}


//gather the Events
$get_Event_sql  = "SELECT Verses.ID AS versesID, Verses.Verse, Verses.Sub_Type, Verses.Event, Events.ID AS eventsID, Events.Event_Type, Event_Sub.ID AS event_SubID, Event_Sub.Event_Sub_Type
FROM Verses
LEFT JOIN Events
ON Verses.Event = Events.ID
LEFT JOIN Event_Sub
ON Verses.Sub_Type = Event_Sub.ID
WHERE Verses.Event = '".$_POST["Event_Type"]."' 
ORDER BY Verses.ID ASC";


$get_Event_res = mysqli_query($mysqli, $get_Event_sql) or die(mysqli_error($mysqli));

//create the display string
$display_block = "
<p> The Event Type is <b> 
 '".$Event_Name."'</b> </p>
<table width=\"70%\" cellpadding=\"3\" cellspacing=\"1\" border=\"1\" BGCOLOR=\"#87CEEB\" >
<tr>
<th>ID</th>
<th>VERSE</th>
<th>MOOD/SUB TYPE</th>
<th>Link</th>
</tr>";

while ($Verse_info = mysqli_fetch_array($get_Event_res)) {
	$Verse_id = $Verse_info['versesID'];
	$Verse_text = nl2br(stripslashes($Verse_info['Verse']));
	$Mood_info = $Verse_info['Event_Sub_Type'];

	//add to display
 	$display_block .= "
	<tr>
	<td width=\"1%\" valign=\"top\">".$Verse_id."<br/></td>
	<td width=\"55%\" valign=\"top\">".$Verse_text."<br/></td>
	<td width=\"35%\" valign=\"top\">".$Mood_info."<br/></td>
	<td width=\"9%\" valign=\"top\"><a href=\"Size_Menu.html\">Click here to choose</a> </td>
	</tr>";
}

//free results
//mysqli_free_result($get_Event_res);
//mysqli_free_result($verify_Event_res);

//close connection to MySQL
//mysqli_close($mysqli);

//close up the table
$display_block .= "</table>";
}

?>
<html>
<head>

<title> List of Verses</title>
</head>
<body BGCOLOR="#87CEEB">
<h1>Verses</h1>
<?php echo $display_block; ?>
</body>
</html>

I have put a cell on each line that hopefully chooses that line (Not sure if this will work?)

 

Then select card size:

<html>
<head>
<title>Card Verse Print</title>
<link rel="stylesheet" href="1066mk2_g.css" type="text/css" media="screen,projection,print">
<link rel="stylesheet" href="Size_p.css" type="text/css" media="screen,projection,print">	<!--// Page Style //-->
</head>
<body BGCOLOR="#00ff66">
    <span id="e11"></span>
<span id="e12"></span>
<span id="e13"></span>
<span id="e14"></span>
<span id="e15"></span>
<span id="e16"></span>
<div id="e3" class="navigation">
	<a id="a3" class="navigation" href="index.html" target="Vframe5>index">
	Home</a>
</div>
<div id="e4" class="navigation">
	<a id="a4" class="navigation" href="1066mk2_002.htm" target="Vframe5>1066mk2_002">
	Links</a>
</div>
<div id="e5" class="navigation">
	<a id="a5" class="navigation" href="1066mk2_003.htm" target="Vframe5>1066mk2_003">
	Techniques</a>
</div>
<div id="e6" class="navigation">
	<a id="a16" class="navigation" href="topiclist_frame.html" target="Vframe5>topiclist_frame">
	Forum</a>
</div>
<div id="e7" class="navigation">
	<a id="a7" class="navigation" href="1066mk2_004.htm" target="Vframe5>1066mk2_004">
	Contact Us</a>
</div>
<div id="e8" class="navigation">
	<a id="a8" class="navigation" href="1066mk2_006.htm" target="Vframe5>1066mk2_006">
	Gallery</a>
</div>
    
    
<div id="e30" class="cc08"
<h1>Card Size Menu

<table border="1">
<tr>
    <th>Card Size/Orientation</th>
    <th>Paper Orientation</th>
    <th>Cut Size</th>
</tr>
<tr>
    <td> <a href="VinputA5P.html">A5 Portrait</a></td>
    <td> Landscape </td>
    <td> 297 x 210mm </td>
</tr>
<tr>
    <td> <a href="VinputA5L.html">A5 Landscape</a></td>
    <td> Portrait </td>
    <td> 210 x 297mm </td>
</tr>
<tr>
    <td> <a href="VinputA5PS.html">A5 Portrait (single)</a></td>
    <td> Portrait </td>
    <td> 148 x 210mm </td>
</tr>
<tr>
    <td> <a href="VinputA6P.html">A6 Portrait</a></td>
    <td> Portrait </td>
    <td> 210 x 148mm </td>
</tr>
<tr>
    <td> <a href="VinputA6L.html">A6 Landscape</a></td>
    <td> Landscape </td>
    <td> 148 x 210mm </td>
</tr>
<tr>
    <td> <a href="VinputA6PS.html">A6 Portrait (Single)</a></td>
    <td> Portrait </td>
    <td> 105 x 148mm </td>
</tr>
<tr>
    <td> <a href="Vinput7x5P.html">7" x 5" Portrait</a></td>
    <td> Landscape </td>
    <td> 10" x 7" </td>
</tr>
<tr>
    <td> <a href="Vinput7x5L.html">7" x 5" Landscape</a></td>
    <td> Portrait </td>
    <td> 7" x 10" </td>
</tr>
<tr>
    <td> <a href="Vinput6x4P.html">6" x 4" Portrait</a></td>
    <td> Landscape </td>
    <td> 8" x 6" </td>
</tr>
<tr>
    <td> <a href="Vinput6x4L.html">6" x 4" Landscape</a></td>
    <td> Portrait </td>
    <td> 6" x 8" </td>
</tr>
<tr>
    <td> <a href="VinputDLP.html">DL Portrait </a></td>
    <td> Portrait </td>
    <td> 198 x 210mm </td>
<tr>
    <td> <a href="VinputDLL.html">DL Landscape</a></td>
    <td> Portrait </td>
    <td> 210 x 198mm </td>
</tr>    
<tr>
    <td> <a href="Vinput120SQP.html">120mm Square Portrait</a></td>
    <td> Landscape </td>
    <td> 240 x 120mm </td>
</tr>    
<tr>
    <td> <a href="Vinput120SQL.html">120mm Square Landscape</a></td>
    <td> Portrait </td>
    <td> 120 x 240mm </td>
</tr>    
<tr>
    <td> <a href="Vinput125SQP.html">125mm Square Portrait</a></td>
    <td> Landscape </td>
    <td> 250 x 125mm </td>
</tr>    
<tr>
    <td> <a href="Vinput125SQL.html">125mm Square Landscape</a></td>
    <td> Portrait </td>
    <td> 125 x 250mm </td>
</tr>
<tr>
    <td> <a href="Vinput130SQP.html">130mm Square Portrait</a></td>
    <td> Landscape </td>
    <td> 260 x 130mm </td>
<tr>
    <td> <a href="Vinput130SQL.html">130mm Square Landscape</a></td>
    <td> Portrait </td>
    <td> 130 x 260mm </td>
</tr>
<tr>
    <td> <a href="Vinput135SQP.html">135mm Square Portrait</a></td>
    <td> Landscape </td>
    <td> 270 x 135mm </td>
</tr>
<tr>
    <td> <a href="Vinput135SQL.html">135mm Square Landscape</a></td>
    <td> Portrait </td>
    <td> 135 x 270mm </td>
</tr>
<tr>
    <td> <a href="Vinput145SQP.html">145mm Square Portrait</a></td>
    <td> Landscape </td>
    <td> 290 x 145mm </td>
</tr>
<tr>
    <td> <a href="Vinput145SQL.html">145mm Square Landscape</a></td>
    <td> Portrait </td>
    <td> 145 x 290mm </td>
</tr>
<tr>
    <td> <a href="Vinput150SQP.html">150mm Square Portrait</a></td>
    <td> Landscape </td>
    <td> 297 x 150mm </td>
</tr>
<tr>
    <td> <a href="Vinput150SQL.html">150mm Square Landscape</a></td>
    <td> Portrait </td>
    <td> 150 x 297mm </td>
</tr>
<tr>
    <td> <a href="Vinput160SQS.html">160mm Square (Single)</a></td>
    <td> Landscape </td>
    <td> 160 x 160mm </td>
</tr>
<tr>
    <td> <a href="Vinput190SQS.html">190mm Square (Single)</a></td>
    <td> Portrait </td>
    <td> 190 x 190mm </td>
</tr>
<tr>
    <td> <a href="Vinput200SQS.html">200mm Square (Single)</a></td>
    <td> Portrait </td>
    <td> 200 x 200mm </td>
</tr>
</table>

</div>
</body>
</html>

Choice links to correct html script that user enters some variables:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- Generated by Avanquest Technology v:8.0. For information please visit: http://www.avanquestusa.com/ -->
<html lang="en">
<head>
<title> Verses - A5 Portrait </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css;">
<link rel="stylesheet" href="1066mk2_g.css" type="text/css" media="screen,projection,print">	<!--// Document Style //-->
<link rel="stylesheet" href="Vinput_p.css" type="text/css" media="screen,projection,print">	<!--// Page Style //-->
<script src="cverses_g.js" type="text/javascript"></script>		<!--// Document Script //-->
</head>


<body BGCOLOR="#00ff66">

<span id="e11"></span>
<span id="e12"></span>
<span id="e13"></span>
<span id="e14"></span>
<span id="e15"></span>
<span id="e16"></span>
<div id="e3" class="navigation">
	<a id="a3" class="navigation" href="index.html" target="Vframe5>index">
	Home</a>
</div>
<div id="e4" class="navigation">
	<a id="a4" class="navigation" href="1066mk2_002.htm" target="Vframe5>1066mk2_002">
	Links</a>
</div>
<div id="e5" class="navigation">
	<a id="a5" class="navigation" href="1066mk2_003.htm" target="Vframe5>1066mk2_003">
	Techniques</a>
</div>
<div id="e6" class="navigation">
	<a id="a16" class="navigation" href="topiclist_frame.html" target="Vframe5>topiclist_frame">
	Forum</a>
</div>
<div id="e7" class="navigation">
	<a id="a7" class="navigation" href="1066mk2_004.htm" target="Vframe5>1066mk2_004">
	Contact Us</a>
</div>
<div id="e8" class="navigation">
	<a id="a8" class="navigation" href="1066mk2_006.htm" target="Vframe5>1066mk2_006">
	Gallery</a>
</div>

<div id="e30" class="cc03">

	<form action="PrnpdfA5P.php" method="post">
	<p><strong>Input Distance from top in mm:</strong><br/> <input type="text" size="10" name="Top"/></p>
	<p><strong>Input Font size in points:</strong><br/> <input type="text" size="10" name="font"/></p>
	<p><strong>Check only ONE Tick Box in each section!</strong></p>
	<p><strong>Text Colour</strong></p>
	<input type="checkbox" name="color" value="000000000" /> Black<br />
	<input type="checkbox" name="color" value="255215000" /> Gold<br />
	<input type="checkbox" name="color" value="192192192" /> Silver<br />
	<input type="checkbox" name="color" value="255000000" /> Red<br />
	<input type="checkbox" name="color" value="000255000" /> Green<br />
	<input type="checkbox" name="color" value="000000255" /> Blue<br /><br />
	<p><strong>Text Font</strong></p>
	<input type="checkbox" name="fontface" value="French Script MT" /> French Script MT<br />
	<input type="checkbox" name="fontface" value="Batavia" /> Batavia <br />
	<input type="checkbox" name="fontface" value="Algerian" /> Algerian <br />
	<input type="checkbox" name="fontface" value="Bladerunner" /> Bladerunner <br />
	<input type="checkbox" name="fontface" value="Brush Script" /> Brush Script<br />
	<input type="checkbox" name="fontface" value="Helterskelter" /> Helterskelter<br />	
	<input type="checkbox" name="fontface" value="Justice" /> Justice<br />
	<input type="checkbox" name="fontface" value="Magneto" /> Magneto<br />
	<input type="checkbox" name="fontface" value="Old English" /> Old English<br />
	<input type="checkbox" name="fontface" value="Sneakerhead Outline" /> Sneakerhead Outline<br />
	<input type="checkbox" name="fontface" value="Trendy" /> Trendy<br />
	<input type="checkbox" name="fontface" value="Vladimir Script" /> Vladimir Script<br />

	<input type="submit" value="Submit"/>
	</form>
</div>
</body>
</html>

This then runs php script to produce output.  It also runs Mysql query to extract the chosen verse:

<?php
include("loc_cverse_connect.php");
doDB();

//verify the Event exists
$Get_Verse_sql = "SELECT ID, Event, Sub_Type, Verse FROM Verses WHERE ID = '".$Verse_id."'";
$Get_Verse_res =  mysqli_query($mysqli, $Get_Verse_sql) or die(mysqli_error($mysqli));



if (mysqli_num_rows($Get_Verse_res) < 1) {
//this Event does not exist
$display_block = "You have selected an invalid Event.
Please try again.";
} else {
//get the Event ID
while ($Verse_info = mysqli_fetch_array($Get_Verse_res)) {
	$Verse = stripslashes($Verse_info['Verse']);
}
	//create the display string
$display_block = "$Verse";
//free results
mysqli_free_result($Get_Verse_res);

//close connection to MySQL
mysqli_close($mysqli);
}
require('fpdf.php');

class PDF extends FPDF
{
var $B;
var $I;
var $U;
var $HREF;

function PDF($orientation='L', $unit='mm', $size='A4')
{
    // Call parent constructor
    $this->FPDF($orientation,$unit,$size);
    // Initialization
    $this->B = 0;
    $this->I = 0;
    $this->U = 0;
    $this->HREF = '';
}



function SetStyle($tag, $enable)
{
    // Modify style and select corresponding font
    $this->$tag += ($enable ? 1 : -1);
    $style = '';
    foreach(array('B', 'I', 'U') as $s)
    {
        if($this->$s>0)
            $style .= $s;
    }
    $this->SetFont('',$style);
}

}

$color = $POST[color];
$r = substr($color,0,3);
$g = substr($color,4,3);
$b = substr($color,7,3);

$pdf = new PDF();
$pdf->AddPage();
$pdf->AddFont('French Script MT','','frscript.php');
$pdf->AddFont('Batavia','','Batavia_.php');
$pdf->AddFont('Algerian','','Alger.php');
$pdf->AddFont('Bladerunner','','BLADRMF_.php');
$pdf->AddFont('Brush Script','','BRUSHSCI.php');
$pdf->AddFont('Helterskelter','','Helte___.php');
$pdf->AddFont('Justice','','Justice_.php');
$pdf->AddFont('Magneto','','MAGNETOB.php');
$pdf->AddFont('Old English','','OldEngl.php');
$pdf->AddFont('Sneakerhead Outline','','Sneabo__.php');
$pdf->AddFont('Trendy','','Trendy__.php');
$pdf->AddFont('Vladimir Script','','VLADIMIR.php');
$pdf->SetTextColor(255,215,000);
$pdf->SetFont($_POST[fontface],'',$_POST[font]);
$pdf->SetXY(170, $_POST[Top]);
$pdf->MultiCell(108,10,$display_block,'' ,'C');
$pdf->SetFont('');
$pdf->Output('verse.pdf','D');
?>

It appears not to put the verse_ID into the final php script as it runs the error part of the script.

 

Any ideas as to how I get this to work correctly?

Link to comment
Share on other sites

$Get_Verse_sql = "SELECT ID, Event, Sub_Type, Verse FROM Verses WHERE ID = '".$Verse_id."'";

 

I don't see where you are setting the value to $Verse_id, try the below: ... don't forget to sanitize the input

 

$Verse_id = $_GET['fontface'];
$Get_Verse_sql = "SELECT ID, Event, Sub_Type, Verse FROM Verses WHERE ID = '".$Verse_id."'";

 

 

Link to comment
Share on other sites

  • Solution

Hi

 

The $Verse_id comes from the second batch of code which queries the database to list all verse of a choosen type (e.g. Birthday).

 

I don't understand why you have suggested the addition of the line suggested as Fontface is the font that the user has choosen for the output.

 

What I am unsure of is how long  the life of the variable $Verse_id can be stored for use in the last script which outputs the verse via a printer.

 

The other thing that I am unsure of is whether the way I have put a link on each line of the output from the query will store the ID of the line its on.

 

This may be why I am not getting the results I am expecting. 

 

Has anyone got any ideas on how I can store this variable for the line in the output table?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.