Jump to content

Recommended Posts

Hello again I need help once more :-x

Ok so I created a post html page where the user fills out a form and it sends it to my PHP script using the $POST method.  I have validated froms checking for input if non is given it prints an error message.  Now here is my question how can I reload the form with the information that the vistor entered on the previous one.  My HTML code is stored in a varible $htmlcode here is the code for it is below.  This comes from the original html document that passed the value to PHP from the form.  I tried to set the values of the input text box to strings; however that did not work.  Here is what I used

<input type="text" name="db_fax" value="$db_fax" size="25">.  For some reason the scipt didnt read the value of the string and put it as its value. It just filled the input text boxes with the name of the string($db_fax). To output the data is used print "$htmlcode"; method. If some one could tell me what Im doing that would be awesome.

Thank You

Grodo

 

Varible $htmlcode

$htmlcode = '<html><head><title>Untitled-4</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head><body bgcolor="#ffffcc" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><img src="gts.gif" width="100%" height="79" alt="">
<center><br><font color="white" size="4"> <b>Sign Up For Galaxy Tool Supply Promotional News Letter</b></font><form name=form1 method=post action=http://xxxxx.com/~gxxxx/xxxx.php> <table border = "0" width="100%" cellpadding="5" cellspacing="0">
<tr><td width="100"><b>Name*</b></td><td><input type="text" name="db_name" value="$db_name" size="25"></td></tr><tr><td>Email</td>
<td><input type="text" name="db_email" value="$db_email"  size="25"></td></tr><tr><td>Company</td><td><input type="text" name="db_company" value=" $db_company" size="25"></td></tr>
<tr><td><b>Address 1*</b></td><td><input type="text" name="db_snumber" value="$db_snumber" size="25"></td></tr>
<tr><td>Address 2</td><td><input type="text" name="db_address2" value="$db_address2" size="25"></td></tr><tr>
<td><b>City</b>*</td><td><input type="text" name="db_city" value="$db_city"size="25"></td></tr><tr><td><b>State / Territory*</b></td>
<td><input type="text" name="db_state" value="$db_state" size="25"></td></tr><tr><td><b>Country*</b></td><td><input type="text" name="db_country" value="$db_country" size="25"></td></tr>
<tr><td><b>Postal Code*</b></td><td><input type="text" name="db_zip" value="$db_zip" size="25"></td>
</tr><tr><td>Phone</td><td><input type="text" name="db_phone" value='$db_phone' size="25"></td></tr>
<tr><td>Fax</td><td><input type="text" name="db_fax" value="$db_fax" size="25"></td></tr>
<tr><td> </td><td><input type="submit" name="submit"> <input type="reset" name="Reset"></td></tr></table></form></center>';

 

Thank You Grodo

it's not recognizing the variable within a variable because you'r using single quotes.

 

example:

$name = "Bob";

 

$a = "Hello My Name is $name";

$b = 'Hello My Name is $name';

 

echo $a;  // returns: Hello My Name is Bob

echo $b;  // returns: Hello My Name is $name

my above post being said, you have three options.

 

1)  Use "double quotes" around your variable -- but then you have to escape all the quotes withing your HTML:  <? $htmlcode = "..... value=\"$db_snumber\" size=\"25\".....";

 

easier:

2) Use the single quotes but break out of them for your variables: <? $htmlcode = '..... value="'.$db_snumber.'" size="25".....';

 

easiest:

3) why do you have to have all your HTML in a variable?

<? //some php code here ?>

<!-- regular html code here: -->

 

<input type="text" name="db_name" value="<?=$db_name ?>" size="25">

 

 

Thanks for your input... I need all the html in a variable because its in the middle of a else statement. Unless if there is another option there are 108 quotes this is going to be fun!

 

	 else {
 // Lovely Error Codes :-)
	//if ( $errorcodes[0] == "ename")
	//	print "<style font-color:'red'>State / Territory Field Missing<br></style>";
	//Lets set some background colors
	print "<body bgcolor=#ffffcc>";
	if ( $errorcodes[0] == "ename")
		{print "<font color ='red'><b><ul type="circle"><li>State / Territory Field Missing<br></font></b></ul></li>";}	
	if ( $errorcodes[1] == "esnumber")
		{print "<font color ='red'><b><ul type="circle">Street Number Missing<br></font></b></ul></li>";}
	if ( $errorcodes[2] == "ecity")
		{print "<font color ='red'><b><ul type="circle">City Field Missing<br></font></b></ul></li>";}
	if ( $errorcodes[3] == "estate")
		{print "<font color ='red'><b><ul type="circle">State Field Missing<br></font></b></ul></li>";}
	if ( $errorcodes[4] == "ezip" )
		{print "<font color ='red'><b><ul type="circle">Postal Code Field Missing<br></font></b></ul></li>";}
	if ( $errorcodes[5] == "ecountry")
		{print "<font color ='red'><b><ul type="circle">Country Field Missing<br></font></b></ul></li>";}
	print "$htmlcode";
	}

