Jump to content

gsashwin

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

gsashwin's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi guys, I am having a tough time executing the code inside the javascript. Everything is working fine with the Php code and I am able to see the output of variable myValue too.. But the problem is nothing is being executed inside the javascript..Not even the first statement of the javascript..When I look at the output sent by the HTML to the browser, the output is what is listed after this code which is right at the bottom of this page. Please advise. <html> <head> <title>AES (Rijndael) Encryption Test in JavaScript</title> <script src="aes-enc.js" type="text/javascript" language="JavaScript"></script> <script src="aes-dec.js" type="text/javascript" language="JavaScript"></script> <script src="aes-test.js" type="text/javascript" language="JavaScript"></script> <script type="text/javascript"> function doDecryption() { document.println("Inside Javascript"); var ct, key; var theForm = document.forms[0]; blockSizeInBits=128; keySizeInBits = theForm.keySize[theForm.keySize.selectedIndex].value; if (theForm.key.value.toLowerCase().indexOf("0x") == 0) theForm.key.value = theForm.key.value.substring(2); if (theForm.ciphertext.value.toLowerCase().indexOf("0x") == 0) theForm.ciphertext.value = theForm.ciphertext.value.substring(2); if (theForm.key.value.length*4 != keySizeInBits) { alert("For a " + keySizeInBits + " bit key, the hex string needs to be " + (keySizeInBits / 4) + " hex characters long."); if (theForm.key.select) theForm.key.select(); return; } if (theForm.ciphertext.value.length*4 != blockSizeInBits) { alert("For a " + blockSizeInBits + " bit block, the hex ciphertext string needs to be " + (blockSizeInBits / 4) + " hex characters long."); if (theForm.ciphertext.select) theForm.ciphertext.select(); return; } ct = hex2s(<?php echo $myValue; ?>); document.println("Inside Javascript"); document.write(ct); // key = hex2s(theForm.key.value); // theForm.plaintext.value = byteArrayToHex(rijndaelDecrypt(ct, key, "ECB")); } </script> </head> [syntax=php] <?php mysql_connect("localhost","root",""); mysql_select_db("encryption") or die(mysql_error()); $userId = $_POST['userId']; if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key'] == "")) { $query = mysql_query("select * from employee_details where id = '$userId'"); if($row=mysql_fetch_assoc($query)) { echo '<tr>'; foreach($row as $value) echo '<td>'.$value.'</td>'; echo '</tr>'; } else { echo "No rows returned"; }} else if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key'])) { $columname = "ciphertext"; $tablename = "employee_details"; function getField($field, $tbl_name, $condition) { $result = mysql_query("SELECT $field FROM $tbl_name WHERE id = ".$condition); return @mysql_result($result, 0); } $myValue = getField($columname,$tablename,$userId); echo "$myValue"; //doDecryption(); } echo '<script type="text/javascript"> doDecryption(); </script>'; echo "whats happening"; ?> </body> </html> [/syntax] <body> CODE THAT IS SENT AS HTML OUTPUT TO THE BROWSWER <!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>AES (Rijndael) Encryption Test in JavaScript</title> <script src="aes-enc.js" type="text/javascript" language="JavaScript"></script> <script src="aes-dec.js" type="text/javascript" language="JavaScript"></script> <script src="aes-test.js" type="text/javascript" language="JavaScript"></script> <script type="text/javascript" language="JavaScript"> function doDecryption() { document.alert("Inside Javascript"); var ct, key; var theForm = document.forms[0]; blockSizeInBits=128; keySizeInBits = theForm.keySize[theForm.keySize.selectedIndex].value; if (theForm.key.value.toLowerCase().indexOf("0x") == 0) theForm.key.value = theForm.key.value.substring(2); if (theForm.ciphertext.value.toLowerCase().indexOf("0x") == 0) theForm.ciphertext.value = theForm.ciphertext.value.substring(2); if (theForm.key.value.length*4 != keySizeInBits) { alert("For a " + keySizeInBits + " bit key, the hex string needs to be " + (keySizeInBits / 4) + " hex characters long."); if (theForm.key.select) theForm.key.select(); return; } if (theForm.ciphertext.value.length*4 != blockSizeInBits) { alert("For a " + blockSizeInBits + " bit block, the hex ciphertext string needs to be " + (blockSizeInBits / 4) + " hex characters long."); if (theForm.ciphertext.select) theForm.ciphertext.select(); return; } ct = hex2s(<br /> <b>Notice</b>: Undefined variable: myValue in <b>C:\wamp\www\AES4U\Decryptedresults.php</b> on line <b>41</b><br /> ); document.write("Inside Javascript"); document.write(ct); // key = hex2s(theForm.key.value); // theForm.plaintext.value = byteArrayToHex(rijndaelDecrypt(ct, key, "ECB")); } </script> </head> <body> <br /> <b>Notice</b>: Undefined index: userId in <b>C:\wamp\www\AES4U\Decryptedresults.php</b> on line <b>58</b><br /> // Do not worry about this notice because teh value has not been posted it is not able find this value. </body>
  2. Thorpe, Thanks thorpe. How do you think should I rearrange the code? Can you give me a brief idea? Sorry for the trouble. But I am running out of ideas and this is frustrating me. Is there any other method other than the header to redirect a page to the other page?
  3. Well I could understand get and post methods through books but I couldn't understand how do I approach this situation of two different submits.. That is the reason why I posted in the forum.
  4. All right I will take that as a constructive criticism but can you tell me the reasons why you told me that so I can analyze my code from next time?
  5. Hi, Thanks for your prompt reply. I have used the one you showed header("Location: Decryption.php?usersubmit=".urlencode($_POST[$usersubmit])); but it still does not print out the usersubmit value in the second page. usersubmit is the name given to the ID textbox in the page 1 code right at the top. Here it goes. Enter your ID<input name="usersubmit" type="text"> <br>
  6. Code for the first page. <?php session_start(); // start up your PHP session! ?> <html> <head> </head> <body> <form name="retrieve.php" action="retrievefieldex11.29.2.56.php" method="POST"> Enter your ID<input name="usersubmit" type="text"> <br> <table><tr> <td><b>Key size in bits: </b></td> <td><select name="keySize"> <option value="128" selected="selected">128</option> <option value="192">192</option> <option value="256">256</option> </select></td> </tr> <tr> <td><b>Key in hex: </b></td> <td><input type="text" size="66" name="key"></td></tr> <tr> <td><b>Ciphertext in hex: </b></td> <td><input type="text" size="66" name="ciphertext"></td> </tr> </table> <?php mysql_connect("localhost","root",""); mysql_select_db("encryption") or die(mysql_error()); $userId = $_POST['usersubmit']; if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key'] == "")) { $query = mysql_query("select * from employee_details where id = '$userId'"); if($row=mysql_fetch_assoc($query)) { echo '<tr>'; foreach($row as $value) echo '<td>'.$value.'</td>'; echo '</tr>'; } else echo "No rows returned"; } else if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key'])) { //header("Location: Decryption.php?name=".urlencode($usersubmit)); //header("Location: Decryption.php?var1=$usersubmit"); header("Location: Decryption.php?usersubmit=".urlencode($_POST($usersubmit))); /* $columname = "ciphertext"; $tablename = "employee_details"; function getField($field, $tbl_name, $condition) { $result = mysql_query("SELECT $field FROM $tbl_name WHERE id = ".$condition); return @mysql_result($result, 0); } $myValue = getField($columname,$tablename,$userId); echo "$myValue"; echo "<br>"; */ } ?> <br> <input name="submit" type="submit" value="Submit"><table> </table> </form> </body> </html></code> Code for the second page: <code><?php session_start(); mysql_connect("localhost","root",""); mysql_select_db("encryption") or die(mysql_error()); $userId = $_GET['usersubmit']; // $userId=$_SESSION['views']; // $userId = $_POST['var1']; $columname = "ciphertext"; $tablename = "employee_details"; echo $userId; //echo $var1; echo "inside decryption"; function getField($field, $tbl_name, $condition) { echo "inside function"; $result = mysql_query("SELECT $field FROM $tbl_name WHERE id = ".$condition); return @mysql_result($result, 0); } $myValue = getField($columname,$tablename,$userId); echo "$myValue"; echo "<br>"; ?>
  7. Hi, I am new to Php and having problems with redirecting of page particularly sending variables across pages. I have this page1 which contains an if else statement. If { User types in two text fields code should be executed and the page should be resubmitted to the same page with database results. For this reason I am using the form attribute of the page and directing the action variable in the form attribute to page1 ( this page itself) on submit. Else { Now if user types in only one text field, it should go to another page wherein the another page should be able to receive the value entered by the user in the page1. I have got suggestions saying I can do this by using page header redirect to another page and concating the value of the textbox to the header variable. I am using this in page 1 <code> header("Location: Decryption.php?usersubmit=".urlencode($_POST($usersubmit))); </code> // Usersubmit is the value entered in the textbox field by the user. and in page 2 <code> $userId = $_GET['usersubmit']; </code> But of no use. I also tried creating a session variable here and using the session variable in the page2. But that does not work either. } Someone please help me. Let me know if you have any questions? Thanks,
  8. Hi, I am trying to print my database records into a php page. I am able to succesfully print the values however the values are being duplicated. For example If I have two records in the employee_details, every these two records are being printed twice on my php page. can anyone tell me the reason why? The output that I see is as follows 7 7 3a7cf5162a9c0a5014c92021e7ca0bf0 3a7cf5162a9c0a5014c92021e7ca0bf0 Bryan Bryan 4111 4111 Admin Admin 6 6 6743c3d1519ab4f2cd9a78ab09a511bd 6743c3d1519ab4f2cd9a78ab09a511bd Raul Raul 601 W Yandell Dr, 601 W Yandell Dr, Admin Admin <html> <head> </head> <body> <?php mysql_connect("localhost","root",""); mysql_select_db("encryption") or die(mysql_error()); $query = mysql_query("select * from employee_details"); ?> <table> <?php for($counter = 0;$row=mysql_fetch_array($query); $counter++) { print ("<tr>"); foreach($row as $key=> $value) print ("<td>$value</td>"); print ("</tr>"); } ?> </table> </body> </html>
  9. Hi, I am very new to PHP and I am trying to execute the below code but getting these errors : Notice: Undefined variable: mysql_query in C:\wamp\www\process.php on line 16 Fatal error: Function name must be a string in C:\wamp\www\process.php on line 16 Code: <html><body> <?php mysql_connect("localhost","root",""); mysql_select_db("encryption") or die(mysql_error()); $username = $_POST['username']; $password = $_POST['password']; $mysql_query("INSERT INTO login (username,password) VALUES ('$username','$password')") or die(mysql_error()); ?> </body></html> ` $_POST['username'] & $_POST['password'] come from a previous page. I have no problem with that. Please help.. Thanks in advance.
×
×
  • 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.