Jump to content

[SOLVED] What is missing?


refiking

Recommended Posts

What am I missing in this code?  It returns:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/refiking/public_html/test/uploader.php on line 6

| could not be uploaded!

 

$loan_id = $_GET['loan_id'];
$upload = $_GET['upload'];
$sql = mysql_query("SELECT upfc FROM Loans WHERE loan_id = $loan_id");
while($row = mysql_fetch_assoc($sql)) {
IF ($row[upfc] == 0){
$file_name = $loan_id . "point1";
}
ELSE {
$file_name = $loan_id . "point2";
}
}

Link to comment
Share on other sites

<?php

$loan_id = (int)$_GET['loan_id'];
$sql = mysql_query("SELECT upfc FROM Loans WHERE loan_id = '$loan_id'");

if( !$sql ) 
    die(mysql_error());

while($row = mysql_fetch_assoc($sql)) {
    if( $row[upfc] == 0 )
        $file_name = $loan_id . "point1";
    else
        $file_name = $loan_id . "point2";
}

?>

 

Untested.[/code]

Link to comment
Share on other sites

Your query is failing because of inavlid syntax and your failing to check your query succeeds before attempting to use its result.

 

<?php

 $loan_id = $_GET['loan_id'];
 $upload = $_GET['upload'];
 $sql = "SELECT upfc FROM Loans WHERE loan_id = '$loan_id'";
 if ($result = mysql_query($sql)) {
   if (mysql_num_rows($result)) {
     while ($row = mysql_fetch_assoc($sql)) {
       if ($row['upfc'] == 0) {
         $file_name = $loan_id . "point1";
       } else {
         $file_name = $loan_id . "point2";
       }
     }
   }
 } else {
    echo mysql_error();
  }

?>

 

Also, how many results are you expecting? do you need the loop? If so $file_name will only ever equal the result of the last record.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.