Call to undefined function getsqlvaluestring() with Dreamweaver PHP mysql

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

Was this helpful?  Yes    No
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.

Was this helpful? Yes   No
Helpful Answersby  osgood_osgood_osgood_osgood_ 
Replies
  • MurraySummers
    2012-1-26  上午4:26    in reply to AntonsScreenName

    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
  • MurraySummers
    2012-1-26  上午4:48    in reply to AntonsScreenName

    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
  • osgood_
    2012-1-26  上午4:53    in reply to AntonsScreenName

    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
  • MurraySummers
    2012-1-26  上午5:05    in reply to AntonsScreenName

    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
  • osgood_
    2012-1-26  上午5:11    in reply to AntonsScreenName

    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
  • osgood_
    2012-1-26  上午5:22    in reply to AntonsScreenName

    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
  • osgood_
    2012-1-26  上午5:31    in reply to AntonsScreenName

    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
  • osgood_
    2012-1-26  上午5:51    in reply to AntonsScreenName

    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
  • osgood_
    2012-1-26  上午5:55    in reply to AntonsScreenName

    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
  • osgood_
    2012-1-26  上午6:11    in reply to AntonsScreenName

    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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值