www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 29

Thread: Can't use function return value in write context

  1. #1
    Join Date
    Jul 2006
    Posts
    249

    Unhappy Can't use function return value in write context

    I have a function that's supposed to query mysql with a zip code, and generate an html <select> box with possible cities. Instead, it crashes the site and gives this error:

    Code:
    Fatal error: Can't use function return value in write context in /home/rahl/public_html/RVM/include/functions.php on line 298
    The content of the function is:

    PHP Code:
    function zip_code_city_handler($zip)
        {

        global 
    $zip;
        
        
    $query "SELECT * FROM zip WHERE zip = '$zip'";
        
        
    $result safe_query($query);
            
        if (
    mysql_num_rows($result) = 1)
            {
            
    $city_select "<select>";
            while(
    $row mysql_fetch_array($result))
                {
                
    $city_select .= "<option>".$row['city']."</option>";
                }
            
    $city_select .= "</select>";
            }
            else
            {
            
    $row mysql_fetch_array$result );
            
    $city_select $row['city'];
            }
            
            return 
    $city_select;
        } 
    I've never gotten this error before and I'm not really sure what it means...

    Any help is appreciated, as always.

    Thanks,

    Nick

  2. #2
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    It means that your function is returning an unspeakable value - make that unwritable value. True and false are examples of that.

    You have a coding error in the function:
    PHP Code:
    if (mysql_num_rows($result) = 1
    This resolves to a value assignment and not a condition test. Use "==" instead of "=".

  3. #3
    Join Date
    Jul 2006
    Posts
    249
    oops... That fixed the error. Thank you

    Now I'm getting:

    Code:
    # errorno=1064
    # error=You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
    # query=query

    I think this is causing the problem:

    PHP Code:
        if(empty($error))
            {
            
    $query mysql_query("UPDATE Users SET title='$title',last_name='$l_name',first_name='$f_name',zip='$zip' WHERE handle='$user_name'"
            or die(
    mysql_error());  
            
            
    safe_query($query); 
    Last edited by lightnb; 02-26-2007 at 11:44 AM.

  4. #4
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Change the function safe_query as follows:
    PHP Code:
    function safe_query ($query "")
        {
        if(empty(
    $query))
            {
            return 
    FALSE;
            }
        
    $result mysql_query($query)
            or die(
    "I've Failed You: <li>errorno=".mysql_errno()."<li>error=".mysql_error()."<li>query=".$query);
        return 
    $result;
        } 
    (Missing "$" in final "query".)

  5. #5
    Join Date
    Jul 2006
    Posts
    249

    Smile

    wow. how do you always find the needle in the haystack? (or the missing $ in 3000 lines of code)

    I now get:

    PHP Code:
    query=
    So I'm guessing the query got screwed up somewhere...

  6. #6
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    On second thought, I would change it to this:

    PHP Code:
    function safe_query ($query "") {
      
    $result FALSE;
      if (!empty(
    $query)) {
        
    $result = @mysql_query($query);
        if (!
    $result) {
          echo 
    "I've Failed You:<br>";
          echo 
    "<li>Script Name: " $_SERVER['PHP_SELF'];
          echo 
    "<li>Include File: " __FILE__;
          echo 
    "<li>errorno=" mysql_errno();
          echo 
    "<li>error="   mysql_error();
          echo 
    "<li>query= "  $query;
          exit;
        }
      }
      return 
    $result;


  7. #7
    Join Date
    Jul 2006
    Posts
    249
    Error now reads:


    Code:
    I've Failed You:
    # Script Name: /RVM/registration/register2.php
    # Include File: /home/rahl/public_html/RVM/include/functions.php
    # errorno=1064
    # error=You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
    # query= 1

  8. #8
    Join Date
    Jul 2006
    Posts
    249
    register2.php reads:
    PHP Code:
    <?PHP

    $location_ID 
    ="RVM Registration"// Set the location variable 

    // Include Database connection information 

    Require('../include/SQL_connect.php');

    // Include the shared registration functions

    Require('../include/functions.php');

    // Include the registration forms functions page

    Require('../registration/registration_forms.php');


    // Check to see if the form has been submited


    if (isset($HTTP_POST_VARS["submit"])) //if the form has been submited, do the following
        
    {
        
        
    $title $HTTP_POST_VARS["title"];
        
    $f_name $HTTP_POST_VARS["f_name"];
        
    $l_name $HTTP_POST_VARS["l_name"];
        
    $zip $HTTP_POST_VARS["zip"];    
        
        
    $ret_error form_validator_names($title$l_name$f_name$zip);
        
        
    registration_form_2();
            
        }else 
    //(if the form has not be submited)
        
    {
        
    $user_name $HTTP_GET_VARS["user_name"];
        
    registration_form_2(); //display the form
        
    }
        
    ?>

  9. #9
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Try this:
    PHP Code:
    function safe_query ($query "") {
      
    $result FALSE;
      if (!empty(
    $query)) {
        
    $result = @mysql_query($query);
        if (!
    $result) {
          echo 
    "I've Failed You:<br>";
          echo 
    "<li>Script Name: " $_SERVER['PHP_SELF'];
          echo 
    "<li>Include File: " __FILE__;
          echo 
    "<li>errorno=" mysql_errno();
          echo 
    "<li>error="   mysql_error();
          echo 
    "<li>query= "  $query;
          
    var_dump(debug_backtrace());
          exit;
        }
      }
      return 
    $result;


  10. #10
    Join Date
    Jul 2006
    Posts
    249
    Code:
    I've Failed You:
    # Script Name: /RVM/registration/register2.php
    # Include File: /home/rahl/public_html/RVM/include/functions.php
    # errorno=1064
    # error=You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
    # query= 1array(2) { [0]=> array(4) { ["file"]=> string(48) "/home/rahl/public_html/RVM/include/functions.php" ["line"]=> int(217) ["function"]=> string(10) "safe_query" ["args"]=> array(1) { [0]=> &bool(true) } } [1]=> array(4) { ["file"]=> string(53) "/home/rahl/public_html/RVM/registration/register2.php" ["line"]=> int(29) ["function"]=> string(20) "form_validator_names" ["args"]=> array(4) { [0]=> &string(3) "Dr." [1]=> &string(4) "last" [2]=> &string(4) "nick" [3]=> &string(5) "23456" } } }

  11. #11
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Code:
    # array(2) {
    #   [0]=> array(4) {
    #     ["file"]=> string(48) "/home/rahl/public_html/RVM/include/functions.php"
    #     ["line"]=> int(217)
    #     ["function"]=> string(10) "safe_query"
    #     ["args"]=> array(1) {
    #       [0]=> &bool(true)
    #     }
    #   }
    #   [1]=> array(4) {
    #     ["file"]=> string(53) "/home/rahl/public_html/RVM/registration/register2.php"
    #     ["line"]=> int(29)
    #     ["function"]=> string(20) "form_validator_names"
    #     ["args"]=> array(4) {
    #       [0]=> &string(3) "Dr."
    #       [1]=> &string(4) "last"
    #       [2]=> &string(4) "nick"
    #       [3]=> &string(5) "23456"
    #     }
    #   }
    # }
    The calling line is Line 29 in register2.php with the values listed.

  12. #12
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Quote Originally Posted by lightnb
    wow. how do you always find the needle in the haystack? (or the missing $ in 3000 lines of code)
    Probably because I make more mistakes than you do...

  13. #13
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    PHP Code:
    function safe_query ($query "") {
      
    $result FALSE;
      if (!empty(
    $query)) {
        
    $result = @mysql_query($query);
        if (!
    $result) {
          echo 
    "I've Failed You:<br>";
          echo 
    "<li>Script Name: " $_SERVER['PHP_SELF'];
          echo 
    "<li>Include File: " __FILE__;
          echo 
    "<li>errorno=" mysql_errno();
          echo 
    "<li>error="   mysql_error();
          echo 
    "<li>query= "  $query;
          echo 
    "<pre>";
          
    print_r(debug_backtrace());
          echo 
    "</pre>";
          exit;
        }
      }
      return 
    $result;

    It should make the display a bit more readable. Make sure that you only use this when testing...

  14. #14
    Join Date
    Jul 2006
    Posts
    249
    Line 29 reads:

    PHP Code:
    $ret_error form_validator_names($title$l_name$f_name$zip); 
    and the variables:

    Code:
    [0]=> &string(3) "Dr."
    #       [1]=> &string(4) "last"
    #       [2]=> &string(4) "nick"
    #       [3]=> &string(5) "23456"
    are correct as well.

    I don't see where it's getting "Query=1" though...

  15. #15
    Join Date
    Jul 2006
    Posts
    249
    PHP Code:
    I've Failed You:
    # Script Name: /RVM/registration/register2.php
    # Include File: /home/rahl/public_html/RVM/include/functions.php
    # errorno=1064
    # error=You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
    1' at line 1
    # query= 1

    Array
    (
        [0] => Array
            (
                [file] => /home/rahl/public_html/RVM/include/functions.php
                [line] => 220
                [function] => safe_query
                [args] => Array
                    (
                        [0] => 1
                    )

            )

        [1] => Array
            (
                [file] => /home/rahl/public_html/RVM/registration/register2.php
                [line] => 29
                [function] => form_validator_names
                [args] => Array
                    (
                        [0] => Dr.
                        [1] => last
                        [2] => nick
                        [3] => 23456
                    )

            )



    So does:

    Code:
    [args] => Array
                    (
                        [0] => 1
                    )
    mean that the safe_query function itself is setting the value to one?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.21611 seconds
  • Memory Usage 3,060KB
  • Queries Executed 13 (?)
More Information
Template Usage (38):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (7)bbcode_code
  • (11)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (15)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (15)postbit
  • (15)postbit_onlinestatus
  • (15)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates