Forum Moderators: coopster

Message Too Old, No Replies

Help with PHP

very basic thing

         

Argie

9:32 pm on Sep 28, 2003 (gmt 0)

10+ Year Member



Can somebody tell me why this isn't working:

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.

dmorison

11:47 pm on Sep 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi 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...?

RonPK

11:02 am on Sep 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Matias,
The keyword in this part of your learning curve is 'register globals'.

In welcome.php, try
print ("<B><CENTER>Hello, ". $_GET['Name'] . "</CENTER></B>\n" );

Argie

1:09 pm on Sep 29, 2003 (gmt 0)

10+ Year Member



Thank you very much both for taking the time to answer my question. I've already fix my problem, but thank you very much both for your time.

Sorry for my poor english.

Matias

PSWorx

6:22 am on Oct 2, 2003 (gmt 0)

10+ Year Member



Im currently reading up on the php language and i seem to have come to an abrupt end in my testing/learning phase. At present im on a section to do with DMB databases (i have a funny feeling these are somewhat obsolete..?!? but never the less...), im testing the scripts i create both localy and on a remote server for the sake of any OS dependancies etc, the script goes as follows (bare with me this is some simple stuff)

(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...

PSWorx

6:24 am on Oct 2, 2003 (gmt 0)

10+ Year Member



Pardon my somewhat terrible spelling mistakes ive been awake too long i think... :">

Paul in South Africa

6:49 am on Oct 2, 2003 (gmt 0)

10+ Year Member



PSWorx - depending on your version of PHP you may have to recompile it with --with-ndb and --with-db.

Have a look at the User Contibuted Notes on the PHP Site [za2.php.net]

PSWorx

7:21 am on Oct 2, 2003 (gmt 0)

10+ Year Member



Thanks for the advice ill give it a shot and see what results i get, if not ill just move onto the mysql section, well im already there but u know...

Much appreciated ;)

PSWorx

6:48 am on Oct 3, 2003 (gmt 0)

10+ Year Member



Im have written a script that calls a series of data from a MySQL database, i can output this as is with none or little formatting which is alright for that point, now i need to format the data differntly according to the field from which the data came from... The code is as follows (This is only a section):

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)

PSWorx

6:49 am on Oct 3, 2003 (gmt 0)

10+ Year Member



I made an error on the last entry, in the final parapgraph replace the $field var for $result... Either way the scripts wrong but would appreciate the help...

PSWorx

7:01 am on Oct 3, 2003 (gmt 0)

10+ Year Member



I don't think anyone has seen the post yet, but either way not to worry i've sorted the little problem using mysql_fetch_array... DUH

Paul in South Africa

7:01 am on Oct 3, 2003 (gmt 0)

10+ Year Member



Deleted. Wrong information. That's what comes with typing while on the phone.

PSWorx

7:30 am on Oct 3, 2003 (gmt 0)

10+ Year Member



Pardon me... LOL anyways to the point, right ive sorted out the display of the data with the appropriate formatting which once again is fine at that point. i used the following:

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]

coopster

11:26 am on Oct 3, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Are you saying you want to print three items of information out of the database on one row, print a horizontal rule and print three more, etc. until the entire recordset has been processed? Well, it's not pretty, but a counter should work:

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>";
}

PSWorx

1:11 pm on Oct 3, 2003 (gmt 0)

10+ Year Member



I knew it was something to do with a count variable but just couldnt fathem it, uve given me a good base to go with there, thanks alot, lol ive said this a fair few times today but here goes again... MUCH APPRECIATED lets just hope i can get this to work ;)

PSWorx

1:25 pm on Oct 3, 2003 (gmt 0)

10+ Year Member



Just incase you wanted to know i thought i'd show you the final working function (Once again with much appreciation), here it is (a few modifications did take place):

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]

PSWorx

9:01 am on Oct 6, 2003 (gmt 0)

10+ Year Member



OK, I've made a simple login script which verifies the users inputs with data stored in a mysql db. Heres the code:

<?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"&nbsp;Enter your user name here.<p>\n";
echo"<input type=\"text\" name=\"npass\">";
echo"&nbsp;Enter your password here.<p>\n";
echo"<input type=\"text\" name=\"nemail\">";
echo"&nbsp;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]

PSWorx

10:13 am on Oct 6, 2003 (gmt 0)

10+ Year Member



Well noone's been, or more so replied but never the less, ive sorted the problem so forget about the last entry...