Forum Moderators: coopster
form.html:
----------
<html>
<head>
<title>Form</title>
</head>
<body>
<FORM ACTION="HandleForm.php" METHOD="GET">
Firs Name <INPUT TYPE=TEXT NAME="FirstName" SIZE=20><BR>
Last Name <INPUT TYPE=TEXT NAME="LastName" SIZE=40><BR>
E-Mail <INPUT TYPE=TEXT NAME="Email" SIZE=60><BR>
Comments <TEXTAREA NAME="Comments" ROWS=5 COLS=40></TEXTAREA><BR>
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit">
</FORM>
</body>
</html>
HandleForm.php:
----------------
<html>
<head>
<title>Form Results/Using Strings</title>
</head>
<body>
<?php
extract($_GET);
$FirstName = Trim($FirstName);
$LastName = Trim($LastName);
$Email = Trim($Email);
$Comments = Trim($Comments);
$Name = $FirstName . " " . $LastName;
print("Your Name is $Name<BR>\n" );
print("Your E-Mail address is $Email<BR>\n" );
print("This is what you had to say: <BR>\n $Comments<BR>\n" );
$Name = urlencode($Name);
print ("<P>Click <a href=\"welcome.php?Name=$Name\"> here</a> to see your personalized greeting!\n" );
?>
</body>
</html>
welcome.php:
-------------
<html>
<head>
<title>Welcome</title>
</head>
<body>
<?php
print ("<B><CENTER>Hello, $Name</CENTER></B>\n" );
?>
</body>
</html>
The problem is that in welcome.php, the $Name variable is empty, i don't know how to pass the value of $Name in HandleForm.php to $Name in welcome.php. In the way I'm doing it (source code above), is not working.
Can anybody help me?, i'm very new in PHP.
Just for the record, i'm using PHP 4.3.3 in Windows 98 SE with Personal Web Server.
Sorry for my poor english, and thanks in advance.
Matias.
Your code looks OK at first glance.
What is the actual URL that apears in the address bar when viewing welcome.php? Is it exactly as you would expect; for example:
http://www.yourdomain.com/welcome.php?Name=Fred%20Bloggs
What i'm saying is, can you tell from observation if the $Name value is being presented on the URL correctly...?
(READING FROM:SAMS Teach Yourself PHP4 in 24Hours)
<?php
$dbh = dbmopen("./data","c")or die ("Couldnt open database");
dbminsert($dbh,"Pre-Boxed Site 1","19.99");
dbminsert($dbh,"Pre-Boxed Site 2","29.99");
dbminsert($dbh,"Pre-Boxed Site 3","39.99");
dbminsert($dbh,"Pre-Boxed Site 4","49.99");
dbmclose($dbh);
?>
Yet when i run the script in my browser i get the following:
adding products now...
Fatal error: Call to undefined function: dbmopen() in c:\apache\htdocs\temp\php testing\index2.php on line 8
Now if im not mistaken thats telling me the function dmbopen() is undefined and non-existant, so why is it im being told its a built in function of php, and if the latter is correct why the error message...
Have a look at the User Contibuted Notes on the PHP Site [za2.php.net]
function read_and_print($Name,$Image,$Description)
{
$result=mysql_query("SELECT * FROM cus_gallery");
while($row=mysql_fetch_row($result))
{
foreach($row as $field)
{
if($result=="Name")
{
print"<div id=\"top\"><p id=\"title\">$field</p></div>\n";
}
elseif($result=="Image")
{
print"<div id=\"mid\">$field";
}
elseif($result=="Description")
{
print"<p id=\"text1\">$field</p></div>";
}
}
print("<div id=\"bot\"></div>");
print"<hr>";
}
}
Im trying to use an if statement in the foreach statement to decide which data field the data has come from i.e. if($field=="Name") or if($field=="Image") or if($field=="Description"), depending on which data filed the data came from, will depend on how its formatted. To get to the point how would i setup a statement to discover which field the data came from so i can format it appropriatley...? HELP ME (LOL Sorry)
function read_and_print($Name,$Image,$Description)
{
$result=mysql_query("SELECT * FROM cus_gallery");
while($field=mysql_fetch_array($result))
{
print("<table id=\"pbslayout\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n<tr>\n<td>\n");
print"\t<div id=\"top\"><p id=\"title\">$field[Name]</p></div>\n";
print"<div id=\"mid\">$field[Image]\n";
print"<p id=\"text\">$field[Description]</p></div>\n";
print("<div id=\"bot\"></div>\n");
print("</td>\n</tr>\n</table>\n");
print"<hr>";
}
}
Now, that prints the data in the appropriate div tags within a table, but i need three colums like this, i have an auto incrament field named "ID" within the database, for the final output i require three of these display boxes per a table and then for the script to write a new table with the next three blocks of details (formatted in the same way as the previous three (so three of the "info" boxes per table)), and so on untill it reaches the end of the database, ill probably figure it out within the next ten mintues (He says chuckling to his self) but once again i would appreciate the help...
If its any help you the working script with its current output is available at:
You will have to enter some details to view the output or you can just submit the form blank.
And another thing, is there anyway that i can get this to work with jpg/jpeg images as it doesnt seem to be uploading them, it apparently only supports gif images...
[edited by: jatar_k at 4:21 pm (utc) on Oct. 6, 2003]
[edit reason] removed specifics [/edit]
function read_and_print($Name,$Image,$Description)
{
$result=mysql_query("SELECT * FROM cus_gallery");
while($field=mysql_fetch_array($result)) {
if (++$counter == 1) {
print("<table id=\"pbslayout\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n<tr>\n<td>\n");
} else {
print"\t<div id=\"top\"><p id=\"title\">$field[Name]</p></div>\n";
print"<div id=\"mid\">$field[Image]\n";
print"<p id=\"text\">$field[Description]</p></div>\n";
print("<div id=\"bot\"></div>\n");
if ($counter == 3) {
print("</td>\n</tr>\n</table>\n");
print"<hr>";
$counter = 0;
}
}
}
if ($counter!= 0 and $counter!=3) {
print("</td>\n</tr>\n</table>\n");
print"<hr>";
}
function read_and_print($Name,$Image,$Description)
{
$result=mysql_query("SELECT * FROM cus_gallery");
while($field=mysql_fetch_array($result))
{
if (++$counter == 1)
{
print("<table id=\"pbslayout\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n<tr>\n");
print"<td>\n\t<div id=\"container\"><div id=\"top\"><p id=\"title\">$field[Name]</p></div>\n";
print"<div id=\"mid\">$field[Image]\n";
print"<p id=\"text\">$field[Description]</p></div>\n";
print("<div id=\"bot\"></div></div>\n</td>\n");
}
else
{
print"<td>\n\t<div id=\"container\"><div id=\"top\"><p id=\"title\">$field[Name]</p></div>\n";
print"<div id=\"mid\">$field[Image]\n";
print"<p id=\"text\">$field[Description]</p></div>\n";
print("<div id=\"bot\"></div></div>\n</td>\n");
if ($counter == 3)
{
print("</tr>\n</table>\n");
print"<hr>\n";
$counter = 0;
}
}
}
if ($counter!= 0 and $counter!=3)
{
print("</tr>\n</table>\n");
print"<hr>\n";
}
}
Theres you have and final piece is at:
if you would like to try it out.
[edited by: jatar_k at 4:21 pm (utc) on Oct. 6, 2003]
[edit reason] removed specifics [/edit]
<?php
if(isset($nuser)&&isset($npass)&&isset($nemail))
{
$ret=connectandcheck($nuser,$npass,$nemail);
if(!$ret)
echo"ERROR";
}
else
{
echo login_form();
}
function connectandcheck($nuser,$npass,$nemail)
{
$user="psworx";
$pass="200783";
$db="displays";
$link=mysql_pconnect("localhost",$user,$pass);
if(!link)die("ERROR: Couldn't connect to MySQL server.");
mysql_select_db($db)or die("ERROR: Couldn't connect to MySQL database: \".$db\".");
$result=mysql_query("SELECT * FROM users");
$field=mysql_fetch_array($result);
if($field[user]!=$nuser or $field[pass]!=$npass or $field[email]!=$nemail)
{
echo"Wrong login details, please try again:\n";
echo login_form();
}
else
{
include("mem_gallery_input.php");
}
}
function login_form()
{
global$PHP_SELF;
echo"<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" width=\"750\">\n<tr>\n<td>\n";
echo"Welcome to Edit-WORX, please login to continue:";
echo"<form action=\"$PHP_SELF\" method=\"POST\">\n";
echo"<input type=\"text\" name=\"nuser\">";
echo" Enter your user name here.<p>\n";
echo"<input type=\"text\" name=\"npass\">";
echo" Enter your password here.<p>\n";
echo"<input type=\"text\" name=\"nemail\">";
echo" Enter your email here.<p>\n";
echo"<input type=\"submit\" value=\"submitit!\">\n</form>\n";
echo"</tr>\n</td>\n</table>\n";
}
?>
THE PROBLEM:
When i run the page and enter the CORRECT login details it returns the line:
echo"ERROR";
If the user details are correct it will work as it's meant to but still the error line is displayed...
Any help would be appreciated!
[edited by: jatar_k at 4:20 pm (utc) on Oct. 6, 2003]
[edit reason] removed specifics [/edit]