Hello fellows.
I need some help regarding my script.
I have a simple php script contains form to insert First Name and Last Name. This works successfully.
But my problem is when i try to display the posted data to ASP page, the ASP page doesnt come out.
What should I do in this case?

This is my code

PHP

<!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=utf-8" />
<title>PHP TO ASP :: testing only</title>

<!-- Submit Form script -->
<script type="text/javascript">
function submitForm()
{
	document.forms["hiddenform"].submit();
	alert("??");
}
</script>
</head>

<?php

//Connect to DB server
$conn = mysql_connect('localhost','root','') or die(mysql_error());

//Selece database
mysql_select_db('ems',$conn) or die(mysql_error());


$FName = $_POST['FName'];
$LName = $_POST['LName'];

if(isset($_POST['send'])){
    $sql = "INSERT INTO `ems`.`tbl_dummy` (`FName`, `LName`) VALUES ('$FName', '$LName');";
    mysql_query($sql);
	
	// I dont know whether this correct or not. But it doesnt work
	print("<script type=\"text/javascript\">submitForm();</script>");
}
?>
<body>
<form action="" method="post" enctype="application/x-www-form-urlencoded" name="frm_test">
<label>First Name: </label><input name="FName" type="text" /><br />
<label>Last Name: </label><input name="LName" type="text" /><br  />
<input name="send" type="submit" value="Save" />
</form>

<!-- Hidden form submitted by javascript to php2asp.asp -->
<form action="http://localhost/php2asp.asp" method="post" enctype="application/x-www-form-urlencoded" name="hiddenform" id="hiddenform">
<input name="FName" type="hidden" value="<?= $FName ?>" />
<input name="LName" type="hidden" value="<?= $LName ?>" />
<input name="submit" type="hidden" value="" />
</form>

</body>
</html>

ASP

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!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=utf-8" />
<title>This is ASP :: Data from PHP</title>
</head>

<body>
<h2>These data are from PHP</h2>
<% 
dim fname, lname
fname = request.Form("FName")
lname = request.Form("LName")

response.Write(fname& " " &lname)
%>
</body>
</html>

Thank you. :)

On line 34 you are attempting to submit the hidden form, BUT at that point, there is no such form defined/seen by the browser yet because you begin the definition until line 45. What you need to do is call that function AFTER you have closed the hidden form

OR upon page load:

print('<script type="text/javascript">window.onload=submitForm;</script>');

@hielo
Thanks for the solution. It works.
But then, could you give any idea besides using javascript?

search for articles on CURL:

<?php
if( isset($_POST['send']) )
{
	//Connect to DB server
	$conn = mysql_connect('localhost','root','') or die(mysql_error());

	//Select database
	mysql_select_db('ems',$conn) or die(mysql_error());


	$FName = mysql_real_escape_string($_POST['FName']);
	$LName = mysql_real_escape_string($_POST['LName']);

	$sql = "INSERT INTO `ems`.`tbl_dummy` (`FName`, `LName`) VALUES ('$FName', '$LName');";
	mysql_query($sql) or die(mysql_error());
	
	$params=array();
	$params[]="FName=".urlencode($_POST['FName']);
	$params[]="LName=".urlencode($_POST['LName']);

	$ch = curl_init(POSTURL);
	curl_setopt($ch, CURLOPT_POST ,1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $params) );
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
	curl_setopt($ch, CURLOPT_HEADER      ,0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);
	$data = curl_exec($ch);
}
else
{
	$data=<<<BLANKFORM
	<form action="{$_SERVER['PHP_SELF']}" method="post" enctype="application/x-www-form-urlencoded" id="frm_test">
		<label>First Name: </label><input name="FName" type="text" /><br />
		<label>Last Name: </label><input name="LName" type="text" /><br  />
		<input name="send" type="submit" value="Save" />
	</form>
BLANKFORM;

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>PHP TO ASP :: testing only</title>
</head>
<body>
<?php echo $data; ?>
</body>
</html>
commented: Nice +0

wow. it works.
Thank you hielo.
That's really help.

i have another problem.
when i run the code, it seems the URL doesnt change.
How should i do to redirect to the ASP page?

this is the code.

<?php
if (isset($_POST['send'])) {
    //Connect to DB server
    $conn = mysql_connect('localhost', 'root', '') or die(mysql_error());

    //Select database
    mysql_select_db('ems', $conn) or die(mysql_error());


    $FName = mysql_real_escape_string($_POST['FName']);
    $LName = mysql_real_escape_string($_POST['LName']);

    $sql = "INSERT INTO `ems`.`tbl_dummy` (`FName`, `LName`) VALUES ('$FName', '$LName');";
    mysql_query($sql) or die(mysql_error());

    $params = array();
    $params[] = "FName=" . urlencode($_POST['FName']);
    $params[] = "LName=" . urlencode($_POST['LName']);

    $ch = curl_init("http://localhost/php2asp.asp");
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $params));
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $data = curl_exec($ch);
}
?>
<!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=us-ascii" />

    <title>PHP TO ASP :: testing only</title>
</head>

<body>
    <?php
    if (!isset($data)) {
    ?>

    <form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" enctype="application/x-www-form-urlencoded" id="frm_test" name="frm_test">
        <label>First Name:</label> <input name="FName" type="text" />
        <br />
        <label>Last Name:</label> <input name="LName" type="text" />
        <br />
        <input name="send" type="submit" value="Save" />
    </form><?php
    } else {
        print $data;
    }
    ?>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.