Jump to content

Data insertion


vikrantmohite

Recommended Posts

I rather thought the problem was line 42 (i.e. http://en.wikipedia.org/wiki/42_Puzzle#42_Puzzle )

 

The reason for Pikachu2000's answer is that you posted no relevant information upon which to tell you what is wrong in your code, so you got an accurate as possible answer (i.e. a guess) based on the information supplied.

 

Programming is an exact science. Computers only do exactly what their code and data tells them to do. We cannot tell you what your code and data are doing without seeing all the code and data needed to reproduce the problem. We are not standing right next to you and don't know what your code and data is.

Link to comment
https://forums.phpfreaks.com/topic/263939-data-insertion/#findComment-1352646
Share on other sites

We need to see the code that you use for making the array, and the code for when you insert into the database table, else we can't really help.

 

index.php

<?php

    # don't forget the library
    include('simple_html_dom.php');
    
    # this is the global array we fill with article information
    $trains = array();

    # passing in the first page to parse, it will crawl to the end
    # on its own
    getArticles('http://www.makemytrip.com/railways/mumbai_sawantwadi_s-01013-train.html');






function getArticles($page) {
global $trains, $con;
    $html = new simple_html_dom();
    $html->load_file($page);

$con = mysql_connect("localhost","root","");
mysql_select_db("temp",$con);


/*   foreach($html->find('table tr.segonroute1') as $e)
   {
	//$details[] = $e->children(1)->outertext;
	//echo $e->children(1)->outertext;
   }
*/   
   $route = $html->find('table tr.segonroute1');
   
   foreach($route as $key)
   	{
	$trains[]=array(
						$key->children(1)->plaintext,
						$key->children(2)->plaintext,
						$key->children(3)->plaintext,
						$key->children(4)->plaintext,
						$key->children(5)->plaintext,
						$key->children(6)->plaintext
					);

//mysql_query("INSERT INTO trains (station_name, arrives, departs, halt_time, distance, train_no) VALUES ('".$key->children(1)->outertext."");

}

}


    foreach($trains as $item) {
        echo $item[0];
	$s = (string) $item[0];
        echo " ".$item[1];
	echo " ".$item[2];
	echo " ".$item[3];
	echo " ".$item[4];
	echo " ".$item[5]."<br/>";


	//mysql_query("INSERT INTO trains (station_name, arrives, departs, halt_time, distance, train_no) VALUES ('$item[0]','$item[1]','$item[2]','$item[3]','$item[5]',01013");
	$q="INSERT INTO trains (station_name) VALUES ('$s')";
	mysql_query($q,$con);


    }
?>

 

simple_html_dom.php

is attached here .

18569_.php

Link to comment
https://forums.phpfreaks.com/topic/263939-data-insertion/#findComment-1352649
Share on other sites

What exactly is the query? Since you are not escaping the data being put into it, it might have special sql characters that are breaking the sql syntax. Echo the $q variable and post the result.

 

Is your query failing due to an error of some kind? For debugging purposes, change your mysql_query line of code to -

 

mysql_query($q,$con) or die("Query failed: $q<br />Error: " . mysql_error($con));

Link to comment
https://forums.phpfreaks.com/topic/263939-data-insertion/#findComment-1352692
Share on other sites

What exactly is the query? Since you are not escaping the data being put into it, it might have special sql characters that are breaking the sql syntax. Echo the $q variable and post the result.

 

Is your query failing due to an error of some kind? For debugging purposes, change your mysql_query line of code to -

 

mysql_query($q,$con) or die("Query failed: $q<br />Error: " . mysql_error($con));

 

Thanks PFMaBiSmAd

 

I got the solution

I was getting a lot of white spaces while inserting data so data was not getting inserted into the table. I used trim() to remove white spaces and now everything is workin fine.

 

Thanks to all for your support and response. :thumb-up:

Link to comment
https://forums.phpfreaks.com/topic/263939-data-insertion/#findComment-1352842
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.