Thread Tools Display Modes
04-10-11, 05:27 PM   #1
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
A little PHP/HTLM Help?

Hi, my guild leader wrote something on our forums and I was just seeing if anyone here would have the knowledge / willing to be able to help us out?

Hey, im working on a program for something going in my lab. Basically i need to pass a number from an html file to a write file later on in the series.

Here is the html file in which we get the number i need with the form.

Code:
<html> <form action="IAT.php" method="post">    
Subject ID: <input type="text" name="sub" /> <input type="submit" value="submit" /> 
</form> </html>
below here is IAT.php which the number is being passed to

Code:
<?php require_once("IATname.inc"); ?><?php    if( !isset( $_POST['sub'] ) || !$_POST['sub'] ){       die( 'No sub provided! go back and try again!' );    }        // initialize a session    // a session allows us to maintain state related to a specific user across page views    session_start();        // store the sub inside the session data    $_SESSION['subject'] = $_POST['sub']; ?> 
<html>
<head>
<title><?php echo $IATname; ?> IAT</title>
<script type="text/javascript" src="IAT.js"></script>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript"> 
   initialize(); 
   document.onkeypress = keyHandler; 
</script>
<style type="text/css"> @import "iat.css";</style>
</head>

<body>
    
<div id="experiment_frame">
    <div id="header">
        <div id="left_cat"></div><div id="right_cat"></div>
    </div>
    <div id="picture_frame">
        <div id="exp_instruct"></div>
        <div id="word" class="IATitem"></div>
        <img id="wrong" src="Wrong.jpg">
    </div>
</div>
<div id="under_instruct">
    If the <b>E</b> and <b>I</b> keys do not work, click the mouse inside the white box and try again.<br>
    If the red <font color=red>X</font> appears, press the other key to make the red <font color=red>X</font> go away.
</div>

</body>
And finally here is the write file. Basically the iat collect a bunch of data and than writes it in a file. I want the number that was put in the html file to write into the file name so that it will write IAT_the number and the random text and date marker we have. I can tell the number is being passed to the IAT file but for some reason teh write while keeps writing IAT_unknown_date_random text. Ive been working on this since thursday and its driving me batty. Any help would be good. If you aren't pro at php please dont provide crappy suggestions i might kill myself

Here is the writefile

Code:
<?php 
session_start();
$base_dir = realpath(dirname(__FILE__));  

$folder_dir = "/Users/patrick/Sites/IAT/implicitassoc/trunk/output";    // retrieve the subject from the session data -- or unknown if not there (so we don't lose data) 

$sub = isset( $_SESSION['subject'] ) ? $_SESSION['subject'] : 'unknown' ;  
echo $sub;
$data = $_REQUEST["data"]; $randtxt = date('Y-m-d-H-s-') . dechex(rand(4097,65536));  // we need to stick the subject identifier in the file name 
$fh = fopen($folder_dir. '/IAT_' . $sub . '-' . $randtxt . '.txt', 'w'); 
fwrite($fh, $data); 
fclose($fh);  
?>
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote
04-10-11, 06:08 PM   #2
Ither
A Firelord
 
Ither's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 497
Tell your friend to watch the code breaks. He had them messed up.

The files he needs to fix are listed below

IAT.php
PHP Code:
<?php
require_once("IATname.inc");
if( !isset( 
$_POST['sub'] ) || !$_POST['sub'] ){       
    die( 
'No sub provided! go back and try again!' );    }
    
$_SESSION['subject'] = $_POST['sub']; ?> 
<html>
<head>
<title><?php echo $IATname?> IAT</title>
</head>

<body>
    
<div id="experiment_frame">
    <div id="header">
        <div id="left_cat"></div><div id="right_cat"></div>
    </div>
    <div id="picture_frame">
        <div id="exp_instruct"></div>
        <div id="word" class="IATitem"></div>
        <img id="wrong" src="Wrong.jpg">
    </div>
</div>
<div id="under_instruct">
    If the <b>E</b> and <b>I</b> keys do not work, click the mouse inside the white box and try again.<br>
    If the red <font color=red>X</font> appears, press the other key to make the red <font color=red>X</font> go away.
</div>

