value pass from one script to another script

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Apr 2008
Posts: 5
Reputation: thirusvga is an unknown quantity at this point 
Solved Threads: 0
thirusvga thirusvga is offline Offline
Newbie Poster

value pass from one script to another script

 
0
  #1
Apr 23rd, 2008
Hi.. I am new in php +ajax.....Now i am doing project in php+ajax+linux environment...i create a login page using php,ajax,mysql,, i have mysql tables are. register,slideshow,,,,,In register table having following field...
1.uid (autoincrement)2.first (firstname)3.last(surname)4.user(username),5.pass(password)
In slide show table having following field,,,
1.uid 2.pid(presentation id,autoincrment) 3.slideno 4.description 5.location(this is what image file is store that particular location)..
my login programs are..
//login.html
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <script language="javascript" type="text/javascript">
  4. //Browser Support Code
  5. function ajaxFunction()
  6. {
  7. var ajaxRequest; // The variable that makes Ajax possible!
  8.  
  9. try
  10. {
  11. // Opera 8.0+, Firefox, Safari
  12. ajaxRequest = new XMLHttpRequest();
  13. }
  14. catch (e)
  15. {
  16. // Internet Explorer Browsers
  17. try
  18. {
  19. ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
  20. }
  21. catch (e)
  22. {
  23. try
  24. {
  25. ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
  26. }
  27. catch (e)
  28. {
  29. // Something went wrong
  30. alert("Your browser broke!");
  31. return false;
  32. }
  33. }
  34. }
  35.  
  36. // Create a function that will receive data sent from the server
  37. ajaxRequest.onreadystatechange = function()
  38. {
  39. if(ajaxRequest.readyState == 4)
  40. {
  41. var ajaxDisplay = document.getElementById('ajaxDiv');
  42. ajaxDisplay.innerHTML = ajaxRequest.responseText;
  43. document.getElementById('message').style.visibility = 'hidden';
  44. }
  45. }
  46.  
  47. var user= document.getElementById('user').value;
  48. var pass= document.getElementById('pass').value;
  49. var queryString = "?user=" + user + "&pass=" + pass;
  50. document.getElementById('message').style.visibility = 'visible';
  51. ajaxRequest.open("GET","login.php" + queryString, true);
  52. ajaxRequest.send(null);
  53.  
  54. }
  55. </script>
  56. </head>
  57. <body>
  58. <div id="message" style="position:absolute; top:1%; left:95%; margin-left:-100px; font-size:14;background-color: red ;color: white;width: 165px; height: 25px; overflow: auto;visibility: hidden">Executing...</div>
  59. <form>
  60. <center>
  61. <img src="" style="visibility:hidden" width="0%" height="0%">
  62. <table border="0" bgcolor="#CCCCFF" cellspacing="1" cellpadding="3" width="287">
  63. <tr>
  64. <td align="left" colspan="2" width="275"><b><font size="5" color="#000080">Login</font></b></td>
  65. </tr>
  66. <tr>
  67. <td align="right" width="81"><b><font color="#000080">User
  68. Name:</font></b></td>
  69. <td width="184">
  70. <input type="text" id="user">
  71. </td>
  72. </tr>
  73. <tr>
  74. <td align="right" width="81"><b><font color="#000080">Password:</font></b></td>
  75. <td width="184">
  76. <input type="password" id="pass">
  77. </td>
  78. </tr>
  79. <tr>
  80. <td colspan="2" align="center" width="275"><input type="button" onclick="ajaxFunction()" value="Login" ></td>
  81. </tr>
  82. </table>
  83. <div id="ajaxDiv">&nbsp;
  84. </center>
  85. </form>
  86. </body>
  87. </html>
  88. //login.php
  89. <?php
  90. $user=$_GET['user'];
  91. $pass=$_GET['pass'];
  92. $conn = mysql_connect("localhost","root","") or die("could not connect server");
  93. $db = mysql_select_db("thiru",$conn) or die("could not connect database");
  94. $query= "select * from register";
  95. $res = mysql_query($query) or die("query failed" . mysql_error());
  96. $num_rows=mysql_num_rows($res);
  97. while($rr=mysql_fetch_array($res))
  98. {
  99. if($user==$rr[3] && $pass==$rr[4])
  100. {
  101. //get uid
  102. $insert=$rr[0];
  103. //echo"welcome" .$user;
  104. $flag=true;
  105. }
  106. }
  107. if($flag==false)
  108. {
  109. echo"userid and password mismatch";
  110. }
  111. mysql_close($conn);
  112. ?>
The above program is successfully logged .. and i fetch uid in $insert variable...This is my quetion...
uid,pid,slideno,description,location will be stored automaticallyin slideshow table..while i upload file....
my upload proram is given below...
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. //upload.html file
  2. <html>
  3.  
  4. <head>
  5.  
  6. <script type="text/javascript" language="javascript">
  7. function upload()
  8. {
  9.  
  10. var oForm = document.uploadform;
  11. oForm.submit();
  12. }
  13. </script>
  14.  
  15. </head>
  16.  
  17. <body>
  18.  
  19. <div id="message" class="drag" style="position:absolute; top:50%; left:50%; margin-left:-100px; font-size:12;background: transparent;
  20.  
  21. width: 75px; height: 75px; overflow: auto; visibility: hidden">
  22.  
  23. </div>
  24.  
  25. <center>
  26.  
  27. <form name="uploadform" action="upload.php" method="POST" ENCTYPE="multipart/form-data" target="hiddenFrame">
  28. Open :
  29. <input style="font:normal 10px Verdana" size="35" align="left" type="file" name="code" id="code">&nbsp;&nbsp;&nbsp;&nbsp;<br><button onClick="upload();return false">Upload</button>
  30.  
  31. </form>
  32.  
  33. <iframe src="about:blank" name="hiddenFrame" width="400" height="400"
  34.  
  35. frameborder="1" ></iframe>
  36.  
  37. </center>
  38.  
  39. </body>
  40.  
  41. </html>
  42.  
  43. //upload php file
  44. <?php
  45. $uploaddir='/var/www/html/upload/';
  46. $uploadfile=$uploaddir.basename($_FILES['code']['name']);
  47. echo '<pre>';
  48. if (move_uploaded_file($_FILES['code']['tmp_name'], $uploadfile))
  49. {
  50. echo "File was successfully uploaded.\n";
  51. print "</pre>";
  52. $conn=mysql_connect("localhost","root","");
  53. $db=mysql_select_db("thiru");
  54. $query = "insert into slide(sloc)values('$uploadfile')";
  55. $result=mysql_query($query);
  56. echo"<br>";
  57. mysql_close($conn);
  58. $filename=$_FILES['code']['name'];
  59. echo"filename:";
  60. echo $filename;
  61. echo"<br>";
  62. }
  63. else
  64. {
  65. echo "please choose a correct file!!";
  66. }
  67.  
  68. ?>
please send me the correct coding ..
Last edited by ~s.o.s~; Apr 23rd, 2008 at 2:46 pm. Reason: Added code tags, learn to use them.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC