Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

im going to shoot myself

Featured Replies

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:

 

<?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);


?>

If the make and model are going in, it sounds like

if (strrpos($theData, "£") === false ) {

is always reporting false.

 

Your echo "hello"; - does that ever echo hello?

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.