Learning PHP encountered a grammatical problem, tossing a day,.

Source: Internet
Author: User
Tags parse error
PHP code part, the problem is here, not normal to make judgments.

            
 
  Open in ';              Echo 'Stop in ';} else{  Echo 'Stop in ';  Echo 'Open in ';   }? >


Function part:
Website basic information, get content according to field function sysname ($field) {$sql = "select * from System"; $query =mysql_query ($sql); $rs =mysql_fetch_ Array ($query); echo $rs ["$field"];}


The Webstate field in the database uses the Char type field function to output normally, just can't judge.


Help.


Reply to discussion (solution)

function sysname ($field) {   $sql = "SELECT * from System";   $query =mysql_query ($sql);   $rs =mysql_fetch_array ($query);   Retrun $rs [$field]; Here is the return}

function sysname ($field) {   $sql = "SELECT * from System";   $query =mysql_query ($sql);   $rs =mysql_fetch_array ($query);   Retrun $rs [$field]; Here is the return}



If I want to call directly on the display, how to write it?

function sysname ($field) {   $sql = "SELECT * from System";   $query =mysql_query ($sql);   $rs =mysql_fetch_array ($query);   Retrun $rs [$field]; Here is the return}



If you write like this, you will report the error directly.
Parse error:syntax error, unexpected t_variable in points to the last line, i.e. Retrun $rs [$field];

Sorry, wrong hand!
Retrun
should be for
Return

Sorry, wrong hand!
Retrun
should be for
Return



What if I wanted to be able to display directly in the function and not echo when I was tuning it?

I have written before, you can do it without echo, but used to judge it. I don't understand. Please mention one or two, thank you.

1. Return $rs in function [$field];
2. var_dump (sysname ("webstate") output is available when judging.

In the function echo just output or print, return is the function return value, can judge.

Return

1, you first learn to debug, through the breakpoint debugging can find the problem out there, only know the problem again that, can be modified.
2, note: You see sometimes can not see the problem.
3. Solution:
function sysname ($field) {
$sql = "SELECT * from System";
$query =mysql_query ($sql);
$rs =mysql_fetch_array ($query);
return $rs [$field];//without quotation marks
}
On the PHP page: $aa = sysname ("webstate"); Var_dump ($AA); see $aa can output Y No, if you can, in the judgment statement if ($aa = = "Y") {echo "AA";} Else{echo "BB";} See what the output, step by step debugging you can solve.

1. Return $rs in function [$field];
2. var_dump (sysname ("webstate") output is available when judging.



Hello, first of all thank you for your help, but no. Print it Out is Ynull

What is your return value now?

There may be more than one record in the system table of the database, and the field you are querying is not in the first record.
Why don't you take a look at the system table?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.