
mpsn
Members-
Posts
264 -
Joined
-
Last visited
Everything posted by mpsn
-
I want to save files to a directory. I am using a input type="text" to let user paste directory, then they choose the file from an upload form, then press submit. So here is my script: ============== <form method="post" action="" enctype=...> <input type="text" name="textboxDir" /> <input type="file" name="uploadedFile"/> </form> So how do I now save the uploaded file via $_POST['uploadedFile'] to the text box directory: $_POST["textBoxDir"]? Any help much appreciated!
-
Hi, I am building a learning site for kids. On this page, 1)there's a textbox to choose the directory to save the list of new words they learnt 2)an HTML table that displays all the words they have stored to db (they choose the words to store to directory via checkboxes next to each word in this HTML table) 3)then they click submit and it stores these new words they can use to file in their specified directory. My quesiton is should I use $_GET or $_POST? (somehow I think I need to output the primary key in step 2) for query string, so maybe I should also store directory that user types in textbox as query string too? Any help much appreciated!
-
Hi, I know how to use an upload form: <form enctype='multipart/form-data'>";> <input type="file" /> </form> BUT what if I want to have a "save to" form, so they click a button and they choose the directory to save to. Any help much appreciated!
-
I thought about turning on magic quotes BUT it escapes everything which can get hairy, so I think better to just do it manually, but then what's difference b/t mysql_real_escape_string VS addslashes()?
-
Thanks for the heads up, but then what is the purpose of hidden input type then?
-
Sorry, that is what I meant. So continuing with my scripts, do you see what I am doing incorrectly? Any help much appreciated!
-
Hi, I think i'm ok, it's context specific: eg: if I have email message: <email> <to/> <from/> <message/> </email> *so it doesn't make sense if a user uses this XML and defines just a message first without a to and from field. Anways, I really hope you can take a look at my other post, it's very simple so I don't know why I'm stuck: When a user logs out, it will timestamp the current date/time to a lastSession field in my db table users. When the same user logs in again, in my Index.php, it should output: "Last session: 2011-11-19", please I hope you can help me out! I'd appreciate it. **Just look at Reply #7** http://www.phpfreaks.com/forums/index.php?topic=347908.0
-
Can someone please explain to me what's the importance of node order? Does certain nodes that appear first or last have impact on traversing time? Any suggestions much appreciated!
-
I figured it out, if I have: $originalString=car/red/blue/gun/hit then just use: $originalStringToArray=explode("/",$originalString); $firstItem=$originalStringToArray[0] Done!
-
Hi, how do I extract a substring? I just want to store "car" in a variable for other uses: Here is the original string: car/red/blue/gun/hit Any help much appreciated!
-
Please, please can someone help me, I just want to store the current timestamp when user logs out and then when they log back in, on the Index.php, it will show the Last Session fetching info from the NOW() value stored during logout. Any help much appreciated!
-
:'( Please, please why won't people help out? I just want to get it to check if the desired webpage has the content via assertText, but it doesn' work when I run it. At first I thought it was local host but I tested that via: $this->assertTrue($this->get("localhost/projidr/Whatever.php")) I beg, I beg someone to help me!! Any help much appreciated!
-
Hi, when a user logs out, I want to store the last activity in for the user. I have a db table users: userID userName userPassword lastSession lastActivity ===== ======= ========== ======== ======= 1 bob password 2011-08-09 About.html 2 dre passwords 2011-09-23 Home.php here is logout script: =============== <?php //run this script only if the logout button has been clicked if(array_key_exists('logout', $_POST)) { require("connect.inc"); $username=$_POST["username"]; $updateLastSessionQuery=mysql_query("UPDATE users SET lastSession=NOW() WHERE userName='$username'"); // end session and redirect //empty the $_SESSION array $_SESSION = array(); session_destroy(); header("Location: xmlShredderLogin.php"); exit; }//END IF for when logout submitted ?> here is Index.php: ============= <?php session_start(); if(isset($_SESSION["isAuthenticated"])) { require("logout.inc.php"); $username=$_POST["username"]; //print $username."<br />"; print ' <html> <head><title>Home</title></head> <body> <form id="logoutForm" name="logoutForm" method="post" action=""> <input name="logout" type="submit" id="logout" value="Log out" /> <input type="hidden" name="usernameHidden" value='; print$username; print '/> </form>'; mysql_connect("localhost","root"); mysql_select_db("someDB"); $getUserInfoQuery=mysql_query("SELECT lastSession,lastActivity FROM users WHERE userName='$userName'"); $getUserInfo=mysql_fetch_assoc($getUserInfoQuery); print "Last session: ".$getUserInfo["lastSession"]."<br />"; print "Last activity: ".$getUserInfo["lastActivity"]."<br />"; Let's say the last page the user is on is Index.php, so what do I use to track the last page they are on?? I can't user a form b/c if I have to type in the last activity, that's nonsense! So far I have only figured out how to store the current time in last session (but this doesn't work either). I just want to track the last page and then have a switch such as: switch(type) case 1: $lastActivity="About.html"; case 2: $lastActivity="somethingelse.php"; Any help much appreciated!
-
I don't want to repost as new topic, so please can someone help me out! I just want to be able to logout, and once logged out store current timestamp, so that when the same user logs in again, it will display on Index.php the last session timestamp. Any help much appreciated!
-
I beg anyone to please help a new php programmer out! I even tried contacting the creater of SimpleTest, he doesn't respond. Any help much appreciated!
-
No, that's not it, b/c when I try the following assertion on the get: $this->assertTrue($this->get("localhost/proj_ath/xmlShredderIndex.php")); it returns: PASS 1, FAIL 1 (the get passed, the assertText fails, I know b/c I commented out the assertText and I still get PASS 1) in the command line (this is just SimpleTest output) Any help much appreciated!
-
Thanks, ok here's another problem. I just made a logout page and updated the db users table to hold each users last session (a datetime type). So I used a hidden input type in Index.php BUT and set up the query to add the time as so in the disconnect script, BUT now when I click the login script, it says I am not logged in! (for the Index.php. So that everything is all here, here's the scripts: Login ===== <html> <body> <form method="post" action="Index.php"> <p> <label>Username:</label> <input type="text" name="username" size="10"> </p> <?php //if username/password filled in and submitted, check db to find match login info if(array_key_exists("Login",$_POST) && !empty($_POST["username"]) && !empty($_POST["password"])) { $attemptedUsername=$_POST["username"]; $attemptedPassword=sha1($_POST["password"]); mysql_connect("localhost","root"); mysql_select_db("someDB"); $getLoginInfoQuery=mysql_query("SELECT userName,userPassword FROM users WHERE userName='$attemptedUsername' AND userPassword='$attemptedPassword'"); if(mysql_num_rows($getLoginInfoQuery)==1) { session_start();//NB: Start session BEFORE doing any session stuff! $_SESSION["isAuthenticated"]="userAuthenticated"; } else//"Please register above!" print "Please register above!"; } if(array_key_exists("Login",$_POST) ) { if(empty($_POST["username"]) && empty($_POST["password"])) print "Please fill in a username and password! <br />"; else if(empty($_POST["password"])) print "<Please fill in a password!<br />"; else if(empty($_POST["username"])) print "Please fill in a username! <br />"; } ?> <p> <label>Password:</label> <input type="password" name="password" size="10"> </p> <p> <input type="submit" value="Login" name="Login" /> <input type="reset" value="Reset" name="Reset" /> </p> </form> </body> </html> Index.php: (Here is where I put the hidden input type to be able to link with disconnect.php) ======== <?php session_start(); if(isset($_SESSION["isAuthenticated"])) { require("disconnect.inc.php"); $attemptedUsername=$_POST["username"]; print ' <html> <head><title>Home</title></head> <body> <form id="logoutForm" name="logoutForm" method="post" action=""> <input name="logout" type="submit" id="logout" value="Log out" /> <input type="hidden" name="attemptedUsernameHidden" value=';print $attemptedUsername; print '/> </form>'; mysql_connect("localhost","root"); mysql_select_db("someDB"); $userName=$_POST["username"]; print ' <p> Last session:'; $getUserInfoQuery=mysql_query("SELECT lastSession,mostRecentActivity FROM users WHERE userName='$userName'"); $getUserInfo=mysql_fetch_assoc($getUserInfoQuery); print $getUserInfo["lastSession"]."<br />"; print "Last activity: ".$getUserInfo["mostRecentActivity"]."<br />"; print ' </p> </body> </html>'; } else { print "You must be registered or logged in to continue."; print "<hr />"; print "<a href='xmlShredderRegister.php'>Create account</a> <br />"; print "<a href='xmlShredderLogin.php'>Login</a>"; } ?> Finally, here is disconnect.php: ====================== <?php //run this script only if the logout button has been clicked if(array_key_exists('logout', $_POST)) { mysql_connect("localhost","root"); mysql_select_db("someDB"); $attemptedUsername=$_POST["username"];//**THIS SHOULD HAVE CARRIED OVER FROM THE hidden input type in Index.php!!! $updateLastSessionQuery=mysql_query("UPDATE users SET lastSession WHERE userName='$attemptedUsername'"); // end session and redirect //empty the $_SESSION array $_SESSION = array(); session_destroy(); header("Location: login.php"); exit; }//END IF for when logout submitted ?> Any help much appreciated!
-
Yes, I forgot about session_start must come before all code that is based on the session. Thanks. Now I have a new problem, I noticed that each time the user enters either one field (username or password), it displays the appropriate messge ("Please fill in username/password"), BUT when they click the submit (login) it also resets the field where text typed in already, so how do I make it so that if only one field is entered, to display the message of course, AND NOT reset the currently entered field? Any help much appreciated!
-
Can someone help me with SimpleTest for HTML. I just want to test if a certain page has the text in it, but when I run this SimpleTest script for the page I'm testing (Index.html), it outputs this message: "Text [Hello world!.]" not detected in [string: Bad request! Bad request! Your browser (or proxy) sent a request that this server could not understand. Error 400]" Here is script Index.html: ================= <html> <head></head> <body <p>Hello world!</p> </body> </html> Here is SimpleTest script for testing Index.html: ================================= <?php require_once('simpletest/autorun.php'); require_once('simpletest/web_tester.php'); require_once('Index.html'); class TestOfIndex extends WebTestCase { function testHomeHasTheseLinks() { $this->get("localhost/dir/Index.html"); $this->assertText('Hello world!'); } } ?> Any help much appreciated!
-
I decided to use sha1(), but now when the login info is successful on login.php, the SecureSite.php for some reason does not recognize a session has been created(it should). Login script: ======== <?php //if username/password filled in and submitted, check db to find match login info if(array_key_exists("Login",$_POST) && !empty($_POST["username"]) && !empty($_POST["password"])) { $attemptedUsername=$_POST["username"]; $attemptedPassword=sha1($_POST["password"]); mysql_connect("localhost","root"); mysql_select_db("someDB"); $getLoginInfoQuery=mysql_query("SELECT userName,userPassword FROM users WHERE userName='$attemptedUsername' AND userPassword='$attemptedPassword'"); if(mysql_num_rows($getLoginInfoQuery)==1) { session_start();//NB: Start session BEFORE doing any session stuff! $_SESSION["isAuthenticated"]="userAuthenticated"; header("Location: secureSite.php"); exit; } else//"Please register above!" print "Please register above!"; } ?> Here is register script: ================ <?php if(array_key_exists("makeAccountSubmit",$_POST) && !empty($_POST["newUsername"]) && !empty($_POST["newPassword"]) ) { //IF username doesn't exist, then store new user login info to db dummydpevx mysql_connect("localhost","root"); mysql_select_db("someDB"); $newUserName=$_POST["newUsername"]; $newPassword=sha1($_POST["newPassword"]); $usernameQuery=mysql_query("SELECT userName FROM users WHERE userName='$newUserName'"); if(mysql_num_rows($usernameQuery)==0) { $makeNewAccountQuery=mysql_query("INSERT INTO users (userName,userPassword) VALUES('$newUserName','$newPassword')"); print "You are now registered, <a href='login.php'>proceed to login</a>"; } //ELSE IF username exists already, "Username already taken, please enter another BUT KEEP IN MIND user can have any passwords (EVEN IDENTICAL ONES b/c doesn't make sense to say password exists (this will help hackers have easier time hacking!) if(mysql_num_rows($usernameQuery)==1) print "Username taken. Please make another one. <br />"; } if(array_key_exists("makeAccountSubmit",$_POST) ) { if(empty($_POST["newUsername"]) && empty($_POST["newPassword"])) print "Please fill in a username and password! <br />"; else if(empty($_POST["newPassword"])) print "Please fill in a password!<br />"; else if(empty($_POST["newUsername"])) print "Please fill in a username! <br />"; } ?> Here is the secureSite.php (session should have started, since it redirected me to secureSite.php BUT it displays: "You must be registered or logged in..." which doeesn't make sense since the redirect to THIS page means that the user's password was correct... <?php if(isset($_SESSION["isAuthenticated"])) { session_start(); print "YOU ARE ACCESSING SECURE DATA!" else { print "You must be registered or logged in to continue."; print "<hr />"; print "<a href='xmlShredderRegister.php'>Create account</a> <br />"; print "<a href='xmlShredderLogin.php'>Login</a>"; } ?> Please I'd appreciate any help!
-
Hi, I want to store login info and create account, but when after I create account, I can't log in, it still displays: "Please register above!" login script: ======== <html> <head> <title>Login</title> </head> <body> <hr /> <form method="post" action=""> <label>Username:</label> <input type="text" name="username"> <br /> <label>Password:</label> <input type="password" name="password"> <p> <input type="submit" value="Login" name="Login" /> <input type="reset" value="Reset" name="Reset" /> </p> </form> <?php //if username/password filled in and submitted, check db to find match login info if(array_key_exists("Login",$_POST) && !empty($_POST["username"]) && !empty($_POST["password"])) { $attemptedUsername=$_POST["username"]; $attemptedPassword=crypt($_POST["password"]); mysql_connect("localhost","root"); mysql_select_db("dummydpevx"); $getLoginInfoQuery=mysql_query("SELECT userName,userPassword FROM users WHERE userName='$attemptedUsername' AND userPassword='$attemptedPassword'"); $getLoginInfo=mysql_fetch_assoc($getLoginInfoQuery); $getUsername=$getLoginInfo["userName"]; $getPassword=crypt($getLoginInfo["userPassword"]); if($attemptedPassword==$getPassword) { session_start();//NB: Start session BEFORE doing any session stuff! $_SESSION["isAuthenticated"]="userAuthenticated"; header("Location: SecureSite.php"); exit; } else//"Please register above!" print "Please register above!"; } ?> </body> </html> here is register script: =============== <html> <head> <title>Register</title> </head> <body> <form method="post" action="" > <p>Create a username <input type="text" name="newUsername" size="10" /> </p> <p>Create a password <input type="password" name= "newPassword" size="10" /> </p> <p> <input type="submit" value="Make account now" name="makeAccountSubmit" /> </p> </form> <?php if(array_key_exists("makeAccountSubmit",$_POST) && !empty($_POST["newUsername"]) && !empty($_POST["newPassword"]) ) { //IF username doesn't exist, then store new user login info to db dummydpevx mysql_connect("localhost","root"); mysql_select_db("someDB"); $newUserName=$_POST["newUsername"]; $newPassword=crypt($_POST["newPassword"]); $usernameQuery=mysql_query("SELECT userName FROM users WHERE userName='$newUserName'"); if(mysql_num_rows($usernameQuery)==0) { $makeNewAccountQuery=mysql_query("INSERT INTO users (userName,userPassword) VALUES('$newUserName','$newPassword')"); print "You are now registered, <a href='login.php'>proceed to login</a>"; } //ELSE IF username exists already, "Username already taken, please enter another BUT KEEP IN MIND user can have any passwords (EVEN IDENTICAL ONES b/c doesn't make sense to say password exists (this will help hackers have easier time hacking!) if(mysql_num_rows($usernameQuery)==1) print "Username taken. Please make another one. <br />"; } if(array_key_exists("makeAccountSubmit",$_POST) ) { if(empty($_POST["newUsername"]) && empty($_POST["newPassword"])) print "Please fill in a username and password! <br />"; else if(empty($_POST["newPassword"])) print "Please fill in a password!<br />"; else if(empty($_POST["newUsername"])) print "Please fill in a username! <br />"; } ?> </body> </html> Please I would appreciate any help, thanks!
-
Please help me, why doesn't it store to db if it outputs: "You are now registered!" Any help much appreciated!
-
Hi, now I have a new problem, I don't know why the $_POST array is empty when I have uploaded content. I have three scripts (1st: ask users how many upload pairs they want (an XML file must be accompanied by an XSD file; 2nd: dispaly the total upload form pairs; 3rd: the upload pairs with content user uploaded will be validated before storing to db) First script: (ask user to enter total number upload pairs) ======= <?php <form method="DisplayMultipleUploads.php" action="post"> <input type="text" name="numUploadPairs" /> <input type="submit" name="SUBMIT" name="numUploadPairsSubmit"/> </form> if(array_key_exists("numUploadPairsSubmit", $_POST) && !empty($_POST["numUploadPairs"])) { header("Location: showUploadForms.php"); exit; } ?> Second script: (showUploadForms.php): ============================ <?php $numUploadPairs=$_POST["numUploadPairs"]; print "<form action='storeToDB.php' method='post' enctype='multipart/form-data'>"; for($i=0;$i<$numUploadPairs;$i++) { print '<p> <label> Upload XSD file #'.$i; print '<input type="file" name="uploadedXSDFile".'.$i; print 'value="uploadedXSDFileValue" id="imageFileType" /> </label> </p>i <p> <label>'; print 'Upload an XML file #'.$i; print '<input type="file" name="uploadedXMLFile"'.$i; print 'value="uploadedXMLFileValue" id="imageFileType" /> </label> <input type="hidden" name="numUploadsHidden" value=';print $numUploadPairs; print '/> </p>'; print "-----------------------------------------------------------<br />"; }//END WHILE LOOP for build XSD:XML upload form pairs print "<p> <input type='submit' name='multipleUploadSubmit' value='STORE to DB NOW'/> </p>"; print '</form> <br />'; ?> Third script: (storeToDB.php): ===================== <?php //user's total desired upload pairs $numActualUploads=chop($_POST["numUploadsHidden"], "/");//chop removes char to right of first param string //TEST to make sure $_POST['uploadedXSDFile'.i] and $_POST['uploadedXMLFie'.i] exist for($i=0;$i<$numActualUploads;$i++) { //ONLY print the uploaded forms where XSD:XML pairs BOTH HAVE ACTUAL CONTENT! if(!empty($_POST['uploadedXSDFile'.$i]) && !empty($_POST['uploadedXMLFile'.$i]) ) { print 'cur XSD:'.$_POST['uploadedXSDFile'.$i].':'; print 'cur XML:'.$_POST['uploadedXMLFile'.$i]; } else print "Nay <br />"; } ?> For the third script, I thought I check first if the $_POST even have uploaded content, it turns they don't, so it just prints: "Nay" Any help much appreicated!
-
Hi, I am converting XML to DB and was wondering is it bad XML structure to have twin siblings (or triplets or identical siblings in general), what I mean is: eg: <email> <to> <toFirstName>John</toFirstName> <toLastName type="common">Smith</toLastName> </to> <to> <toFirstName>Jack</toFirstName> <toLastName type="unique">Dravisone</toLastName> </to> </email> Any help much appreciated!
-
Hi, this the error I get: Equal expectation fails at character 0 with [My Page:Home] and [bad requrest!] at [C:\xampp\htdocs\path\way\to\this\script for line 9] line 9 is my assertion: $this->assertTitle b/c I am pretty sure assertTitle checks the <title> tag