passing parameter in sql query by page

Reply

Join Date: Jan 2009
Posts: 125
Reputation: blocker is an unknown quantity at this point 
Solved Threads: 0
blocker's Avatar
blocker blocker is offline Offline
Junior Poster

passing parameter in sql query by page

 
0
  #1
Feb 13th, 2009
Good day.!

I am having problem with passing the parameter value. I have a page called index.php. This page has a textbox named "username" when the user login and type his/her user name in the textbox named "username" i want the data of that user to be displayed in the next page called enrolselection.php. I have already a recordset in the index.php which holds the login statement. below is the recordset:

  1.  
  2. if (!isset($_SESSION)) {
  3. session_start();
  4. }
  5.  
  6. $loginFormAction = $_SERVER['PHP_SELF'];
  7. if (isset($_GET['accesscheck'])) {
  8. $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  9. }
  10.  
  11. if (isset($_POST['username'])) {
  12. $loginUsername=$_POST['username'];
  13. $password=$_POST['password'];
  14. $MM_fldUserAuthorization = "";
  15. $MM_redirectLoginSuccess = "enrolselection.php";
  16. $MM_redirectLoginFailed = "invaliduser.php";
  17. $MM_redirecttoReferrer = false;
  18. mysql_select_db($database_enamysqldb, $enamysqldb);
  19.  
  20. $LoginRS__query=sprintf("SELECT username, password FROM studentregistration WHERE username=%s AND password=%s",
  21. GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  22.  
  23. $LoginRS = mysql_query($LoginRS__query, $enamysqldb) or die(mysql_error());
  24. $loginFoundUser = mysql_num_rows($LoginRS);
  25. if ($loginFoundUser) {
  26. $loginStrGroup = "";
  27.  
  28. //declare two session variables and assign them
  29. $_SESSION['MM_Username'] = $loginUsername;
  30. $_SESSION['MM_UserGroup'] = $loginStrGroup;
  31.  
  32. if (isset($_SESSION['PrevUrl']) && false) {
  33. $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
  34. }
  35. header("Location: " . $MM_redirectLoginSuccess );
  36. }
  37. else {
  38. header("Location: ". $MM_redirectLoginFailed );
  39. }
  40. }

the above recordset works fine. When the user login success, it display the enrolselection.php. My problem is, how can i ddisplay the data of the user who login in enrolselection.php that caomes from mysql table.? here is my recordset in enrolselection.php. I dont know what to put in the where statement of my sql. please help.

  1.  
  2. <?php require_once('Connections/enamysqldb.php'); ?>
  3. <?php
  4. if (!function_exists("GetSQLValueString")) {
  5. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  6. {
  7. $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.  
  9. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  10.  
  11. switch ($theType) {
  12. case "text":
  13. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  14. break;
  15. case "long":
  16. case "int":
  17. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  18. break;
  19. case "double":
  20. $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  21. break;
  22. case "date":
  23. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  24. break;
  25. case "defined":
  26. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  27. break;
  28. }
  29. return $theValue;
  30. }
  31. }
  32.  
  33. $colname_recstudinfo = "-1";
  34. if (isset($_GET['username'])) {
  35. $colname_recstudinfo = $_GET['username'];
  36. }
  37. mysql_select_db($database_enamysqldb, $enamysqldb);
  38. $query_recstudinfo = sprintf("SELECT * FROM studentregistration WHERE username = %s", GetSQLValueString($colname_recstudinfo, "text"));
  39. $recstudinfo = mysql_query($query_recstudinfo, $enamysqldb) or die(mysql_error());
  40. $row_recstudinfo = mysql_fetch_assoc($recstudinfo);
  41. $totalRows_recstudinfo = mysql_num_rows($recstudinfo);

Ive done this in asp by just passing the parameter value of index.php to enrlselection.php that holds the data of username textbox. here is my code in asp

  1.  
  2. <%
  3. Dim MMColParam
  4. MMColParam = "1"
  5. If (Request.QueryString("username") <> "") Then
  6. MMColParam = Request.QueryString("username")
  7. End If
  8. %>
  9.  
  10. <%
  11.  
  12. recdisplaysearchcontent.Source = "SELECT * FROM tblsearch_content WHERE index = " + Replace(MMColParam, "'", "''") + " ORDER BY index ASC"
  13.  
  14. %>

I dont know how to convert this asp code in php.Please help.!!

Thank you and God bless.!!
Last edited by blocker; Feb 13th, 2009 at 9:26 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: passing parameter in sql query by page

 
0
  #2
Feb 13th, 2009
Seeing as you have the username already in a session $_SESSION['MM_Username'] = $loginUsername; , why not just use this in the query?
Last edited by Will Gresham; Feb 13th, 2009 at 9:28 pm.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 125
Reputation: blocker is an unknown quantity at this point 
Solved Threads: 0
blocker's Avatar
blocker blocker is offline Offline
Junior Poster

Re: passing parameter in sql query by page

 
0
  #3
Feb 13th, 2009
Originally Posted by xan View Post
Seeing as you have the username already in a session $_SESSION['MM_Username'] = $loginUsername; , why not just use this in the query?
can i used it the in second page query.?remember that the
  1. $_SESSION['MM_Username'] = $loginUsername
is in the first page which is the index.php. When the login is correct i want to display the data of the user who login in the enrolselection.php here is the sql query.
  1. if (!function_exists("GetSQLValueString")) {
  2. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  3. {
  4. $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  5.  
  6. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  7.  
  8. switch ($theType) {
  9. case "text":
  10. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  11. break;
  12. case "long":
  13. case "int":
  14. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  15. break;
  16. case "double":
  17. $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  18. break;
  19. case "date":
  20. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  21. break;
  22. case "defined":
  23. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  24. break;
  25. }
  26. return $theValue;
  27. }
  28. }
  29.  
  30. $colname_recstudinfo = "-1";
  31. if (isset($_GET['username'])) {
  32. $colname_recstudinfo = $_GET['username'];
  33. }
  34. mysql_select_db($database_enamysqldb, $enamysqldb);
  35. $query_recstudinfo = sprintf("SELECT * FROM studentregistration WHERE username = %s", GetSQLValueString($colname_recstudinfo, "text"));
  36. $recstudinfo = mysql_query($query_recstudinfo, $enamysqldb) or die(mysql_error());
  37. $row_recstudinfo = mysql_fetch_assoc($recstudinfo);
  38. $totalRows_recstudinfo = mysql_num_rows($recstudinfo);

which part of this query should i insert the session.?should i replace the
  1. =%s
with the session variable? please help!!

Thank you so much for giving time with this. God bless
Last edited by blocker; Feb 13th, 2009 at 9:52 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 357
Reputation: death_oclock will become famous soon enough death_oclock will become famous soon enough 
Solved Threads: 37
death_oclock's Avatar
death_oclock death_oclock is offline Offline
Posting Whiz

Re: passing parameter in sql query by page

 
0
  #4
Feb 13th, 2009
Originally Posted by blocker
can i used it the in second page query.?
Yes, thats the whole point of sessions; they last across all pages in your site until they expire or the browser is closed.

It looks to me like you would put it in here:
  1. $query_recstudinfo = sprintf("SELECT * FROM studentregistration WHERE username = %s", GetSQLValueString($_SESSION['MM_Username'], "text"));
I am unsure of your page flow, but I assume $_GET['username'] no longer exists on this page? If this is true you can ditch the part about getting that value. Just use your session.
Last edited by death_oclock; Feb 13th, 2009 at 9:59 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 125
Reputation: blocker is an unknown quantity at this point 
Solved Threads: 0
blocker's Avatar
blocker blocker is offline Offline
Junior Poster

Re: passing parameter in sql query by page

 
0
  #5
Feb 13th, 2009
Originally Posted by death_oclock View Post
Yes, thats the whole point of sessions; they last across all pages in your site until they expire or the browser is closed.

It looks to me like you would put it in here:
  1. $query_recstudinfo = sprintf("SELECT * FROM studentregistration WHERE username = %s", GetSQLValueString($_SESSION['MM_Username'], "text"));
I am unsure of your page flow, but I assume $_GET['username'] no longer exists on this page? If this is true you can ditch the part about getting that value. Just use your session.
thank you sir.! I will post my reply if this work.Thank you very much sir.! Il try it out now.!

God bless
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 125
Reputation: blocker is an unknown quantity at this point 
Solved Threads: 0
blocker's Avatar
blocker blocker is offline Offline
Junior Poster

Re: passing parameter in sql query by page

 
0
  #6
Feb 13th, 2009
Originally Posted by death_oclock View Post
Yes, thats the whole point of sessions; they last across all pages in your site until they expire or the browser is closed.

It looks to me like you would put it in here:
  1. $query_recstudinfo = sprintf("SELECT * FROM studentregistration WHERE username = %s", GetSQLValueString($_SESSION['MM_Username'], "text"));
I am unsure of your page flow, but I assume $_GET['username'] no longer exists on this page? If this is true you can ditch the part about getting that value. Just use your session.
sir it does not display the information.whats wrong with my query.?here is my revised query with session variable:
  1.  
  2. if (!function_exists("GetSQLValueString")) {
  3. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  4. {
  5. $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  6.  
  7. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  8.  
  9. switch ($theType) {
  10. case "text":
  11. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  12. break;
  13. case "long":
  14. case "int":
  15. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  16. break;
  17. case "double":
  18. $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  19. break;
  20. case "date":
  21. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  22. break;
  23. case "defined":
  24. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  25. break;
  26. }
  27. return $theValue;
  28. }
  29. }
  30.  
  31. $colname_reclog = "-1";
  32. if (isset($_SESSION['MM_Username'])) {
  33. $colname_reclog = $_SESSION['MM_Username'];
  34. }
  35. mysql_select_db($database_enamysqldb, $enamysqldb);
  36. $query_reclog = sprintf("SELECT * FROM studentregistration WHERE username = %s", GetSQLValueString($colname_reclog, "text"));
  37. $reclog = mysql_query($query_reclog, $enamysqldb) or die(mysql_error());
  38. $row_reclog = mysql_fetch_assoc($reclog);
  39. $totalRows_reclog = mysql_num_rows($reclog);

I dont know whats wrong with my code.?

Please help
Last edited by blocker; Feb 13th, 2009 at 10:19 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 357
Reputation: death_oclock will become famous soon enough death_oclock will become famous soon enough 
Solved Threads: 37
death_oclock's Avatar
death_oclock death_oclock is offline Offline
Posting Whiz

Re: passing parameter in sql query by page

 
0
  #7
Feb 13th, 2009
You're not displaying anything. Unless there's more to the code on this page, I don't see a single output statement.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 125
Reputation: blocker is an unknown quantity at this point 
Solved Threads: 0
blocker's Avatar
blocker blocker is offline Offline
Junior Poster

Re: passing parameter in sql query by page

 
0
  #8
Feb 13th, 2009
Originally Posted by death_oclock View Post
You're not displaying anything. Unless there's more to the code on this page, I don't see a single output statement.
im sorry sir i forgot: here is the uotput statemet:

  1.  
  2. <td width="492"><span class="style8"><?php echo $row_reclog['lastname']; ?></span></td>

but it does not display the information.Example just to display the last name of the user who login.!

Whats wrong with my query.?

Thank you for giving time with me. I really aprreciate it.!Please help
Last edited by blocker; Feb 13th, 2009 at 10:27 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 125
Reputation: blocker is an unknown quantity at this point 
Solved Threads: 0
blocker's Avatar
blocker blocker is offline Offline
Junior Poster

Re: passing parameter in sql query by page

 
0
  #9
Feb 13th, 2009
Originally Posted by death_oclock View Post
You're not displaying anything. Unless there's more to the code on this page, I don't see a single output statement.
sir i made it.thank you for giving me the process of doing it. I just beat it 1 minute.! i just put on the top under <?php

  1.  
  2. require_once('index.php');

Thank you so much sir. If you need help in vb6 im always here to help.!!

Thank you and Glod bless. This problem was solved.!
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 PHP Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC