0

Hi,

I am trying to execute the following script, but each time it is failing and returning "Unable".
Note: "Unable" is the response returned when isset($_POST) is not working, refer the code for more details.

PHP CODE

<?php
$test = "Hi!";
if ((isset($_POST['usrName'])) && (isset($_POST['pWord'])))
{
	$user = $_POST["usrName"];
	$pass = $_POST["pWord"];
	$con = mysql_connect("","root","");
	
	if(!$con)
	{
		die("Could not connect!");
		echo "Fail";
	}
	
	mysql_select_db("learn", $con);
	mysql_query("INSERT INTO loginrecords (Username, Password)
	VALUES ('$user', '$pass')");
	mysql_close($con);
	echo "Success!";
	echo $test;
	echo $user;
	echo $pass;
	}

	else 
	{
		echo "Unable";
	}
?>

HTML FORM CODE ONLY

<form action="CreateUser.php" method="post">
	<table class=CreateUser cellpadding=4px, cellspacing=2px>
		<tr class=TableHeading>
			<td colspan=2>Enter the infomation below</td>
		</tr>
		<tr class=FormContents>
				<td>Username</td>
				<td><input type=text id=usrName size=20px></input>
				</td>
		</tr>
		<tr class=FormContents>
				<td>Password</td>
				<td><input type=password id=pWord size=20px></input>
				</td>
		</tr>
		<tr class=FormContents>
				<td></td>
				<td align=right><input type=submit id=Cu_Bt value=Login></td>
		</tr>	
	</table>
	</form>

Thanks!

5
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by iammirko
0

the browser submits the NAME of your input fields, NOT the id. So you MUST give your fields a name="..." attribute:

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

the same goes for the other fields.

0

You don't have name="" attributes in your html form code.

<form action="CreateUser.php" method="post">
	<table class=CreateUser cellpadding=4px, cellspacing=2px>
		<tr class=TableHeading>
			<td colspan=2>Enter the infomation below</td>
		</tr>
		<tr class=FormContents>
				<td>Username</td>
				<td><input type=text id=usrName name=usrName size=20px></input>
				</td>
		</tr>
		<tr class=FormContents>
				<td>Password</td>
				<td><input type=password id=pWord name=pWord size=20px></input>
				</td>
		</tr>
		<tr class=FormContents>
				<td></td>
				<td align=right><input type=submit id=Cu_Bt value=Login></td>
		</tr>	
	</table>
	</form>
0

Hello iammirko. Both, hielo and mschroeder, are right, but you must "close" all your name, id, and that stuff with "" or '', and use style="" for styling your table... your html code must be:

<form action="CreateUser.php" method="post" name="form">
     <table class="CreateUser" style="cellpadding:4px; cellspacing:2px;">
          <tr class="TableHeading">
               <td colspan="2">Enter the infomation below</td>
          </tr>
          <tr class="FormContents">
               <td>Username</td>
               <td><input type="text" name="text" id="usrName" size="20px"/></td>
          </tr>
          <tr class=FormContents>
               <td>Password</td>
               <td><input type="password" name="password" id="pWord" size="20px"/></td>
          </tr>
          <tr class="FormContents">
               <td></td>
               <td align="right"><input type="submit" name="submit" id="Cu_Bt" value="Login"/></td>
          </tr>	
     </table>
</form>

Edited by P0lT10n: n/a

0

Misread but cannot (or don't know how to) delete, apologies.

Edited by Nyight: n/a

0

Hello iammirko. Both, hielo and mschroeder, are right, but you must "close" all your name, id, and that stuff with "" or '', and use style="" for styling your table... your html code must be:

<form action="CreateUser.php" method="post" name="form">
     <table class="CreateUser" style="cellpadding:4px; cellspacing:2px;">
          <tr class="TableHeading">
               <td colspan="2">Enter the infomation below</td>
          </tr>
          <tr class="FormContents">
               <td>Username</td>
               <td><input type="text" name="text" id="usrName" size="20px"/></td>
          </tr>
          <tr class=FormContents>
               <td>Password</td>
               <td><input type="password" name="password" id="pWord" size="20px"/></td>
          </tr>
          <tr class="FormContents">
               <td></td>
               <td align="right"><input type="submit" name="submit" id="Cu_Bt" value="Login"/></td>
          </tr>	
     </table>
</form>

Actually only the XHTML 1.0 spec (http://www.w3.org/TR/xhtml1/#h-4.4) requires attributes to be quoted. The HTML 4 spec (http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2) does not require them to be quoted unless they fail to meet certain criteria: In certain cases, authors may specify the value of an attribute without any quotation marks. The attribute value may only contain letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45), periods (ASCII decimal 46), underscores (ASCII decimal 95), and colons (ASCII decimal 58). We recommend using quotation marks even when it is possible to eliminate them. Just FYI.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.