Jump to content

ajoo

Members
  • Posts

    871
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by ajoo

  1. Hi ! I am not sure what you are asking but I'll say what i am doing now. As of now I am using it through the flash IDE on my machine. I have xamp installed and so a local server exists on my machine. But for this example I am using the flash IDE and running my flash file and trying to get the variables into the flash, In fact thats all I am trying to do as of now in this example. Just to get the right variables loaded and displayed in flash. Part of the flash code is given by me in the first message of this thread. Once i get the flash variables correct I do intend to embed the flash in HTML and host it on a server. Still far from there. I hope I have answered your question. If not please ask more. Thanks Mac n all else who would be interested in taking this on.
  2. Hi, Glad to receive a reply. It is encouraging to know that flash is receiving exactly what php is sending to it. Before I post the code i would like to post the output of my php code. hmmm ok this does not permit me to paste a picture( snapshot) of my output so i'll just write it below: =========== Output of the php file =============== var11=4 var12=4 wsc=4wtt=4 Val1=4 Val2=4 Val3=written &db_w_var1=4&db_w_var2=4&db_w_var3=written&db_w_end=0 ====================================================== The last line of the output shows the correct values but when i check the first value in flash w_WS = lvIn1.db_w_var1; and display this one value in a text field in flash I get $db_val1"; as the output. OK so here is the php file <?php $dt = "data1"; //$_POST["dataType"]; // switch ($dt) { case "data1": $var11 = 4; // $_POST["f_var1"]; // 2; debug 4 $var12 = 4; // $_POST["f_var2"]; // 3; debug 5 $var11 = $var11 * 1; $var12 = $var12 * 1; $send_val = array($dt,$var11,$var12); $db_val = get_val($send_val); // break; case "data2": $var21 = 5; //$_POST["f_var1"]; // 2; debug 4 $var22 = 5; //$_POST["f_var2"]; // 3; debug 5 $var21 = $var21 * 1; $var22 = $var22 * 1; $send_val = array($dt,$var21,$var22); $db_val = get_val($send_val); break; default: echo " Bad Choice - cannot identify $datatype"; } // end switch $db_val1=$db_val[0]; $db_val2=$db_val[1]; $db_val3=$db_val[2]; $d_end='0'; //$dbw_WS = $dbw_WS*1; //$dbw_WT = $dbw_WT/1; //$dbw_ST = $dbw_ST; echo "Val1 =".$db_val1; echo "<br>"; echo "Val2 =".$db_val2; echo "<br>"; echo "Val3 =".$db_val3; echo "<br>"; echo "&db_w_var1=$db_val1"; echo "&db_w_var2=$db_val2"; echo "&db_w_var3=$db_val3"; echo "&db_w_end=$d_end"; ////////////////////////////////////////////////////////// function get_val($vals) { $db = "test"; $table = "testdata"; $con = mysqli_connect("localhost","root","",$db); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $dtype = $vals[0]; echo " VALS = ".$dtype; $query = "SELECT * FROM $table WHERE status IS NULL || status = '0' "; mysqli_query($con,$query) or die (mysqli_error($con)); if(mysqli_affected_rows($con)==1) { //a // $result = mysqli_query($con, $query); $row=mysqli_fetch_assoc($result); mysqli_free_result($result); $id = $row['id']; switch($dtype) { case "data1": $var11 = $vals[1]; $var12 = $vals[2]; echo "---------------UPDATEing VAR1---------------"; echo"<br>"; echo " ID = ".$id; echo"<br>"; echo "var11 = ".$var11; echo"<br>"; echo "var12 = ".$var12; echo"<br>"; $query = "UPDATE $table SET var11 = '$var11', var12 = '$var12' WHERE id = '$id'"; $result = mysqli_query($con, $query); // if($result) // { $query = "SELECT * FROM $table WHERE id = '$id'"; $result1 = mysqli_query($con,$query); // // if($result1) { $row=mysqli_fetch_assoc($result1); mysqli_free_result($result1); // $wsc = $row['var11']; $wtt = $row['var12']; $var_result =array($wsc,$wtt,"written"); // echo "wsc = ".$wsc; echo "wtt = ".$wtt; echo " Record VAR1 Inserted. <br>"; } } else{ echo " NOT INSERTED";} break; case "data2": $var21 = $vals[1]; $var22 = $vals[2]; echo "---------------UPDATEing VAR2---------------"; echo"<br>"; echo " ID = ".$id; echo"<br>"; echo"<br>"; echo "var21 = ".$var21; echo"<br>"; echo "var22 = ".$var22; echo"<br>"; $query = "UPDATE $table SET var21 = '$var21', var22 = '$var22' WHERE id = '$id'"; $result = mysqli_query($con, $query); // if($result) // { $query = "SELECT * FROM $table WHERE id = '$id'"; $result1 = mysqli_query($con,$query); // // if($result1) { $row=mysqli_fetch_assoc($result1); mysqli_free_result($result1); // echo " Row = ".$row; $vsc = $row['var21']; $vtt = $row['var22']; $var_result =array($vsc,$vtt,"written"); // mysqli_close($con); echo "vsc = ".$vsc; echo "vtt = ".$vtt; echo " Record VAR2 Inserted. <br>"; } } else{ echo " NOT INSERTED";} break; default : " Cannot recognise the data"; break; } // end switch } // end if else { $query = "SELECT * FROM $table ORDER BY id DESC LIMIT 0,1"; if($result = mysqli_query($con,$query)) { // j $row=mysqli_fetch_assoc($result); $id = $row['id']; } // j end else die(mysqli_error($con)); // $id = $lastrow+1; echo " Before INSERT "; echo " var11 = ".$var11; echo "<br>"; echo " var12 = ".$var12; echo "<br>"; $query = "INSERT into $table ( var11, var12) VALUES ('$var11','$var12')"; $result=mysqli_query($con, $query) or die(mysqli_error($con)); // echo " After INSERT "; echo " id = ".$id; if(!$result){ die( 'Error: ' . mysqli_error($con)); } else { // k // $query = "SELECT * FROM $table WHERE id = '$id'"; $result1 = mysqli_query($con,$query); // or die (mysqli_error($con)); if($result1) { // l $row=mysqli_fetch_assoc($result1); mysqli_free_result($result1); // echo " Row = ".$row; $wsc = $row['var11']; $wtt = $row['var12']; $var_result =array($wsc,$wtt,"written"); echo "wsc = ".$wsc; echo "wtt = ".$wtt; echo " Record Written Inserted. <br>"; } // l end else { die( 'Record not inserted. ERROR: ' . mysqli_error($con)); } } // k end echo " UPDATING SESSION STATUS "; $query = "SELECT * FROM $table WHERE id = '$id'"; $result1 = mysqli_query($con,$query); // or die (mysqli_error($con)); if($result1) { $row=mysqli_fetch_assoc($result1); mysqli_free_result($result1); $WS = $row['var11']; $VS = $row['var21']; } if($WS==1 && $VS==1 ) // { $query = "UPDATE $table SET status = '1' WHERE id = '$id' "; } $result = mysqli_query($con, $query); // or die (mysqli_error($con)); if($result) // { echo " Updated SessionStatus <br>"; } else echo " Could not Update SessionStatus <br>"; } // end get_val return ($var_result); } ?> Hope someone can help me figure this one. I do feel this is a typecast issue but have no idea how to deal with it. Thanks loads for any help which i desperately need here.
  3. loading variables into flash from a php file. Hi guys. I wonder this has been discussed many times & having gone through many such answers I still seem not to get a reply to my problem. So i have a program in flash, which generates a button which when clicked gets a set of variables from a php file called testdata.php. Now this tesfile.php when run standalone generates correct values of variables & displays them. However when i change it to be able to send it to a flash file ( make changes in echo "&db_w_var1=$db_val1"; ) like this. the values I receive in flash are odd. in fact i get this $db_val1";exactly this for the first variable. I get this string instead of receiving an integer value 4 or maybe even a string value '4'. So can anyone looking at this tell me what could be going wrong. The following is a part of code which calls the php file to get the value of variables: var w_WS; // Database returned Written Sums var w_WT; // Database returned Written Time var w_ST; // Database returned Sum Type ( written or visual or oral) var w_end; lv1.dataType = "written"; lv1.w_sums_correct= w_sums_correct; lv1.w_time = w_time; /////////// for localhost /////////////////// lv1.sendAndLoad(path+"testdata.php",lvIn1,"POST"); // sends data values of lv1 variabless // and GETS lvIn1 value /////////// for display on a webpage (_blank) /////////////////// // lv1.send(path + "sessdata1.php", "_blank", "POST"); // or GET lvIn1.onLoad = function(success){ if(success){ w_WS = lvIn1.db_w_var1; w_WT = lvIn1.db_w_var2; w_ST = lvIn1.db_w_var3; w_end = lvIn1.db_w_end; written_data = " WT = "+w_WT; // " WS = "+w_WS + " Type = "+w_ST + "End = "+w_end; } // end success Thanks to all for any help. This has me losing my brains. please help the gurus.
  4. Thanks Mac for your valuable tips. I will keep that in mind as well as the one regarding connecting to the database time n again. I saw my code and indeed there are instances where i close the database connection and then reconnect at another place. Will change those too. Thanks.
  5. ok i did this $result = mysqli_query($con,$query); $row=mysqli_fetch_assoc($result); $lastrow = $row['id']; echo "Last Row found = ".$lastrow."<br>"; and got the result. All i want to know now is that if there's a shorter way to extract the value of the 'id'. Hope this will help many like me who would like to know how to do this. Thanks.
  6. OK !! Thanks guys. You guys were right ! I found the error and the mistake. There were 2 calls to the function. One was called using the correct table name, while there was a typo mistake in the table name in the 2nd call to the function. Thank you all. Jazzman actually pointed out that I should check the table name and i did without realising that there was a typo in the table name in the 2nd call to it. Then I changed as Mac suggested and there it showed me the typo to the table name. Thanks loads. You guys are fantastic and i hope to learn loads from you. Thanks.
  7. Thanks Mac, I'll try this out and revert. Thanks also for the suggestions regarding the opening of databases. I'll keep that in mind. Will revert with the results of your suggestions. Thanks
  8. SELECT id FROM tbl ORDER BY id DESC LIMIT 1 Kindly show How I might extract the value of id into a variable. Thanks.
  9. hmmm well in what i have in mind, no entry in my table is getting deleted. It kind of proceeds linearly. so the last ID would be the same as the number of rows in this case. I must admit that I am very new to mysql and so my questions might be awkward and possibly there may be better solutions. So i am very open to any ideas that i can get. Again chances of crossed linking is zero because each user has a unique table that can only be manipulated by that very person. I hope that in the light of this reply, the questions that I asked are correct. if there is any way to better to do the same I'ld be happy to learn. Thanks I'll try as suggested by trq.
  10. ok my mistake, the actual echo of the query was Select * FROM loginstatus WHERE username = 'yahoo4' AND id = 21. Now that is a valid sql statement i guess. The other 3, yahoo4 21 A are three echo statements displaying id, user & status values of the fields. Ofcourse the table 'loginstatus' exists and snapshot of the last four entries in my last reply was from the 'loginstatus' table. So now why am I getting the Warnings ? Any suggestion , help is welcome. Thanks lots again
  11. by last row i just mean the one having the last or latest id or highest id value or which would be the same as the number of rows in the database. Thanks.
  12. ok I get the following:- Select * FROM loginstatus WHERE username = 'yahoo4' AND id = 21 yahoo4 21 A which is correct !! as can be seen by the last 4 entries of my table loginstatus. 18 yahoo4 X 1374925966 19 yahoo4 X 1374926013 20 yahoo4 X 1374926344 21 yahoo4 A 1374933359 So how can the warnings be removed? Thanks.
  13. hmmm yea sure i can. i will. thanks. I'll revert. Thanks
  14. if only for a cross check. or to get some value from the penultimate row. If i know the last row i can then scan the penultimate row. I hope thats a reason good enuff to elicit an answer. Thanks.
  15. Hi thanks, Sorry if i am bit slow to catch on. But lemme see if i understand this. The warning that i get is Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in functions.php on line 6". So what you mean is that my query is returning a boolean to mysqli_fetch_array() and hence the warning. Is that a good or a bad thing then? Because the result that I get otherwise is correct. And I am getting this warning in the special case where the table would be NULL when no value has been inserted in it. If this is not good then how can i change this ? Ok here is some more of the code along with the previous one. In fact I use the fact that (!row) (that the row return a NULL or is uninitialized) Any more discussion and any solution is welcome. The code: $con = mysqli_connect($db_host, $db_user, $db_pass, $db); if(mysqli_connect_errno($con)) die('Could not connect: '. mysqli_connect_error()); // $query="Select * FROM $table WHERE username = '".$_POST['username']."' && status = A"; $query = "Select * FROM $table WHERE username = '$user' AND id = $id "; // AND id = '$id' AND $result=mysqli_query($con, $query); $row = mysqli_fetch_array($result,MYSQLI_ASSOC); mysqli_free_result($result); if (!$row) { /* Table is empty - - initialization condition ! v! */ $existingId = "Valid"; // Making the Session Valid bcos at this point the login table is empty mysqli_close($con); return($existingId); // and insert the first values in the table.
  16. Hi, thanks for the reply. Well the values are simply values in a table. The user name and ID coud be null for a new table with no entry or there could be name and id entries in the table like say: id user 1 Jack 2 John 3 David & so on. I don't get an error when i run this code. I just get a warning. Further ID is an integer and user is a varchar. My code runs ok but I wanna do away with the warning. Why is $result a boolean ?. I do have a check for an initial value when the table is empty. but when i got the above warnings my table was not empty and so the values for the user and id existed or exist. I hope this can help. The whole code is heaps long. Looking for anyone to take a longer look and see if something can be found. Thanks all.
  17. Hi all ! another simple mysql query to which i never found any satisfactory answer so far. I have a table with four fields. id is auto generated and increases as the table is filled. So i fill the table and say i have 4 entries in it as shown. id name age class 1 aaa 6 1 2 bbb 6 1 3 ccc 7 2 4 ddd 7 2 Now i wish to add the 5th entry but before that i wish to query the database to find how many records have already been entered so far. So whats the best way to get that using php and mysql. i can count the number of rows or i can check for the last vale of id and from there i can know that the next row would be 5 and so would the id be. pls some appropriate code is what i am looking for. beginning wid connecting to the database. ( WHY? cos sql has a nasty habit of throwing Warnings which are difficult to get over) Thanks loads.
  18. Hi everybody, Please can someone check the snippet of code below and say why it generates a warning as "Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in functions.php on line 6". Same warning is generated for the next line i.e. line 7. Ofcourse this is only due to the earlier line i.e. line 6. 1. $con = mysqli_connect($db_host, $db_user, $db_pass, $db); 2. if(mysqli_connect_errno($con)) die('Could not connect: '. mysqli_connect_error()); 3. 4. $query = "Select * FROM $table WHERE username = '$user' AND id = $id "; // AND id = '$id' AND 5. $result=mysqli_query($con, $query); 6. $row = mysqli_fetch_array($result,MYSQLI_ASSOC); 7. mysqli_free_result($result); I have checked the usage of mysqli_fetch_array($result,MYSQLI_ASSOC) on google and it seems to be almost the same. The difference was only in the $query which on w3schools examples was as follows $query ="SELECT Lastname,Age FROM Persons ORDER BY Lastname"; Can someone please help. Thanks all
  19. yes I am talking about the 'Duplicate Tab' option in chrome that opens a duplicate of the page in another Tab. So there is no way for php or javascript to detect that a duplicate TAB has been created of an already open page and there is no way to stop or prevent that using PHP or javascript etc. Please confirm. Thanks all.
  20. Hi guys !! hope all of you are good n doing great ! So i have achieved a login system which i think is secure enuff in the sense that it does not allow multiple logins. It takes care of back arrows and stuff like that and so far i tested the system it is just fine as long as the person is trying to login a 2nd time. It prevents that successfully. However once a person is logged in and is on hiot bs secure page and that person uses the right key to create a duplicate page there or for that matter n duplicate pages, he can do so !!!!!!! Now i am besides myself on trying to find a way to prevent that. How can i prevent the logged in user from duplicating his secured page. I have not been able to come up with anything that can check that. Any suggestions ? I most desperately hope that someone has a solution to that one. Awaiting the response of gurus and senior members. Thanks all in advance for their time, effort and help. Ajoo.
  21. Hello Jessica, thanks for the reply. I thought it was ajax cos i thought .$fetch was a command. I am absolutely unfamiliar with ajax but that came into my head and so i wrote that. However i was interested in that line of code because it seems to be checking for session authentication before a button is clicked. That means the code following the if would be executed if ,in this case the session was valid. This was exactly what i was wanting to achieve in a 'user login system" that i am trying to create. I have asked this in another thread started by me named / called " Another login twister". I hope you can help. Thanks loads.
  22. Hi, what you said is absolutely correct. However I just have a questions. 1. Once a session is destroyed, shouldn't the link and page itself become irrelevant? 2. is there a way by which, the hyperlink upon being pressed, should first check if the session is valid and only then move to the next page which in my case is Mypage? So i want the authentication to take place on the securedpage.php instead of going onto the Mypage and checking for it there. Yes i did realise that my page would be directly accessible thru a hyperlink but this was just for the sake of an illustration. In an application that page would check for further authentication. Thanks for all the replies so far. I do hope others would joinin too with their valuable suggestions and ideas. Thanks all !
  23. Hi Fahad, I just came across your snippet question and I think I could use a similar solution. Ofcourse I am trying to find a solution to a login issue. Ithink the $fetch command in your php is an ajax implimentation. Can you please quickly explain how this line of code works. Thats all I want to know. Thanks.
  24. I thought I would illustrate this with a small demo program. I am sure other would have come against something like this and found a way around it. This involves five small files for a login syste. 1. Index.php 2. loginproc1.php 3. securedpage.php 4. loggedout.html. 5. Mypage.html. It does not make use of a database but accepts only one user namely "John" with password - actually password is irrelevant for this illustration but i use 1234. So typing the url "localhost/xampp/sessions/index.php" will open a login form. Once I login using USER as John and password 1234, loginproc1 takes me to securedpage.php if i am not already logged in. Now I open another browser window and as soon as i put in the url "localhost/xampp/sessions/index.php" it immediately goes to the loggedout.html which is displayes and says that since ur already logged in ur being logged out. So i am logged out. But since i am logging in from another tab of the same browser, I am actually logged out of both sessions since both sessions in this case ( on different tabs of the same browser ) are considered as one and the same. At this point I have two pages on the two tabs. secured Page on the 1st tab and loggedout Page on the 2nd tab of my browser and effectively i should be logged out and the sessions ( actually session - since both are one and the same) destroyed. However if you now go to the secured page ( 1st Tab of the broswer) , you can still see the link to MyPage on it, which if clicked on would take us to the contents of Mypage.html even though envoking the the url "localhost/xampp/sessions/index.php" , in the 2nd tab of my browser has effectively destroyed the session. I want to prevent the link to MyPage from working once the session is destroyed. How can this be achieved. SInce I have attached the code files I would be glad if someone can actually do this one here and demonstrate it. Thanks loads to all for any help that i would receive on this one. The code files :- INDEX.PHP <?php //////// INDEX.PHP ///////////// // Inialize session session_start(); // Check, if user is already login, then jump to secured page if (isset($_SESSION['username'])) { echo $_SESSION['username']. "Already Logged in @ index 8"; echo " You are being logged out as you have logged in from another page "; session_destroy(); header('Location: loggedout.html'); exit(); } else { echo " Hi new user ";} ?> <html> <head> <title>PHPMySimpleLogin 0.3</title> </head> <body> <h3>User Login</h3> <table border="0"> <form method="POST" action="loginproc1.php"> <tr><td>Username</td><td>:</td><td><input type="text" name="username" size="20"></td></tr> <tr><td>Password</td><td>:</td><td><input type="password" name="password" size="20"></td></tr> <tr><td> </td><td> </td><td><input type="submit" value="Login"></td></tr> </form> </table> </body> </html> <?php ////// loginproc1.php ////// // Inialize session session_start(); // Include database connection settings include('config.inc'); if (isset($_SESSION['username'])) { echo $_SESSION['username']. "Already Logged in @ index 8"; echo " You are being logged out as you have logged in from another page "; session_destroy(); header('Location: loggedout.html'); exit(); } else { echo " Hi new user ";} $_SESSION['username'] = $_POST['username']; if($_SESSION['username'] == "John") { header('Location: securedpage.php'); exit(); } else { // Jump to login page echo " Can't find you"; //header('Location: index.php'); } ?> SECUREDPAGE.PHP <?php ///// SECUREDPAGE.PHP /////// // Inialize session session_start(); // Check, if username session is NOT set then this page will jump to login page if (!isset($_SESSION['username'])) { header('Location: index.php'); exit(); } else { echo " Welcome". $_SESSION['username']; } ?> <html> <head> <title>Secured Page</title> </head> <body> <p>This is secured page with session: <b><?php echo $_SESSION['username']; ?></b> <br>You can put your restricted information here.</p> <p> You can jump to your page <a href = "mypage.html">MyPage </a> </p> <p><a href="logout.php">Logout</a></p> </body> </html> This is content of ‘securedpage.php’: <? LOGGEDOUT.HTML <html> <head> <title>Loggedout Page</title> </head> <body> <p> <?php echo $_SESSION['username']. ?> "Already Logged in @ index 8"; <p> " You are being logged out as you have logged in from another page "; <p><b><?php echo $_SESSION['username']; ?></b> you are logged out. <br>You cannot put any kind of information now.</p> </body> </html> MYPAGE.HTML <!DOCTYPE html> <html> <head> <title> MyPage </title> </head> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html>
  25. Hi guys, I am back with another login twister. Earlier i tried to create a yahoo like login system which ensured that a given user was logged in only on one machine even if that user tried to do a multiple login from same or different machines. So after a great deal of effort and with a lot of support from the forum i decided it would be best to not allow a second , the new login, at all if the user was logged in. So the new login fails saying that the user is already logged in. I am now using a sliding jquery login panel that i picked up from the net and i tried and implement this new logic and guess what ? I ran into another issue. So the panel works fine. I'll put the login procedure in steps; 1. I input the username and password and I login. The initial screen provides the username and password and a login button. Also a registration form for a new login registration. The display shows Guest for user. 2. The user logs in & is greeted by his 'username' that it picks from a database. When the panel is expanded it now opens to a new page ( say PAGE 1) which has two hyperlinks: a) to play a movie and b) to logout. 3. Both work fine. So far so good. 4. Now I run the login page again in a new tab and because an instance of it is already running, it opens on PAGE 1 which has the two hyperlinks a) movie and b) to logout. Since the panel is running sessions and since i am running the two on the two tabs of a browser, the sessions would ensure that the session values are the same for the instances in both tabs. 5. Now I logout from the 2nd (newer) tab. ( actually since there are two instances running on the two tabs of the same browser I can logout of either.) The sessions is destroyed and the logout page is displayed. Since the sessions are destroyed, they must be destroyed from both instances. At this point of time the first instance / tab is still showing the PAGE1 as it should but it is now a dead session. However now when i press the a) option, the hyperlink to a movie, it plays !!!!! WHY should the movie play when the session is destroyed. 6. So in effect, while i am effectively logged out because of a logout command in one of the two tabs of the browser, the hyperlink to the movie in the other tab is still active. which is a great flaw i think. I mean it should not behave like that. So does anyone have any idea why this is happening and how it may be over come?? A bit of code showing that which makes the PAGE 1 <div class="left"> <h1>Members panel</h1> <p>You can put member-only data here</p> <a href="registered.php">View a special member page</a> <p>- or -</p> <a href="?logoff">Log off</a> </div> registered.php actually runs a movie - the a) option - or the user can logoff - the b) option Please HELP, stuck on this one again.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.