Jump to content


Photo

Difficulties Passing Variables


  • Please log in to reply
3 replies to this topic

#1 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 10 July 2006 - 02:03 PM

I am trying to pass a db variable from one script to the next but nothing is working.
Admin page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Approval</title>
</head>
<body>
<h3>Welcome Bobby</h3>
<p>These are recently pending database entries, please accept/decline.  Please note declined entries are automatically permanently deleted from the database. These are all updated together, upon submit.  The ones that are approved are set to approved status, the ones that are declined, are immediately deleted from the database, and the file is removed from it's location on the server.  If you check some of the choice, and leave some of the choice alone, they will still be here later, for instance if there are 3 items listed.  If you approve 1, decline 1, and leave the other alone for now, the approved one is updated, the declined one is deleted, and the one left alone, is not touched, and left there, for you to update later.</p>
<?php  // Connects to database
$connect = mysql_connect("localhost", "#####", "#####");
$select = mysql_select_db("funnyemailforwards");
$errorhandler = "";
$management = true;
if (!$connect || !$select) {
	$errorhandler = "The database could not connect, or was not selected<br />";
	$management = false;
}
?>	

<?php // script to display information
$result = mysql_query("SELECT * FROM fileinfo WHERE approval=0 ORDER BY entrydate ASC");
echo "<form name=\"dataupdating\" action=\"approvalprocessor.php\" method=\"post\">";

while ($row = mysql_fetch_assoc($result))
{
extract($row);
$date = date("m/d/y");
$website = "http://www.funnyemailforwards.com/apex/";
$site = $website . $funnyurl;
 echo "<ul>";
 echo "<li><a href=" . '"' . $site . '"' . 'target="_blank">' . $nameoffunny . "</a></li>";
 echo "<li>" . $date . "</li>";
 echo "<li><input type=\"radio\" name=\"approval[$id]\" value=\"1\">Approve</li>";
 echo "<li><input type=\"radio\" name=\"approval[$id]\" value=\"0\">Decline</li>";
 echo "</ul>";  
 $manager = true;
}
if ($manager === true) {
echo "<input name=\"funny\" type=\"hidden\" value=\"{$funnyurl}\" />";
echo "<input name=\"update\" type=\"submit\" value=\"Update Database\">";
echo "</form>";
}
?>



</body>
</html>
Here is my processor page
<?php  // Connects to database
$connect = mysql_connect("localhost", "#####", "#####");
$select = mysql_select_db("funnyemailforwards");
$errorhandler = "";
$management = true;
if (!$connect || !$select) {
	$errorhandler = "The database could not connect, or was not selected<br />";
	$management = false;
}
?>	

<?php
if (isset($_POST['update'])) {

       foreach ($_POST['approval'] as $key => $value) {
    if ($value) {
		mysql_query('UPDATE fileinfo SET approval=1 WHERE id='.$key);
		echo "Update Successful, update";
    } else {
		mysql_query('DELETE FROM fileinfo WHERE id='.$key);
		echo "Update Successful, delete from db";
		echo "{$funnyurl}";
		unlink($funnyurl); // url is set to exactly like this
		// http://www.funnyemailforwards.com/apex/uploads/filename.ext
		// Follows a path exactly to the file.
    	}
	}// closes foreach
}// closes isset control structure
?>
I am having a few issues, I am trying to pass the variable $funnyurl over to the other page.  I originally thought it did it automatically, but I soon realized I have to use hidden form fields or something similar.
I understand that, but not's why it'sn ot passing the variable even through hidden form field.
THe variable is being pulled from the db, with the use of the extract function.  As well the variable has been tested, and it works, the approval pages, displays information using the $funnyurl variable,
In the db the $funnyurl is set to uploads/filename.ext
This allows for the quick part of the file, in my scripts, I have another variable
$site = "http://www.funnyemai...ards.com/apex";
Which is the direcotry
then I put
$url = $site . $funnyurl
And I get a successful combination leading directly to the file, this works so far in all my script, but I tried doing this entire script on one page, I am still fairly new to php, so my main weakpoint is doing same page scripts.  If I have 5 scripts doing the same thing, or a form, I can never get it to work on same page, I haven't gotten there yet, but even now I am having trouble, I don't get it, any advice, I tried passing it normally, but variables don't pass like that, then I tried the hidden form field, the same with connections, I thought if you connected to a db, it stayed open in between scripts, but I had to reopen the connection on the other page as well.  IS there a reason the variable isn't getting read, or do I have to use a whole nothing db call for it to have access to the variable information, I thought variable information was passed through the form field.  Or is the other page not accessing the db for the information, if that is true, can't I just put my db connection, database seclecting, information retrieval, and extract function in a seperate page, and include them in all of them so all my scripts have the same access, or is this another issue?

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#2 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 10 July 2006 - 02:41 PM

bump

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 10 July 2006 - 02:56 PM

Try $_POST['funnyurl'] instead of $funnyurl in your processor script.

Also dont bump your threads until they are atleast 2 or more hours old.

#4 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 10 July 2006 - 03:13 PM

Sounds good, I just ran the connect, and select statement, and extract in a include, and included it in both, so I can freely use variables in both scripts from the database.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users