Forum Moderators: coopster

Message Too Old, No Replies

How to POST the data to second page?

         

kira4

2:14 pm on Oct 5, 2009 (gmt 0)

10+ Year Member



This is the first page of my website(AssociationAdd.php). When I clicked the 'Add' button, it shows that :
"Notice: Undefined index: T2 in c:\easyphp1-8\www\efiling\associationaddprocess.php on line 19

Notice: Undefined index: T1 in c:\easyphp1-8\www\efiling\associationaddprocess.php on line 20"


<html>
<head>
<meta http-equiv="Content-Language" content="ja">
<title>Index</title>
</head>
<div style="position: absolute; width: 1146px; height: 842px; z-index: 1; left:10px; top:1px" id="layer2" align="center">

<body background="E-Filing%20Management%20System%20Picture/Snow.gif">

<p align="center">
<img border="0" src="E-Filing%20Management%20System%20Picture/logo-RR-gif.gif" width="957" height="245"></p>
<p align="center"><span lang="zh-cn">&nbsp;</span></p>
<p align="center"><span lang="zh-cn"><img border="0" src="E-Filing%20Management%20System%20Picture/Association.gif" width="491" height="74"></span></p>

<p align="center"><span lang="zh-cn">&nbsp;</span></p>

<div style="position: absolute; width: 191px; height: 28px; z-index: 2; left: 546px; top: 441px" id="layer4">
<font color="#FFFFFF"><span lang="en-us">

<font size="4" face="Arial Rounded MT Bold">&nbsp;Association Name</font></span></font></div>
<div style="position: absolute; width: 70px; height: 24px; z-index: 1; left: 298px; top: 442px" id="layer3">
<font size="4" face="Arial Rounded MT Bold"><font color="#FFFFFF"><span lang="en-us">

Index</span></font></font></div>
<p align="center"><span lang="zh-cn">&nbsp;
</span><font color="#FFFFFF"><span lang="en-us">

<font face="Arial Rounded MT Bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>
<font size="4" face="Arial Rounded MT Bold">&nbsp;&nbsp;&nbsp;&nbsp;</font></span></font></p>
<p align="center"><span lang="en-us">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>

<?php

echo"<form method='POST' action='AssociationAdd.php'>";
echo"<input type='text' name='T2' size='11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo"<input type='text' name='T1' size='77'></p>";
echo"<p>&nbsp;<input type='submit' value=' Add ' name='submit' style='font-family: Times New Roman; color: #000000; font-weight: bold; font-size: 12pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo"<input type='reset' value=' Reset ' name='B2' style='font-family: Times New Roman; color: #000000; font-weight: bold; font-size: 12pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo"<input type='submit' value=' Back ' name='submit' style='font-family: Times New Roman; color: #000000; font-weight: bold; font-size: 12pt'></p>";

if(isset($_POST["submit"]))
{
$submit = $_POST["submit"];
$T1 = $_POST["T1"];
$T2= $_POST["T2"];
if($submit==" Add ")
{

print "<script language ='javascript'>window.location.href='AssociationAddProcess.php?T1=$T1&T2=$T2'</script>";

}

else if($submit==" Back ")
{
print "<script language ='javascript'>window.location.href='Association.php'</script>";
}
}
echo"</form>";
?>
</div>
</body>
</html>

This is the second page(AssociationAddProcess.php):


<html>
<head>
<meta http-equiv="Content-Language" content="ja">
<title>Index</title>
</head>
<body background="E-Filing%20Management%20System%20Picture/Snow.gif">

<p align="center">
<img border="0" src="E-Filing%20Management%20System%20Picture/logo-RR-gif.gif" width="957" height="245"></p>
<p align="center"><span lang="zh-cn">&nbsp;</span></p>
<p align="center"><span lang="zh-cn"><img border="0" src="E-Filing%20Management%20System%20Picture/Association.gif" width="491" height="74"></span></p>

<?php

$id = $_POST["T2"];
$an = $_POST["T1"];

