Valhalla Legends Archive

Programming => Web Development => Topic started by: PaiD on November 01, 2005, 04:37 AM

Title: [PHP Solved] Form
Post by: PaiD on November 01, 2005, 04:37 AM
Ok I cant find out what is wrong with this code of mine and I was hoping someone could spot my problem(s).

echo ("<html>\n");
echo ("<title>Enter Username/Password</title>\n");
echo ("<p align=\"center\">\n");
echo ("<body bgcolor=\"black\">\n");
echo ("<img src=\"bot.jpg\">\n");
echo ("<form name=\"form1\" method=\"post\" action=\"bot.php\">\n");
echo ("<p align=\"center\">\n");
echo ("<font color=\"#FFFFFF\">Username:</font>");
echo ("<input name=\"User\" type=\"text\" id=\"User\">\n");
echo ("<br>\n");
echo ("<font color=\"#FFFFFF\">Password:</font>");
echo ("<input name=\"Pass\" type=\"text\" id=\"Pass\">\n");
echo ("<br>\n");
echo ("<input type=\"submit\" name=\"Submit\" value=\"Submit\">\n");
echo ("</p>\n");
echo ("</form>\n");
echo ("</body>\n");
echo ("</html>\n");

That is the form and when they click Submit I wanted it to go to Bot.php and pass the Post Stuff with it. I cant seem to get it to work right. It keeps going to the Header and being redirected

$User == $_POST["User"];
$Pass == $_POST["Pass"];
if (!$User) {
   header("location: /wb/bot.jpg");
   Exit;
} else {
$IP = $_SERVER['REMOTE_ADDR'];
$Connection = @mysql_connect("localhost","Username","Password") or die(mysql_error());
$DB = @mysql_select_db("Database Name",$Connection);
$SQL = "INSERT INTO `Users` (`Username`,`Password` , `Ip Address`, `Status`)" .
"VALUES ('$User', '$Pass', '$IP','0')";
@mysql_query($SQL,$Connection) or die(mysql_error());
mysql_close($Connection);
}
break;


Edit: Nevermind. Fixed. Not sure how but I was just messing with it and now it works :o
Title: Re: [PHP Solved] Form
Post by: AC_Drkan on December 30, 2005, 02:54 PM
Just as a side note, you don't have to separate every html code into a seperate echo statement, it can be included in 1 without the \n.
Title: Re: [PHP Solved] Form
Post by: rabbit on December 31, 2005, 09:32 AM
You'll want to changeif (!$User) { to if(!isset($_POST)) {
Title: Re: [PHP Solved] Form
Post by: FrOzeN on January 02, 2006, 10:10 PM
While were posting in a dead and solved topic I might add that you can close the php brackets then use html code and re-open them even during a statement.

Eg,
<?php$var1 = "hello";$var2 = "world";if (($var1 . " " . $var2) == ("hello world")) {?>

<html>
<head>
  <title>Page Title</title>
</head>
<body>
Hello World!
</body>
</html>
<?
} else {
    echo "Didn't work!";
}
?>


I find it comes in handy when using alot of html within php. :)
Title: Re: [PHP Solved] Form
Post by: Warrior on January 02, 2006, 11:08 PM
I'd rather not have my HTML code mixed with my PHP. I like to keep them both seperate for easy maintenence in the future.