Rahmi Posted December 4, 2009 Share Posted December 4, 2009 Hello all I have make one program which parse a XML file and then insert selected entries into the database. It is not inserting all the entries there r few entries which it is not entering into the database. I am not able to figure out the reason. please help me regarding this. Thank u Rashmi Quote Link to comment https://forums.phpfreaks.com/topic/183960-problem-with-inserting-data-in-mysql-using-php/ Share on other sites More sharing options...
MadTechie Posted December 4, 2009 Share Posted December 4, 2009 Yeah i am having difficulty seeing the problem as well! would you mind showing the code, that has the problem! Quote Link to comment https://forums.phpfreaks.com/topic/183960-problem-with-inserting-data-in-mysql-using-php/#findComment-971122 Share on other sites More sharing options...
Rahmi Posted December 5, 2009 Author Share Posted December 5, 2009 Thanks for the reply here I am pasting the code i used to parse and then to insert data... if(isset($_POST['show'])) { $conn=mysql_connect("localhost","root","root") or die("Could not connect"); mysql_select_db("pubmeddb",$conn) or die("Could not select db"); foreach($_POST['checkB'] as $val) { #print $val; foreach($xml->PubmedArticle as $pubmart) { $pubmedid=$pubmart->MedlineCitation->PMID; if($pubmedid == $val) { $pubID=$pubmedid; $vol=$pubmart->MedlineCitation->Article->Journal->JournalIssue->Volume; $journal=$pubmart->MedlineCitation->Article->Journal->Title; $year=$pubmart->MedlineCitation->Article->Journal->JournalIssue->PubDate->Year; $month=$pubmart->MedlineCitation->Article->Journal->JournalIssue->PubDate->Month; $day=$pubmart->MedlineCitation->Article->Journal->JournalIssue->PubDate->Day; $pubdate=$year; $title=$pubmart->MedlineCitation->Article->ArticleTitle; $abstract=$pubmart->MedlineCitation->Article->Abstract->AbstractText; $authorlist=''; # print $pubID ."volume". $vol. $journal . "year".$year . $title . " ".$abstract; $i=0; foreach($pubmart->MedlineCitation->Article->AuthorList->Author as $auth) { $authorlist1= $auth->LastName . " " . $auth->ForeName.$auth->FirstName; $authorlist=$authorlist . $authorlist1."; "; if($i == 0) { $firstauth=$authorlist1; } $i=1; } # print $firstauth. " " . $authorlist; $query5="INSERT INTO 'pubmed_record'('pubmedID', 'volume', 'journal', 'pubdate', 'title', 'abstract', 'firstauth', 'authorlist') VALUES('$pubID', '$vol', '$journal', '$pubdate', '$title', '$abstract', '$firstauth','$authorlist')"; $result5=mysql_query($query5,$conn); if(!$result5) { print "Result failed"; } $num1=mysql_num_rows($result5); print $num1; } } Quote Link to comment https://forums.phpfreaks.com/topic/183960-problem-with-inserting-data-in-mysql-using-php/#findComment-971757 Share on other sites More sharing options...
MadTechie Posted December 5, 2009 Share Posted December 5, 2009 Can't see any logical problems, what's not being inserted, This basically need some debugging, you need to know the problem exists before you can workout how to fix it! Quote Link to comment https://forums.phpfreaks.com/topic/183960-problem-with-inserting-data-in-mysql-using-php/#findComment-971934 Share on other sites More sharing options...
Rahmi Posted December 7, 2009 Author Share Posted December 7, 2009 Thank u for the reply I knw code is correct because it is giving porb with few entries only. First I thought these entries could hav bad characters so i tried all the functions to remove those char still prob is same. here I send one example.... 7476849 248 Molecular & general genetics : MGG 1995 A maize DNA-binding factor with a bZIP motif is induced by low temperature. We have isolated a low temperature-induced maize gene, mlip15, via cross hybridization using rice lip19. The longest cDNA isolated comprised 1179 bp and coded for a 135 amino acid bZIP (basic region/leucine zipper) protein. The gene showed 61.4% and 68.9% identity with the rice gene at the DNA and amino acid sequence levels, respectively, and is distinct from other maize genes that code for bZIP proteins. The level of mlip15 transcript was positively regulated by low temperature in the same way as the lip19 transcript. The levels of the transcript were also strongly increased by salt stress and exogenous abscisic acid, and slightly increased by anaerobiosis, but were not affected by heat shock and drought. The mLIP15 protein and truncated derivatives, produced in rabbit reticulocyte lysates or in an Escherichia coli expression system, were able to bind to a fragment of the wheat histone H3 gene promoter. This binding was diminished by addition of a molar excess of the hexamer sequence 5'-ACGTCA-3' found in the promoter and of the G-box-like sequence, but not by the addition of the ocs sequence or a mutated hexamer sequence. The factor bound to a promoter region of the maize Adh1 gene, expression of which is also induced by low temperature. These results lead to the conclusion that mlip15 is a strong candidate for a low temperature-induced transcription factor in maize. Aguan K Kusano T; Berberich T; Harada M; Suzuki N; Sugawara K Do u find any error with this entry? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/183960-problem-with-inserting-data-in-mysql-using-php/#findComment-972663 Share on other sites More sharing options...
PFMaBiSmAd Posted December 7, 2009 Share Posted December 7, 2009 All string data that is placed into a query must be escaped so that any special sql characters in the string don't break the sql syntax of the query. See the mysql_real_escape_string function. I'm also going to guess you are getting the "Result failed" message that your code outputs when a query fails? If you bother to mention what you see in front of you, you can get faster and better solutions to your problem. Quote Link to comment https://forums.phpfreaks.com/topic/183960-problem-with-inserting-data-in-mysql-using-php/#findComment-972665 Share on other sites More sharing options...
Rahmi Posted December 7, 2009 Author Share Posted December 7, 2009 Yes Dear u r right I m getting result failed msg only. Now i used this function.. still it is showing same error. $pubID=$pubmedid; mysql_real_escape_string($pubID); $vol=$pubmart->MedlineCitation->Article->Journal->JournalIssue->Volume; mysql_real_escape_string($vol); $journal=$pubmart->MedlineCitation->Article->Journal->Title; mysql_real_escape_string($journal); $year=$pubmart->MedlineCitation->Article->Journal->JournalIssue->PubDate->Year; mysql_real_escape_string($year); $month=$pubmart->MedlineCitation->Article->Journal->JournalIssue->PubDate->Month; mysql_real_escape_string($month); $day=$pubmart->MedlineCitation->Article->Journal->JournalIssue->PubDate->Day; $pubdate=$year; $title=$pubmart->MedlineCitation->Article->ArticleTitle; mysql_real_escape_string($title); $abstract=$pubmart->MedlineCitation->Article->Abstract->AbstractText; mysql_real_escape_string($abstract); $authorlist=''; # print $pubID ."volume". $vol. $journal . "year".$year . $title; $i=0; foreach($pubmart->MedlineCitation->Article->AuthorList->Author as $auth) { $authorlist1= $auth->LastName . " " . $auth->ForeName.$auth->FirstName; $authorlist=$authorlist . $authorlist1."; "; if($i == 0) { $firstauth=$authorlist1; } $i=1; } mysql_real_escape_string($firstauth); mysql_real_escape_string($authorlist); Thank u Rashmi Quote Link to comment https://forums.phpfreaks.com/topic/183960-problem-with-inserting-data-in-mysql-using-php/#findComment-972673 Share on other sites More sharing options...
Rahmi Posted December 7, 2009 Author Share Posted December 7, 2009 Thank u so much for the reply.... I was not assigning output of "mysql_real_escape_string" function into sme variable, which is required. now my problem is solved. Thanks once again. Rashmi Quote Link to comment https://forums.phpfreaks.com/topic/183960-problem-with-inserting-data-in-mysql-using-php/#findComment-972677 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.