with PHP there's always an easier way to everything!

 

<?php

// ..... here's all your PHP code

if ( $errorcodes[5] == "ecountry"){ ?>

<font color ='red'><b><ul type="circle">Country Field Missing<br></font></b></ul></li>

put all the HTML you want here.

<?php } // then finish off your PHP code here ?>

MMMMM Thought I had it... the values were read but now the form keeps displaying its self i was going to create another page in an include if there was no errors. Orignally there was a blank page if everythign was sent without any errors. However now it just keeps showing the same page(newsform.html). I think that suspending of the php for a second made the browser think it was supposed just skip a section of the else. Here is my whole code I am really lost now :-x I have been working on this for a while now and I cant seem to figure it out

 

phpharvester.php

<?php
// Information Harvester v 1.0
//Special thanks to the members of PHP Freaks.com that made this script possible ;-)
// This PHP script collects information that was passed through a form.
// Then in out puts the data into categories and creates different campaign .csv files
// July 25, 2007
include ('functions.php');


// MMMMM Lets Get That Raw Data!
if (isset($_POST["submit"])) {
	// Get data from post
	$db_name = $_POST["db_name"];
	$db_company = $_POST["db_company"];
	$db_email = $_POST["db_email"];
	$db_fax = $_POST["db_fax"];
	$db_phone = $_POST["db_phone"];
	$db_snumber = $_POST["db_snumber"];
	$db_address2 = $_POST["db_address2"];
	$db_city = $_POST["db_city"];
	$db_state = $_POST["db_state"];
	$db_zip = $_POST["db_zip"];
	$db_country = $_POST["db_country"];
	// After Data Gathered Format It |  Trim removes white space |  Strip Tags removes html for security
	// Format Name
	$db_name = strip_tags($db_name);

	//Format Company
	$db_company = strip_tags($db_company);

	// Format Email
	$db_email = strip_tags($db_email);
	$db_email = trim($db_email);

	//Format Fax
	$db_fax = strip_tags($db_fax); 
	$db_fax = preg_replace("/[a-zA-Z]/xms","",$db_fax); 	// Lets Extract All Numbers From The Fax Data
	$db_fax = trim($db_fax);

	//Format Phone
	$db_phone = strip_tags($db_phone); 
	$db_phone = preg_replace("/[a-zA-Z]/xms","",$db_phone); 	// Lets Extract All Numbers From The Phone Data
	$db_phone = trim($db_phone);

	//Format Address
	$db_snumber = strip_tags($db_snumber);

	//Format Address2
	$db_address2 = strip_tags($db_address2);

	//Format city
	$db_city = strip_tags($db_city);

	//Format State
	$db_state = strip_tags($db_state);

	//Format Postal Code
	$dp_zip = strip_tags($db_zip);

	//Format Country
	$dp_country = strip_tags($db_country);
}
// Ok lets validate some parameters! With error reporting!
//First we make an array to hold the error code information
$errorcodes = array('ok', 'ok', 'ok', 'ok', 'ok', 'ok');
if ($db_name == "") {
	$errorcodes[0] = ename;

}
if ($db_snumber == "") {
	$errorcodes[1] = esnumber;

}
if ($db_city == "") {
	$errorcodes[2] = ecity;

}
if ($db_state == "") {
	$errorcodes[3] = estate;

}
if ($db_zip == "") {
	$errorcodes[4] = ezip;
}
if ($db_country == "") {
	$errorcodes[5] = ecountry;
}

// Code that gives the ok to process
for ( $i = 0; $i<6; $i++ ) {
	if ( $errorcodes[$i] == "ok" ) {
		$process == TRUE;
	} else {
		$process == FALSE;
	}
}	

if (isset($db_name) && isset($db_snumber) && isset($db_city) && isset($db_state) && isset($db_zip) && isset($db_country) && $process == TRUE)
{
	//Lets Try To Open Our Fax Campaign File
	$csv_fax = "fax.csv";
	if (is_writable($csv_fax)) {
		if (!$csv_faxhandle = fopen($csv_fax,"a")) {
			echo "<p>Cannot open file $csv_fax</p>";
			exit;
		}
	}
	//Lets Try To Open Our Telemarketing Campaign File
	$csv_phone = "phone.csv";
	if (is_writable($csv_phone)) {
		if (!$csv_phonehandle = fopen($csv_phone,"a")) {
			echo "<p>Cannot open file $csv_phone</p>";
			exit;
		}
	}
	//Lets Try To Open Our All Data Campaign File
	$csv_alldata = "alldata.csv";
	if (is_writable($csv_alldata)) {
		if (!$csv_alldatahandle = fopen($csv_alldata,"a")) {
			echo "<p>Cannot open file $csv_alldata</p>";
			exit;
		}
	}
	// Lets Try To Open Our Mailing List
	$csv_mail = "mail.csv";
	if (is_writable($csv_mail)) {
		if (!$csv_mailhandle = fopen($csv_mail,"a")) {
			echo "<p>Cannot open file $csv_mail</p>";
			exit;
		}
	}
	// Lets Try To Open Our Formated mailing list
	$txt_mail = "mailformat.txt";
	if (is_writable($txt_mail)) {
		if (!$txt_mailhandle = fopen($txt_mail,"a")) {
			echo "<p>Cannot open file $txt_mail</p>";
			exit;
		}
	}



	// Alright! Its time to start writing
	// Writing All Data Name, Company, Email, Phone, And Fax
	$csv_itemalldata = "\"$db_name\",\"$db_company\",\"$db_email\",\"$db_phone\",\"$db_snumber\",\"$db_address2\",\"$db_city\",\"$db_state\",\"$db_country\",\"$db_zip\",\"$db_fax\"\n";

	if (is_writable($csv_alldata)) {
		if (fwrite($csv_alldatahandle, $csv_itemalldata) === FALSE) {
		echo "Cannot write to file $csv_alldata";
		exit; 
		}
	}
	// Lets Close The File
	fclose($csv_alldatahandle);

	// Writing Telemarket Campaign
	$csv_itemphonedata = "\"$db_name\",\"$db_company\",\"$db_email\",\"$db_phone\"\n";
	if (is_writable($csv_phone)) {
		if (fwrite($csv_phonehandle, $csv_itemphonedata) === FALSE) {
		echo "Cannot write to file $csv_phone";
		exit; 
		}
	}
	// Lets Close The File
	fclose($csv_phonehandle);

	// Writing Fax Campaign
	$csv_itemfaxdata = "\"$db_fax\"\n";
	if (is_writable($csv_fax)) {
		if (fwrite($csv_faxhandle, $csv_itemfaxdata) === FALSE) {
		echo "Cannot write to file $csv_fax";
		exit; 
		}
	}
	// Lets Close The File
	fclose($csv_faxhandle);

	// Writing Mail List Campaign
	$csv_itemmaildata = "\"$db_name\",\"$db_company\",\"$db_email\",\"$db_phone\",\"$db_snumber\",\"$db_address2\",\"$db_city\",\"$db_state\",\"$db_country\",\"$db_zip\"\n";
	if (is_writable($csv_mail)) {
		if (fwrite($csv_mailhandle, $csv_itemmaildata) === FALSE) {
		echo "Cannot write to file $csv_mail";
		exit; 
		}
	}
	//Close File
	fclose($csv_mailhandle);

	// Writing Format Mail
	$txt_data = "$db_name\n$db_company\n$db_snumber\n$db_address2\n$db_city\n$db_state\n$db_zip\n$db_country\n\n";
	if (is_writable($txt_mail)) {
		if (fwrite($txt_mailhandle, $txt_data) === FALSE) {
		echo "Cannot write to file $txt_mail";
		exit; 
		}
	} 
	fclose($txt_mailhandle);



}
 else {
 // Lovely Error Codes :-)
	//if ( $errorcodes[0] == "ename")
	//	print "<style font-color:'red'>State / Territory Field Missing<br></style>";
	//Lets set some background colors
	print "<body bgcolor=#ffffcc>";
	if ( $errorcodes[0] == "ename")
		{print "<font color =red><b><ul type=circle><li>State / Territory Field Missing<br></font></b></ul></li>";}	
	if ( $errorcodes[1] == "esnumber")
		{print "<font color =red><b><ul type=circle><li>Street Number Missing<br></font></b></ul></li>";}
	if ( $errorcodes[2] == "ecity")
		{print "<font color =red><b><ul type=circle><li>City Field Missing<br></font></b></ul></li>";}
	if ( $errorcodes[3] == "estate")
		{print "<font color =red><b><ul type=circle><li>State Field Missing<br></font></b></ul></li>";}
	if ( $errorcodes[4] == "ezip" )
		{print "<font color =red><b><ul type=circle><li>Postal Code Field Missing<br></font></b></ul></li>";}
	if ( $errorcodes[5] == "ecountry")
		{print "<font color =red><b><ul type=circle><li>Country Field Missing<br></font></b></ul></li>";}
	// SUSPENDING PHP TO ALLOW HTML
	?>
	<form name=form1 method=post action=http://mysite.net/phpharvest.php> 
	<table border = "0" width="100%" cellpadding="5" cellspacing="0">
	<tr>
	<td width="100"><b>Name*</b></td>
	<td><input type="text" name="db_name" value="<?=$db_name?>" size="25"></td>
	</tr>
	<tr>
	<td>Email</td>
	<td><input type="text" name="db_email" value="<?=$db_email?>" size="25"></td>
	</tr>
	<tr>
	<td>Company</td>
	<td><input type="text" name="db_company" value="<?=$db_company?>" size="25"></td>
	</tr>
	<tr>
	<td><b>Address 1*</b></td>
	<td><input type="text" name="db_snumber" value="<?=$db_snumber?>" size="25"></td>
	</tr>
	<tr>
	<td>Address 2</td>
	<td><input type="text" name="db_address2" value="<?=$db_address2?>" size="25"></td>
	</tr>
	<tr>
	<td><b>City</b>*</td>
	<td><input type="text" name="db_city" value="<?=$db_city?>" size="25"></td>
	</tr>
	<tr>
	<td><b>State / Territory*</b></td>
	<td><input type="text" name="db_state" value="<?=$db_state?>" size="25"></td>
	</tr>
	<tr>
	<td><b>Country*</b></td>
	<td><input type="text" name="db_country" value="<?=$db_country?>" size="25"></td>
	</tr>
	<tr>
	<td><b>Postal Code*</b></td>
	<td><input type="text" name="db_zip" value="<?=$db_zip?>" size="25"></td>
	</tr>
	<tr>
	<td>Phone</td>
	<td><input type="text" name="db_phone" value="<?=$db_phone?>" size="25"></td>
	</tr>
	<tr>
	<td>Fax</td>
	<td><input type="text" name="db_fax" value="<?=$db_fax?>" size="25"></td>
	</tr>
	<tr>
	<td> </td>
	<td>
	<input type="submit" name="submit"> <input type="reset" name="Reset">
	</td>
	</tr>
	</table>
	</form></center>
	<?php }