if ($id==null¦¦$an==null)
{
print"
<p align='center'>&nbsp;</p>

<table width='400' height='200' border='1' align='center' bordercolor='#66FF00'bgcolor='#0000FF'>

<td><div align='center'><font color='#FF0000' size='5'><p>Please Enter Index and Association Name Completely</p> </font></div></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table> ";

print "<p align='center'>&nbsp;</p>";
echo "<HTML><META HTTP-EQUIV='REFRESH' CONTENT='2; URL=AssociationAdd.php'>
<CENTER><p>&nbsp;</p><p>&nbsp;
<tr>
<td align='center'><h12>please wait...</h12></td>
</tr>
</table><p>&nbsp;</p><p>&nbsp;</p></CENTER></BODY></HTML>";
}

else
{
$connection=mysql_connect("localhost","root","")
or die("<font color='#FFFFFF'>Could not connect to MySQL</font>".mysql_error());

$selection=mysql_select_db("efiling")
or die("<font color='#FFFFFF'>Unable to select database.</font>".mysql_error());

$sql2 = "SELECT * from association Where AssociationName='$an'";
$result2 = mysql_query($sql2)
or die("<font color='#FFFFFF'>SQL select statement failed</font>");

if (mysql_num_rows($result2) < 1)
{

$sql = "INSERT INTO association(Index, AssociationName) VALUES ('$id', '$an')";
$result=mysql_query($sql)
or die("<font color='#FFFFFF'>SQL select statement failed</font>");

if ($result)
{
print "<script language ='javascript'>window.alert('Added Succesfully!');window.location.href='AssociationAdd.php'</script>";
}

else
{
die(mysql_error());
}
}
else
{
print"<p align='center'>&nbsp;</p>
<table width='400' height='200' border='1' align='center' bordercolor='#66FF00'bgcolor='#0000FF'>
<td><div align='center'><font color='#FF0000' size='5'><p>The Association Name Has Been Registered, Please Enter Other Association Name</p> </font></div></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table> ";

print "<p align='center'>&nbsp;</p>";
echo "<HTML><META HTTP-EQUIV='REFRESH' CONTENT='2; URL=AssociationAdd.php'>
<CENTER><p>&nbsp;</p><p>&nbsp;
<tr>
<td align='center'><h12>please wait...</h12></td>
</tr>
</table><p>&nbsp;</p><p>&nbsp;</p></CENTER></BODY></HTML>";

}
}
?>

</body>
</html>

Anyone can tell me what is the problem and how to solve it?

[edited by: eelixduppy at 3:28 am (utc) on Oct. 6, 2009]
[edit reason] side scroll [/edit]

andrewsmd

8:49 pm on Oct 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your not going to get any help with a post like that. Try telling us what you are trying to do, and what your problem is.

g1smd

9:44 pm on Oct 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The HTML code is 1996 abysmal.

Get rid of all the font elements, center tags, and the miles of non-breaking spaces and do the job properly.

You have spaces in URLs. That is always a very bad idea.

There's a lot more at stake than is suggested by your original question.

[edited by: g1smd at 9:48 pm (utc) on Oct. 5, 2009]

idfer

9:47 pm on Oct 5, 2009 (gmt 0)

10+ Year Member



Here's basically where the errors come from: In your initial script (AssociationAdd.php), if $submit is 'Add' you redirect the user to AssociationAddProcess.php with the values for T1 and T2 specified in the URL (?T1=$T1&T2=$T2) so when AssociationAddProcess.php is called, these values are stored in $_GET and not $_POST.

So you need to change lines 19 and 20 of AssociationAddProcess.php to:

$id = $_GET["T2"];
$an = $_GET["T1"];

Hope this helps. BTW, i'd suggest you name your buttons something other than "submit". In Javascript, all forms have a function called submit() that you may want to use in the future, and a button called "submit" overrides this function. You may want to give unique names to those submit buttons, i like using "op_add" and "op_back" etc:

echo"<p>&nbsp;<input type='submit' value=' Add ' name='op_add' ...
echo"<input type='reset' value=' Reset ' name='B2' ...
echo"<input type='submit' value=' Back ' name='op_back'...

Then in your PHP script you can simply check for isset($_POST['op_add']) and isset($_POST['op_back']).

caribguy

1:24 am on Oct 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not by any chance trying to get help with a phishing expedition, are you?

kira4

1:42 pm on Oct 7, 2009 (gmt 0)

