Web Design Forum  
 
Go Back   Web Design Forum > Web Software > Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-02-2009, 01:11 PM   #1
New Member
 
Join Date: Apr 2009
Posts: 8
Default im going to shoot myself

please help me fix this so i dont have to shoot myself
thanks

basically i am writing a script to insert info from a text file into my database
the listings in the text file look like this:

Kia Picanto 1.0 5dr
£6495

Fiat Panda 1.1 Active ECO 5dr
£7095

etc...

my database has 4 records:
id (auto inc)
make
model
price

id does not get a value from the script, but auto increments
make gets its value from the first word in the line of text (ie, Kia or Fiat etc...)
model is the text up until (and not including) the £
price is supposed to be everything after the £


that is where the problem comes in
the id, make and model are getting written to the database fine, but the price is not. i have tried making the price a varchar instead of an int but it makes no difference.
it seems the else if loop is never actually running

Here is the code:


Code:
<?php

include ('Connections/textcon.php');

$handle = @fopen("xyz.txt", "r"); // Open file form read.

if ($handle) {
  while (!feof($handle)) // Loop til end of file.
  {
   
     $theData = fgets($handle, 4096); // Read a line
     if (strlen($theData) > 2) {
       if (strrpos($theData, "£") === false ) {
         $carmake = substr($theData, 0, strpos($theData, " ") ); // goes from character position 0 to the first occurance of a space
         $carmodel = substr($theData, strpos($theData, " " , strlen($theData) )); // goes from first occurance of a space to end
      
         $queryinsert = "INSERT INTO carsuk.cars (makeid, model)
         VALUES ('$carmake','$carmodel')";
         $result= mysql_query($queryinsert)  or die ("error in query: $query. " . mysql_error());	 
		 
       
         }
		 
		 
		 
		 else if (strrpos($theData, "£") === true) {
		 	$lengthy = strlen($theData);
			echo "hello";
        	$carprice = substr($theData, 1,$lengthy );           
         	$getlastrowiinserted_queryn=sprintf("SELECT count(*) as rowid FROM carsuk.cars"); 
          
           $getlastrowiinserted= mysql_query($getlastrowiinserted_queryn, carsuk.cars) or die(mysql_error());
           while ($line=mysql_fetch_array($getlastrowiinserted)) 
           {
            $rowid= $line['rowid'];
            }
            mysql_query("UPDATE carsuk.cars SET price= '$carprice' WHERE rowid = '$rowid' ");
       }
     }
 
 
  }
  }
fclose($handle);


?>
eskimo is offline   Reply With Quote


Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 01:29 PM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.