Call to undefined function getsqlvaluestring() with Dreamweaver PHP mysql

来源:互联网 发布:王侯将相焉有种乎出自 编辑:程序博客网 时间:2024/05/16 03:37

undefined function getsqlvaluestring()

Hey Guys, I'm new to the forum and it seems very helpful. I think I have a unique problem though.

 

Although this script has been working for a year or two, all of a sudden, over the holidays, it went hay

 

Front end is still getting all the information it should from the Database.But when I try to login through the admin side that I created with the normal dreamweaver php and database extensions I get this error.

 

I dont know a lot of php - so I'll hide the string for now - If I need to paste the code I will - thank you in advance


Fatal error
:  Call to undefined function  getsqlvaluestring() in /xxxxx/xxxx/xxxxxxx/xxxxxxx/newsletters/xxxxxxx/xxxxxxx/admin/login.ph pon line 22

 

Area around line 22 looks like this

 

  mysql_select_db($database_promocenter, $promocenter);

     

  $LoginRS__query=sprintf("SELECT username, password, destination_page FROM users WHERE username=%s AND password=%s",

  GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "int"));

  

   

  $LoginRS = mysql_query($LoginRS__query, $promocenter) or die(mysql_error());

  $loginFoundUser = mysql_num_rows($LoginRS);

  if ($loginFoundUser) {

 

 

Forms first part looks like this

 

 <form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>"> <tr> <td bgcolor="#dedede"> <table width="400" border="0" align="center" cellpadding="3" cellspacing="0" bgcolor="#ffffff"> <tr> <td height="35" align="right" valign="middle" id="description">Username: </td> <td height="35"><label> <input style="height:20px; border:1px solid #999999" name="username" type="text" id="username" size="35"/> </label></td> </tr> <tr> <td height="35" align="right" valign="middle" id="description">Password: </td> <td height="35"><label> <input style="height:20px; border:1px solid #999999" name="password" type="password" id="password" size="35" /> </label></td> </tr>

 

 

Anton

Translate
Was this helpful? Yes   No
MurraySummers
Correct 
Jan 26, 2012 5:05 AM

The could as you show it could never have worked.  Why?  Because the call to the function is made before the function is defined!  It would have always stopped execution with an undefined function error.

 

Now - it appears that you have added user authentication that placed itself before the code block in which the function is defined.  So, I'd suggest you move this -

 

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  if (PHP_VERSION < 6) {

    $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;

}

}

 

from its current location to a new block just under the connection include directive, i.e.,

 

<?php require_once('../Connections/promocenter.php'); ?>

<?php MOVE HERE ?>

<?php

// *** Validate request to login to this site.

 

so that the final code looks like this -

 

<?php require_once('../Connections/promocenter.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  if (PHP_VERSION < 6) {

    $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;

}

}

?>

<?php

// *** Validate request to login to this site.

See the answer in context
Was this helpful?Yes  No
Translate
Helpful Answersby osgood_, osgood_, osgood_, osgood_ 
Replies
  • MurraySummers
    1.MurraySummers,
    2012-1-26 上午4:26   in reply to AntonsScreenName
    Report

    Let's see the PHP from the top 20 lines of code on your page, please (above the <html> tag).

    Was this helpful? Yes   No
    Translate
  • MurraySummers
    3.MurraySummers,
    2012-1-26 上午4:48   in reply to AntonsScreenName
    Report

    Do you see code in that region that looks like this?

     

    if (!function_exists("GetSQLValueString")) {

    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

    {

      if (PHP_VERSION < 6) {

        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

      }

     

    That's boilerplate code for the function that is always inserted by DW when you place a recordset on the page.  The error message you are getting seems to suggest that the function definition is missing.  I'm also a little troubled by the casing of the function name in the error message - it clearly does not match the casing shown here.

    Was this helpful? Yes   No
    Translate
  • osgood_
    4.osgood_,
    2012-1-26 上午4:53   in reply to AntonsScreenName
    Report

    Seems you need a function() file. You must have another file somewhere that you have forgotten to include?

     

    http://forums.digitalpoint.com/showthread.php?t=54786

     

     

    Maybe you are using the same script that worked for another website but forgot to include the function() file???

    Was this helpful? Yes   No
    Translate
  • MurraySummers
    7.MurraySummers,
    2012-1-26 上午5:05   in reply to AntonsScreenName
    Report

    The could as you show it could never have worked.  Why?  Because the call to the function is made before the function is defined!  It would have always stopped execution with an undefined function error.

     

    Now - it appears that you have added user authentication that placed itself before the code block in which the function is defined.  So, I'd suggest you move this -

     

    if (!function_exists("GetSQLValueString")) {

    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

    {

      if (PHP_VERSION < 6) {

        $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;

    }

    }

     

    from its current location to a new block just under the connection include directive, i.e.,

     

    <?php require_once('../Connections/promocenter.php'); ?>

    <?php MOVE HERE ?>

    <?php

    // *** Validate request to login to this site.

     

    so that the final code looks like this -

     

    <?php require_once('../Connections/promocenter.php'); ?>

    <?php

    if (!function_exists("GetSQLValueString")) {

    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

    {

      if (PHP_VERSION < 6) {

        $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;

    }

    }

    ?>

    <?php

    // *** Validate request to login to this site.

    Was this helpful? Yes   No
    Translate
  • osgood_
    8.osgood_,
    2012-1-26 上午5:11   in reply to AntonsScreenName
    Report

    Try moving the below to the top of the php code:

     

    <?php if (!function_exists("GetSQLValueString")) {

    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

    {

      if (PHP_VERSION < 6) {

        $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;

    }

    }

     

    mysql_select_db($database_promocenter, $promocenter);

    $query_rs_users_login = "SELECT * FROM users";

    $rs_users_login = mysql_query($query_rs_users_login, $promocenter) or die(mysql_error());

    $row_rs_users_login = mysql_fetch_assoc($rs_users_login);

    $totalRows_rs_users_login = mysql_num_rows($rs_users_login);

    ?>

    Was this helpful? Yes   No
    Translate
  • osgood_
    10.osgood_,
    2012-1-26 上午5:22   in reply to AntonsScreenName
    Report

    AntonsScreenName wrote:

     

    Hi Murray - thank you for that, but what about

     

    mysql_select_db($database_promocenter, $promocenter);

    $query_rs_users_login = "SELECT * FROM users";

    $rs_users_login = mysql_query($query_rs_users_login, $promocenter) or die(mysql_error());

    $row_rs_users_login = mysql_fetch_assoc($rs_users_login);

    $totalRows_rs_users_login = mysql_num_rows($rs_users_login);

    Thats not part of the function so you can leave that where it is. I just grabbed the whole lot.

    Was this helpful? Yes   No
    Translate
  • osgood_
    12.osgood_,
    2012-1-26 上午5:31   in reply to AntonsScreenName
    Report

    Have you got any white space between the blocks of php code or above the top line of the php code. This 'header already sent' warning usually pops up when the empty space above, below, inbetween in the php code is present.

     

    You could also try adding the below piece of php to the very top of the page:

     

    <? ob_start(); ?>

     

    and this piece after the last closing ?> php tag on the page:

     

    <? ob_flush(); ?>

    Was this helpful? Yes   No
    Translate
  • osgood_
    14.osgood_,
    2012-1-26 上午5:51   in reply to AntonsScreenName
    Report

    AntonsScreenName wrote:

     

     

    Unknown column 'destination_page' in 'field list'

     

    I do have a index.php page in the same folder as login.php

     

    Is there a column in your database table 'users'  with the name destination_page?

     

    I can't see why you are selecting it from the database in the first instance?

     

    $LoginRS__query=sprintf("SELECT username, password, destination_page FROM users WHERE username=%s AND password=%s",

    Was this helpful? Yes   No
    Translate
  • osgood_
    16.osgood_,
    2012-1-26 上午5:55   in reply to AntonsScreenName
    Report

    Well get rid of the call to it then:

     

    Change this:

    $LoginRS__query=sprintf("SELECT username, password, destination_page FROM users WHERE username=%s AND password=%s",

     

    To this:

    $LoginRS__query=sprintf("SELECT username, password  FROM users WHERE username=%s AND password=%s",

    Was this helpful? Yes   No
    Translate
  • osgood_
    19.osgood_,
    2012-1-26 上午6:11   in reply to AntonsScreenName
    Report

    AntonsScreenName wrote:

     

    Just so you know, the script did work for a year and a half without me touching the code and it just stopped working over the holidays.

     

    As Murray said earlier I fail to see how it could have worked because the function was declared after the call to the function which would throw an error. php has to be in the correct order to work as expected.

     

     

    AntonsScreenName wrote:

    Could it have been upgrade to servers or os at hosting company?

     

    Probably unlikely but stranger things have happened. Not all servers work the same way as I've found out to my own frustrations recently.

    Was this helpful? Yes   No

0 0
原创粉丝点击