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!

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.

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>
Member Avatar for P0lT10n

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>

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

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.

It works! Thanks friends. Thanks a lot! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.