Page 1 of 1

Accessing mySQL after PHP import problems....

Posted: Wed Apr 01, 2009 9:39 pm
by GT500_Grad
I have a php file that I run and it reads records in from a text file and either inserts or updates the records in my table in mySQL db. For the most part it seems to import all the information fine, but when I go to login to the site or try to access any of the information I had just imported, the sql query can not find it. It takes me going into phpMyAdmin and just clicking on "edit" for that record and then "go". Not making any changes. I can then go and access the info just fine.

Any suggestions on how to get rid of this inconvenience?

Re: Accessing mySQL after PHP import problems....

Posted: Wed Apr 01, 2009 9:56 pm
by califdon
If you post your PHP code, we might be able to figure out what it's doing. If you do so, please use the [syntax=php]and[/syntax] tags surrounding your code, to format it so it's more readable.

Re: Accessing mySQL after PHP import problems....

Posted: Fri Apr 03, 2009 1:21 pm
by GT500_Grad
I hope this helps.

Code: Select all

 
<?
@ob_start();
@session_start();
 
require('./../foldername/dbconn.inc');
require('./../foldername/site_config.inc');
 
$handle = opendir('./../foldername/');
$latest_date = '2000/01/01';
$latest_file = '';
 
while (false !== ($file = readdir($handle))) {
  if ((strstr($file,'filename_') != FALSE) && (substr($file,-4) == '.txt')){
    if (date("Y/m/d, g:i a",filemtime('./../foldername/'.$file)) > $latest_date) {
        $latest_file = $file;
    $latest_date = date("Y/m/d, g:i a",filemtime('./../foldername/'.$file));
    }
  }
}
closedir($handle);
 
function showerror($id,$text)
   {
    $recipient = "you@something.com "; //recipient
    $mail_body = "There was an error during the record update at ";
    $mail_body .= date("D M j G:i:s T Y");
    $mail_body .= ".\n\n"; //mail body
    $mail_body .= "Error text ".$text."\n";
    $mail_body .= mysql_errno() . " : " . mysql_error()."\n\n";
    $subject = "subject"; //subject
    $header = "From: someone"; //From Header
    mail($recipient, $subject, $mail_body, $header); //mail command :)
   }
 
 
$file=fopen("./../foldername/".$latest_file,"r");
fgets($file);
while(! feof($file))
{
  $strText = fgets($file);
  if ($strText != '') {
    $emp = explode("|", $strText);
        
    $sql = "select *
        from table
        where label = '$ownrid'";
    // echo "SQL: $sql <br />";
    $rs = mysql_query($sql,$db);
    $row = mysql_fetch_array($rs);
    $ownr = $row['name'];
 
    $sql = "select *
        from table
        where label = '$value[7]'";
    // echo "SQL: $sql <br />";
    $rs = mysql_query($sql,$db);
    $row = mysql_fetch_array($rs);
    $flrid = $row['id'];
                
    $sql = "select id
        from table
        where id = '$value[0]'";
    // echo "SQL: $sql <br />";
    $rs = mysql_query($sql,$db);
    $row = mysql_fetch_array($rs);
    $id = $row['id'];
                
    $sql = "select *
        from table
        where label = '$value[6]'";
    // echo "SQL: $sql <br />";
    $rs = mysql_query($sql,$db);
    $row = mysql_fetch_array($rs);
    $bld_id = $row['id'];
                
    $pass = 'password';             
                        
    if ($id != '') {
        $sql = "UPDATE table set label = values where id='value[0]';";       
        if (!($result = @ mysql_query($sql, $db))) showerror($value[o],"table UPDATE failed"); 
        } else {
            $sql = "INSERT into table label) values (values);";
           if (!($result = @ mysql_query($sql, $db))) showerror($value[o],"table INSERT failed"); 
        }
    }           
}
 
mysql_close($db);
fclose($file);
 
    $recipient = "you@something.com "; //recipient
        $mail_body = "The records were updated at ";
    $mail_body .= date("D M j G:i:s T Y");
    $mail_body .= "."; //mail body
        $subject = "subject"; //subject
        $header = "From: someone"; //From Header
        mail($recipient, $subject, $mail_body, $header); //mail command :)
 
?>
 

Re: Accessing mySQL after PHP import problems....

Posted: Fri Apr 03, 2009 2:38 pm
by califdon
I haven't any explanation for the behavior in phpMyAdmin, but your code seems incomplete. Where do all these variables come from: $ownrid, $value[0], $value[6], $value[7]? And the @ in lines 81 and 84 (in the listing above) suppresses any error messages, so the first thing to do is remove those @'s, at least until you resolve the problem.