Reply to Re: super easy questions

Your name:

Reply:


Posted by noone on 10/08/23 11:43

walterbyrd@iname.com wrote:

> I am trying to get user input from a php form. Problem is: the form
> doesn't wait for the user to press the submit button, but falls right
> through. Therefore the variable I am trying to get, is never set. I
> know it has to be something simple, but I'm missing it. Here is the
> code:

> echo "<form action=\"$PHP_SELF\" method=\"post\">";
> echo "Name of new database to create: ";
> echo "<br><input type=\"text\" name=\"new_db\">";
> echo "<input type=\"submit\" value=\"submit\"><br><br>";
> if ($new_db)
> {
> $create_db = 'CREATE DATABASE '.$new_db;
> if (mysql_query($create_db, $conn))
> {
> echo "Database $new_db created successfully\n";
> }
> else
> {
> echo 'Error creating database: ' . mysql_error() . "\n";
> }
> }
> else
> {
> echo ("new database not created");
> };


You need something that stops at the form - I have used either a _SESSION
variable or a hidden variable.


like this:

<?php

if (isset($_POST['hiddenvar']))
// hidden variable set - process input form
{
if ($new_db)
{
$create_db = 'CREATE DATABASE '.$new_db;
if (mysql_query($create_db, $conn))
{
echo "Database $new_db created successfully\n";
}
else
{
echo 'Error creating database: ' . mysql_error() . "\n";
}
}
else
{
echo ("new database not created");
};
}
// hidden variable not set - display form
else {
echo "<form action=\"$PHP_SELF\" method=\"post\">";
echo "Name of new database to create: ";
echo "<br><input type=\"text\" name=\"new_db\">";
echo "<input type=hidden value=1 name=hiddenvar>";
echo "<input type=\"submit\" value=\"submit\"><br><br>";

}
?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация