Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am getting data from couple of queries in a php page. All the loops and queries are working perfectly but I am getting error in the following one.

ERROR ONE:

$sql_pso_sign="SELECT * FROM Table";
$rs_pso_sign=odbc_exec($conn,$sql_pso_sign);
if (!$rs_pso_sign) {
  exit("Error in SIGNATURE TABLE INFO SQL");
}
 while (odbc_fetch_row($rs_pso_sign)) {

      $psoName = odbc_result($rs_pso_sign, "NAME");
      $psoSign = odbc_result($rs_pso_sign, "SIGNATURE");
      $psoDate = odbc_result($rs_pso_sign, "DATE");

  }

  echo $psoName;

the error is Undefined variable: pso_name;

I have copied it from same page other loops which work fine. the working one on same page is

$sql_items="SELECT * FROM Table2";
$rs_items=odbc_exec($conn,$sql_items);
if (!$rs_items) {
  exit("Error in table2 SQL");
}
 while (odbc_fetch_row($rs_items)) {

    $calc = odbc_result($rs_items, "ITEMS_CALC");
    $dsd = odbc_result($rs_items, "ITEMS_DSD");
    $wrs = odbc_result($rs_items, "ITEMS_WRS");
    $specs = odbc_result($rs_items, "ITEMS_SPECS");
    $ochk = odbc_result($rs_items, "ITEMS_OTHERS");
    $otxt = odbc_result($rs_items, "ITEMS_OTHERS_TXT");

}
echo $calc;

it has become really frustrated I've deleted and pasted same while loops from others and I've put echo checks which do not echo inside while loop of first query.

Any suggestions?

ACTUAL CODE:

$sql_pso_sign="SELECT * FROM SIGNATURES_DASO WHERE DASO_NO ='".$daso_no."'";
$rs_pso_sign=odbc_exec($conn,$sql_pso_sign);
if (!$rs_pso_sign) {
  exit("Error in SIGNATURE TABLE INFO SQL");
}
 while (odbc_fetch_row($rs_pso_sign)) {

      $psoName = odbc_result($rs_pso_sign, "NAME");
      $psoSign = odbc_result($rs_pso_sign, "SIGNATURE");
      $psoDate = odbc_result($rs_pso_sign, "DATE");

  }

 echo $psoName;

The $daso_no has value in it and i have checked the query is correct

share|improve this question

put on hold as off-topic by user2864740, Hanky 웃 Panky, Barmar, Elias Van Ootegem, 웃웃웃웃웃 Jul 30 at 7:48

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Hanky 웃 Panky, Barmar, Elias Van Ootegem, 웃웃웃웃웃
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Fix the syntax errors first. –  Hanky 웃 Panky Jul 30 at 7:14
    
the markdown highlighter already shows it (or just maybe a typo) –  Ghost Jul 30 at 7:15
1  
Secondly the variable is named $psoName and not $pso_name; and that's the error you're seeing –  Hanky 웃 Panky Jul 30 at 7:15
    
thts just a typo here, its $psoName in echo. –  Alz Jul 30 at 7:19
    
im using dreamweaver and it says no syntax error. –  Alz Jul 30 at 7:19

2 Answers 2

up vote 0 down vote accepted

Check that the query is returning a row:

$sql_pso_sign="SELECT * FROM SIGNATURES_DASO WHERE DASO_NO ='".$daso_no."'";
$rs_pso_sign=odbc_exec($conn,$sql_pso_sign);
if (!$rs_pso_sign) {
  exit("Error in SIGNATURE TABLE INFO SQL");
}
if (odbc_fetch_row($rs_pso_sign)) {

    $psoName = odbc_result($rs_pso_sign, "NAME");
    $psoSign = odbc_result($rs_pso_sign, "SIGNATURE");
    $psoDate = odbc_result($rs_pso_sign, "DATE");

    echo $psoName;
} else {
    echo "$daso_no not found.";
}

Notice that you don't need to use a while loop if the query is only supposed to return one row.

share|improve this answer
    
working perfectly now. Thank You. One question. if we want one record while loop is not the best approach? –  Alz Jul 30 at 8:07
    
Right. A while loop is for repeatedly processing all the records. It's unnecessary if there's only one record. –  Barmar Jul 30 at 8:08

You wrong named your variable

$pso_name;

Change it to

$psoName;
share|improve this answer
1  
The missing quotes must be a copying error, otherwise the script wouldn't even run. –  Barmar Jul 30 at 7:19
    
Yeah you right :) I edited his post and mine –  RaNdoM_PoWneD Jul 30 at 7:20
    
which missing quotes are you talking about? @barmar? –  Alz Jul 30 at 7:28
    
@Alz When you posted the question, you wrote $sql_pso_sign="SELECT * FROM Table; -- the closing quotes were missing there. –  Barmar Jul 30 at 7:33
1  
Why don't you paste the actual code and error message, instead of retyping it. Then you can't make typos, and we can help you with your problem. –  Barmar Jul 30 at 7:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.