?>

 

 

Newsform.html

<html>
<head>
<title>Untitled-4</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#ffffcc" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center><br>
<font color="white" size="4"> <b>Sign Up For Promotional News Letter</b></font>
<form name=form1 method=post action=http://xxxx.com/~sssz/phpharvest.php> 
<table border = "0" width="100%" cellpadding="5" cellspacing="0">
<tr>
  <td width="100"><b>Name*</b></td>
<td><input type="text" name="db_name" size="25"></td>
</tr>
<tr>
  <td>Email</td>
<td><input type="text" name="db_email" size="25"></td>
</tr>
<tr>
  <td>Company</td>
<td><input type="text" name="db_company" size="25"></td>
</tr>
<tr>
  <td><b>Address 1*</b></td>
<td><input type="text" name="db_snumber" size="25"></td>
</tr>
<tr>
  <td>Address 2</td>
<td><input type="text" name="db_address2" size="25"></td>
</tr>
<tr>
  <td><b>City</b>*</td>
<td><input type="text" name="db_city" size="25"></td>
</tr>
<tr>
  <td><b>State / Territory*</b></td>
<td><input type="text" name="db_state" size="25"></td>
</tr>
<tr>
  <td><b>Country*</b></td>
<td><input type="text" name="db_country" size="25"></td>
</tr>
<tr>
  <td><b>Postal Code*</b></td>
<td><input type="text" name="db_zip" size="25"></td>
</tr>
<tr>
  <td>Phone</td>
<td><input type="text" name="db_phone" size="25"></td>
</tr>
<tr>
  <td>Fax</td>
<td><input type="text" name="db_fax" size="25"></td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" name="submit"> <input type="reset" name="Reset">
</td>
</tr>
</table>
</form></center>

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.