</body>
He did not put $_SESSION['subject'] = $_POST['sub']; on a new line therefore it was blocked by markup. Also, he has both INC and call in two separate <?> blocks; no reason to do that.

IATname.inc
PHP Code:
<?php 
session_start
();
$base_dir realpath(dirname(__FILE__));  

$folder_dir "/Users/patrick/Sites/IAT/implicitassoc/trunk/output";    // retrieve the subject from the session data -- or unknown if not there (so we don't lose data) 

$sub = isset( $_SESSION['subject'] ) ? $_SESSION['subject'] : 'unknown' ;  
echo 
$sub;
$data $_REQUEST["data"]; $randtxt date('Y-m-d-H-s-');  // we need to stick the subject identifier in the file name 
$fh fopen($folder_dir'/IAT_' $sub '-' $randtxt '.txt''w'); 
fwrite($fh$data); 
fclose($fh);  
?>
I removed . dechex(rand(4097,65536)); because I saw no reason why he needed a decimal to hex conversion. I don't know the full extent of his assignment. This was giving a random hex at the end of the filename.


There you go. Solved.

That will be 10,000g. Please ask him to forward it to my super secret Swiss Bank account.
__________________

Last edited by Ither : 04-10-11 at 06:12 PM.
  Reply With Quote
04-10-11, 07:47 PM   #3
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
Thanks a ton.
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote
04-10-11, 07:50 PM   #4
Ither
A Firelord
 
Ither's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 497
No problem.
__________________
  Reply With Quote
04-10-11, 09:27 PM   #5
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
My friend still seems to be getting a problem with your script, would you mind helping me out a bit more if it isn't too much to ask?

still writing as unknown - code as it stands now. Willing to give server side access if it will help. With the new write file it was written as

IAT_unknown-date.txt

IAT.php


PHP Code:
<?php
require_once("IATname.inc");
if( !isset( 
$_POST['sub'] ) || !$_POST['sub'] ){* * * *
    die( 
'No sub provided! go back and try again!' );* * }
    
$_SESSION['subject'] = $_POST['sub']; ?> 
<html>
<head>
<title><?php echo $IATname?> IAT</title>
<script type="text/javascript" src="IAT.js"></script>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript"> 
    initialize(); 
    document.onkeypress = keyHandler; 
</script>
<style type="text/css"> @import "iat.css";</style>
</head>

<body>
* * 
<div id="experiment_frame">
* * <div id="header">
* * * * <div id="left_cat"></div><div id="right_cat"></div>
* * </div>
* * <div id="picture_frame">
* * * * <div id="exp_instruct"></div>
* * * * <div id="word" class="IATitem"></div>
* * * * <img id="wrong" src="Wrong.jpg">
* * </div>
</div>
<div id="under_instruct">
* * If the <b>E</b> and <b>I</b> keys do not work, click the mouse inside the white box and try again.<br>
* * If the red <font color=red>X</font> appears, press the other key to make the red <font color=red>X</font> go away.
</div>

</body>
Write file

PHP Code:
<?php 
session_start
();
$base_dir realpath(dirname(__FILE__));* 

$folder_dir "/Users/patrick/Sites/IAT/implicitassoc/trunk/output";* * // retrieve the subject from the session data -- or unknown if not there (so we don't lose data) 

$sub = isset( $_SESSION['subject'] ) ? $_SESSION['subject'] : 'unknown' ;* 
echo 
$sub;
$data $_REQUEST["data"]; $randtxt date('Y-m-d-H-s-');* // we need to stick the subject identifier in the file name 
$fh fopen($folder_dir'/IAT_' $sub '-' $randtxt '.txt''w'); 
fwrite($fh$data); 
fclose($fh);* 
?>
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote
04-10-11, 09:30 PM   #6
Ither
A Firelord
 
Ither's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 497
Shot you a PM with my email, have your friend email me.

Looks like his server may be running an outdated version of PHP.
__________________
  Reply With Quote
04-10-11, 11:26 PM   #7
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
Originally Posted by StormCalai View Post
Shot you a PM with my email, have your friend email me.

Looks like his server may be running an outdated version of PHP.
I fixed it. :3 Nevermind, thank you so much!
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote

WoWInterface » General Discussion » Chit-Chat » A little PHP/HTLM Help?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off