Jump to content

Displaying recordset query


garydt

Recommended Posts

I have a form where the user enters his name and creates his username and password, all of which are entered in a mysyql database. When users log in I want it to say 'Hello' and their name, but the recordset query isn't showing the name on the screen. Here;s the code-

 

<?php require_once('Connections/registration.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_Recordset1 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_registration, $registration);
$query_Recordset1 = sprintf("SELECT fname FROM tablename1 WHERE username = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $registration) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

session_start(); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
Hello <?php echo $row_Recordset1['fname']; ?>
<p>
</body>

</html>
<?php
mysql_free_result($Recordset1);
?>

Link to comment
https://forums.phpfreaks.com/topic/38932-displaying-recordset-query/
Share on other sites

Thanks for the reply.

Can you tell me what you mean by MM_Username is never set and how do i set it? (i am very new to php).  When i got it to display MM_Username it worked. Have I set the recordset query correctly to search the database for the user that is currently logged on and then for it to search that row for the user's name (fname)? If i have then why won't it show the name?

When users log in I want it to say 'Hello' and their name

 

There should be no need to re-query the database for this infomation, when you login your users, store there username in the $_SESSION array.

 

PS; Id'e definately recomend dropping Dreamweaver until youv'e learnt php. It writes terrible code and will teach you nothing.

thrope correct i used dreamweaver on here when i start php progeamming it done me no good at all, i was advised the same drop dreamweaver so i did so, I used my good old free note pad and now i can do php programing properly.

 

As time goes on and you get really good you can get a decent program from zend ok.

 

good luck all the best redarrow

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.