10+ Year Member



This problem was solved, thank for your help.
Just like idfer said, change the lines 19 and 20 to :

$id = $_GET["T2"];
$an = $_GET["T1"];

But now I am facing another problem, SQL select statement failed. Before that I could connect to database, is that any problem in my coding?

andrewsmd

1:46 pm on Oct 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your best bet is to echo your sql query into your page and paste that into a mysql shell and see if that helps you find the error.

kira4

2:20 pm on Oct 7, 2009 (gmt 0)

10+ Year Member



I have test it and I discover that my error is here :

if (mysql_num_rows($result2) < 1)
{
$sql = "INSERT INTO association(Index, AssociationName) VALUES ('$id', '$an')";
$result=mysql_query($sql)
or die("<font color='#FFFFFF'>SQL select statement failed</font>");

But I checked my database, there is no wrong typing I think. May I know what is the problem? Below is print screen of my databse.
[img127.imageshack.us...]

kira4

3:38 pm on Oct 7, 2009 (gmt 0)

10+ Year Member



I was solved the problem.
Don't know why I can't use 'Index' as my field in database, after I changed my field name then no problem already. Thanks for helping. :)

idfer

4:17 pm on Oct 7, 2009 (gmt 0)

10+ Year Member



Index is a reserved word in SQL, you can see MySQL's list of reserved words here: [dev.mysql.com...]

There are quite a few of them. To avoid this kind of problem, i usually try to use field and table names containing an underscore.

tube34

9:05 pm on Oct 7, 2009 (gmt 0)

10+ Year Member



This is the first page of my website(AssociationAdd.php). When I clicked the 'Add' button, it shows that :
"Notice: Undefined index: T2 in c:\easyphp1-8\www\efiling\associationaddprocess.php on line 19

Notice: Undefined index: T1 in c:\easyphp1-8\www\efiling\associationaddprocess.php on line 20"

<html>
<head>
<meta http-equiv="Content-Language" content="ja">
<title>Index</title>
</head>
<div style="position: absolute; width: 1146px; height: 842px; z-index: 1; left:10px; top:1px" id="layer2" align="center">

<body background="E-Filing%20Management%20System%20Picture/Snow.gif">

<p align="center">
<img border="0" src="E-Filing%20Management%20System%20Picture/logo-RR-gif.gif" width="957" height="245"></p>
<p align="center"><span lang="zh-cn">&nbsp;</span></p>
<p align="center"><span lang="zh-cn"><img border="0" src="E-Filing%20Management%20System%20Picture/Association.gif" width="491" height="74"></span></p>

<p align="center"><span lang="zh-cn">&nbsp;</span></p>

<div style="position: absolute; width: 191px; height: 28px; z-index: 2; left: 546px; top: 441px" id="layer4">
<font color="#FFFFFF"><span lang="en-us">

<font size="4" face="Arial Rounded MT Bold">&nbsp;Association Name</font></span></font></div>
<div style="position: absolute; width: 70px; height: 24px; z-index: 1; left: 298px; top: 442px" id="layer3">
<font size="4" face="Arial Rounded MT Bold"><font color="#FFFFFF"><span lang="en-us">

Index</span></font></font></div>
<p align="center"><span lang="zh-cn">&nbsp;
</span><font color="#FFFFFF"><span lang="en-us">

<font face="Arial Rounded MT Bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>
<font size="4" face="Arial Rounded MT Bold">&nbsp;&nbsp;&nbsp;&nbsp;</font></span></font></p>
<p align="center"><span lang="en-us">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>

<?php

echo"<form method='POST' action='AssociationAdd.php'>";
echo"<input type='text' name='T2' size='11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo"<input type='text' name='T1' size='77'></p>";
echo"<p>&nbsp;<input type='submit' value=' Add ' name='submit' style='font-family: Times New Roman; color: #000000; font-weight: bold; font-size: 12pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo"<input type='reset' value=' Reset ' name='B2' style='font-family: Times New Roman; color: #000000; font-weight: bold; font-size: 12pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo"<input type='submit' value=' Back ' name='submit' style='font-family: Times New Roman; color: #000000; font-weight: bold; font-size: 12pt'></p>";

