Jump to content

php and html forms


abulreesh

Recommended Posts

Hi,

 

This is probably an easy fix but considering i'm a php newbie its causing me a big headache hope someone can help.  Alright i'm trying to write a page which has multiple buttons now once one button is clicked a username and password form appears if the user enters the right username and password then the user is allowed to complete the transaction.  So far i managed to get the display all user button to work, i'm stuck when the user hits the display user button, the username and password form pops out, when the user enters the right ones it's showing the enter the user form but after that the page doesn't do anything.  Can anyone help pleassse.

 

<html>

<body>

 

<p> Admin page please choose an option <br \>

 

<form method="GET">

<input name="DisplayAll" type="submit" id="Display All" value="Display All"><br /><br />

</form>

 

<?php

if (isset($_GET['DisplayAll']))

{

?>

<form action="" method="post" name="login" id="login">

<p>  <font size="4">User ID </font> 

<input type="text" name="username" id="username" size="20"></p>

<p>  <font size="4">Password </font> 

<input type="password" name="password" id="password" size="20"></p>

<p>  <input name="login" type="submit" id="login" value="Login">

<input type="reset" value="Reset" name="clear"></p>

</form>

<?php

if (isset($_POST['username']) && isset($_POST['password'])) {

  include 'connect.php';  //Connects to database

  //Reads username and password from form

  $userId = $_POST['username'];

  $password = $_POST['password'];

 

  //Querying the username and password from the database

  $sql = "SELECT username FROM user WHERE username = '$userId' AND password = '$password'";

  $result = mysql_query($sql) or die('Query failed. ' . mysql_error());

 

  if (mysql_num_rows($result) == 1) {

$sql2 = "SELECT * FROM user";

$result2 = mysql_query($sql2) or die('Query failed. ' . mysql_error());

 

while($r = mysql_fetch_array($result2))

{

$user = $r['username'];

$pass = $r['password'];

$type = $r['type'];

echo $user. " ". $pass. " ". $type;

echo '<br \>';

}

}

mysql_close($conn);

echo "<br \>";

}

}

?>

 

<form method="GET">

<input name="DisplayUser" type="submit" id="Display User" value="Display User"><br /><br />

</form>

 

<?php

if (isset($_GET['DisplayUser'])) {

?>

<form method="post" name="login" id="login">

<p>  <font size="4">User ID </font> 

<input type="text" name="username" id="username" size="20"></p>

<p>  <font size="4">Password </font> 

<input type="password" name="password" id="password" size="20"></p>

<p>  <input name="login" type="submit" id="login" value="Login">

<input type="reset" value="Reset" name="clear"></p>

</form>

<?php

if (isset($_POST['username']) && isset($_POST['password'])) {

  include 'connect.php';  //Connects to database

  //Reads username and password from form

  $userId = $_POST['username'];

  $password = $_POST['password'];

 

  //Querying the username and password from the database

  $sql = "SELECT username FROM user WHERE username = '$userId' AND password = '$password' ";

  $result = mysql_query($sql) or die('Query failed. ' . mysql_error());

 

  if (mysql_num_rows($result) == 1) {

?>

<form action="" method="post" name="usern" id="usern">

<p>  <font size="4">User To Display </font> 

<input type="text" name="user" id="user" size="20">  

<input name="enter" type="submit" id="enter" value="Enter"></p>

</form>

<?php

if (isset($_POST['user'])) {

$uID = $_POST['user'];

 

$sql2 = "SELECT * FROM user WHERE username = '$uID' ";

$result2 = mysql_query($sql2) or die('Query failed. ' . mysql_error());

 

while($s = mysql_fetch_array($result2))

{

$u = $s['username'];

$p = $s['password'];

$t = $s['type'];

echo $user. " ". $pass. " ". $type;

echo '<br \>';

}

}

mysql_close($conn);

echo "<br \>";

}

}

}

?>

 

<input name="AddUser" type="submit" id="Add User" value="Add User"><br /><br />

<input name="DeleteAll" type="submit" id="Delete All" value="Delete All"><br /><br />

<input name="DeleteUser" type="submit" id="Delete User" value="Delete User"><br /><br />

 

</body>

</html>

 

Since i'm here does anyone know how to clean this up a little i tried using functions but it didn't work and tried using sessions and include and i wasn't able to pass anything too.

 

Thanks alot.

Link to comment
https://forums.phpfreaks.com/topic/57146-php-and-html-forms/
Share on other sites

Nope that didn't do it.  You see the display all part is working fine, it's when i re-write the same script for the display user button that's when i run into problems.  It's as if php doesn't allow two forms one after another, because the it displays the username and password then it shows a second form asking for the name of the user you want to display and thats when it just doesn't do anything. It basically goes to a normal page instead of displaying the user's info.  I don't know if my questions is clear enough I guess i could try posting snap shots maybe that would help.

Link to comment
https://forums.phpfreaks.com/topic/57146-php-and-html-forms/#findComment-283051
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.