| | |
passing parameter in sql query by page
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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:
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.
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
I dont know how to convert this asp code in php.Please help.!!
Thank you and God bless.!!
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:
php Syntax (Toggle Plain Text)
if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['username'])) { $loginUsername=$_POST['username']; $password=$_POST['password']; $MM_fldUserAuthorization = ""; $MM_redirectLoginSuccess = "enrolselection.php"; $MM_redirectLoginFailed = "invaliduser.php"; $MM_redirecttoReferrer = false; mysql_select_db($database_enamysqldb, $enamysqldb); $LoginRS__query=sprintf("SELECT username, password FROM studentregistration WHERE username=%s AND password=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $enamysqldb) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = ""; //declare two session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } }
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.
php Syntax (Toggle Plain Text)
<?php require_once('Connections/enamysqldb.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $colname_recstudinfo = "-1"; if (isset($_GET['username'])) { $colname_recstudinfo = $_GET['username']; } mysql_select_db($database_enamysqldb, $enamysqldb); $query_recstudinfo = sprintf("SELECT * FROM studentregistration WHERE username = %s", GetSQLValueString($colname_recstudinfo, "text")); $recstudinfo = mysql_query($query_recstudinfo, $enamysqldb) or die(mysql_error()); $row_recstudinfo = mysql_fetch_assoc($recstudinfo); $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
asp Syntax (Toggle Plain Text)
<% Dim MMColParam MMColParam = "1" If (Request.QueryString("username") <> "") Then MMColParam = Request.QueryString("username") End If %> <% recdisplaysearchcontent.Source = "SELECT * FROM tblsearch_content WHERE index = " + Replace(MMColParam, "'", "''") + " ORDER BY index ASC" %>
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.
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.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
•
•
•
•
Seeing as you have the username already in a session $_SESSION['MM_Username'] = $loginUsername; , why not just use this in the query? php Syntax (Toggle Plain Text)
$_SESSION['MM_Username'] = $loginUsername
php Syntax (Toggle Plain Text)
if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $colname_recstudinfo = "-1"; if (isset($_GET['username'])) { $colname_recstudinfo = $_GET['username']; } mysql_select_db($database_enamysqldb, $enamysqldb); $query_recstudinfo = sprintf("SELECT * FROM studentregistration WHERE username = %s", GetSQLValueString($colname_recstudinfo, "text")); $recstudinfo = mysql_query($query_recstudinfo, $enamysqldb) or die(mysql_error()); $row_recstudinfo = mysql_fetch_assoc($recstudinfo); $totalRows_recstudinfo = mysql_num_rows($recstudinfo);
which part of this query should i insert the session.?should i replace the
php Syntax (Toggle Plain Text)
=%s
Thank you so much for giving time with this. God bless
Last edited by blocker; Feb 13th, 2009 at 9:52 pm.
•
•
•
•
Originally Posted by blocker
can i used it the in second page query.?
It looks to me like you would put it in here:
PHP Syntax (Toggle Plain Text)
$query_recstudinfo = sprintf("SELECT * FROM studentregistration WHERE username = %s", GetSQLValueString($_SESSION['MM_Username'], "text"));
Last edited by death_oclock; Feb 13th, 2009 at 9:59 pm.
•
•
•
•
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:
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.PHP Syntax (Toggle Plain Text)
$query_recstudinfo = sprintf("SELECT * FROM studentregistration WHERE username = %s", GetSQLValueString($_SESSION['MM_Username'], "text"));
God bless
•
•
•
•
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:
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.PHP Syntax (Toggle Plain Text)
$query_recstudinfo = sprintf("SELECT * FROM studentregistration WHERE username = %s", GetSQLValueString($_SESSION['MM_Username'], "text"));
php Syntax (Toggle Plain Text)
if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $colname_reclog = "-1"; if (isset($_SESSION['MM_Username'])) { $colname_reclog = $_SESSION['MM_Username']; } mysql_select_db($database_enamysqldb, $enamysqldb); $query_reclog = sprintf("SELECT * FROM studentregistration WHERE username = %s", GetSQLValueString($colname_reclog, "text")); $reclog = mysql_query($query_reclog, $enamysqldb) or die(mysql_error()); $row_reclog = mysql_fetch_assoc($reclog); $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.
•
•
•
•
You're not displaying anything. Unless there's more to the code on this page, I don't see a single output statement.
php Syntax (Toggle Plain Text)
<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.
•
•
•
•
You're not displaying anything. Unless there's more to the code on this page, I don't see a single output statement.
php Syntax (Toggle Plain Text)
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.!
![]() |
Similar Threads
- How to configure GD (PHP)
- vb.net Fill function (VB.NET)
- php.ini confusion (PHP)
Other Threads in the PHP Forum
- Previous Thread: htmlspecialchars
- Next Thread: Help New to PHP
| Thread Tools | Search this Thread |
.htaccess action ajax apache api array auto beginner binary bounce broken cakephp checkbox class cms code cron curl database date display dynamic echo email error errorlog file files folder form format forms function functions google href htaccess html image include insert integration interactive ip java javascript joomla limit link login loop mail malfunctioning masterthesis menu mlm mod_rewrite multiple mysql nodes oop paypal pdf php popup problem query radio ram random recursion reference regex remote return script search server sessions sms soap source space sql syntax system table tutorial unset update upload url validation validator variable video web websitecontactform xml youtube