if(isset($_POST["submit"]))
{
$submit = $_POST["submit"];
$T1 = $_POST["T1"];
$T2= $_POST["T2"];
if($submit==" Add ")
{

print "<script language ='javascript'>window.location.href='AssociationAddProcess.php?T1=$T1&T2=$T2'</script>";

}

else if($submit==" Back ")
{
print "<script language ='javascript'>window.location.href='Association.php'</script>";
}
}
echo"</form>";
?>
</div>
</body>
</html>

This is the second page(AssociationAddProcess.php):

<html>
<head>
<meta http-equiv="Content-Language" content="ja">
<title>Index</title>
</head>
<body background="E-Filing%20Management%20System%20Picture/Snow.gif">

<p align="center">
<img border="0" src="E-Filing%20Management%20System%20Picture/logo-RR-gif.gif" width="957" height="245"></p>
<p align="center"><span lang="zh-cn">&nbsp;</span></p>
<p align="center"><span lang="zh-cn"><img border="0" src="E-Filing%20Management%20System%20Picture/Association.gif" width="491" height="74"></span></p>

<?php

$id = $_POST["T2"];
$an = $_POST["T1"];

if ($id==null¦¦$an==null)
{
print"
<p align='center'>&nbsp;</p>

<table width='400' height='200' border='1' align='center' bordercolor='#66FF00'bgcolor='#0000FF'>

<td><div align='center'><font color='#FF0000' size='5'><p>Please Enter Index and Association Name Completely</p> </font></div></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table> ";

print "<p align='center'>&nbsp;</p>";
echo "<HTML><META HTTP-EQUIV='REFRESH' CONTENT='2; URL=AssociationAdd.php'>
<CENTER><p>&nbsp;</p><p>&nbsp;
<tr>
<td align='center'><h12>please wait...</h12></td>
</tr>
</table><p>&nbsp;</p><p>&nbsp;</p></CENTER></BODY></HTML>";
}

else
{
$connection=mysql_connect("localhost","root","")
or die("<font color='#FFFFFF'>Could not connect to MySQL</font>".mysql_error());

$selection=mysql_select_db("efiling")
or die("<font color='#FFFFFF'>Unable to select database.</font>".mysql_error());

$sql2 = "SELECT * from association Where AssociationName='$an'";
$result2 = mysql_query($sql2)
or die("<font color='#FFFFFF'>SQL select statement failed</font>");

if (mysql_num_rows($result2) < 1)
{

$sql = "INSERT INTO association(Index, AssociationName) VALUES ('$id', '$an')";
$result=mysql_query($sql)
or die("<font color='#FFFFFF'>SQL select statement failed</font>");

if ($result)
{
print "<script language ='javascript'>window.alert('Added Succesfully!');window.location.href='AssociationAdd.php'</script>";
}

else
{
die(mysql_error());
}
}
else
{
print"<p align='center'>&nbsp;</p>
<table width='400' height='200' border='1' align='center' bordercolor='#66F tube34.net F00'bgcolor='#0000FF'>
<td><div align='center'><font color='#FF0000' size='5'><p>The Association Name Has Been Registered, Please Enter Other Association Name</p> </font></div></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table> ";

print "<p align='center'>&nbsp;</p>";
echo "<HTML><META HTTP-EQUIV='REFRESH' CONTENT='2; URL=AssociationAdd.php'>
<CENTER><p>&nbsp;</p><p>&nbsp;
<tr>
<td align='center'><h12>please wait...</h12></td>
</tr>
</table><p>&nbsp;</p><p>&nbsp;</p></CENTER></BODY></HTML>";

}
}
?>

</body>
</html>

Anyone can tell me what is the problem and how to solve it?

:)

andrewsmd

9:46 pm on Oct 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You define $T2 in your if isset but then output it outside of that if statement
if(isset($_POST["submit"]))
{
$submit = $_POST["submit"];
$T1 = $_POST["T1"];
$T2= $_POST["T2"];
if($submit==" Add ")
{

print "<script language ='javascript'>window.location.href='AssociationAddProcess.php?T1=$T1&T2=$T2'</script>";

Basically your script is saying that there is no varaible $t2 because your if(isset must not have returned true. I hope this helps.