Jump to content

kleidi24

Members
  • Posts

    11
  • Joined

  • Last visited

Posts posted by kleidi24

  1. Hello,

       I was looking around for a solution to get some texts from a webpage. I was searching around for some solutions but i can't make it works. I have a national bank webpage that every day shows the official exchange rates. I want to get thos official rates once a day and cache it. The bank page shows this html code:

    [...]
    <tr>
    <td width="13" height="15" align=right>
    <img src="bullet_light_grey.gif">
    </td>
    <td width="3">
    <img src="spacer.gif" width="3" height="18">
    </td>
    <td class="arial11Light">USD / ABC</td>
    <td class="arial11Light" align=right>
    103.51
    </td>
    </tr>
    <tr>
    <td width="13" height="15" align=right>
    <img src="bullet_light_grey.gif">
    </td>
    <td width="3">
    <img src="spacer.gif" width="3" height="18">
    </td>
    <td class="arial11Light">EUR / ABC</td>
    <td class="arial11Light" align=right>
    140.26
    </td>
    </tr>
    <tr>
    <td width="13" height="15" align=right>
    <img src="bullet_light_grey.gif">
    </td>
    <td width="3">
    <img src="spacer.gif" width="3" height="18">
    </td>
    <td class="arial11Light">GBP / ABC</td>
    <td class="arial11Light" align=right>
    169.65
    </td>
    </tr>
    [...]
    

    This is the code where is found my needed informations. Now, what i need is the currency and the value. Ex: USD / ABC  -  103.51

    Can you help me to find a way to extract this informations?

    Thank you!

  2. :facewall:

     

    You are still using mysql_real_escape_string() instead of real_escape_string()

     

    Nice emoticon :-P Sorry for my incompetence :-/

    I have made the changes an now it looks like this:

    $dataREZ[] = sprintf("'%s','%s','%s','%s','%s','%s'",
    					$dbREZ->real_escape_string($a['Emri']),
    					date('Y-m-d', strtotime($a['Dtlindja'])),
    					$dbREZ->real_escape_string($a['Vendlindja']),
    					$dbREZ->real_escape_string($a['Pass']),
    					date('Y-m-d', strtotime($a['DtLeshimit'])),
    					date('Y-m-d', strtotime($a['DtSkadimit']))
    					);
    	}
    
    

    But i have a problem with insert query. In this case:

    	$sqlSHTOADLT = "INSERT INTO rezervimet_emrat (rezEmEmri, rezEmDatelindja, rezEmVendlindja, rezEmPass, rezEmDtLeshimit, rezEmDtSkadimit)
    	    VALUES \n" . join(",\n", $data);
    

    ...it didn't shows any error but when i echo the query, it shows this warning:

    Warning: join() [function.join]: Invalid arguments passed in D:\VertrigoServ\www\qwerty\rezervo\rezervo.php on line 154
    INSERT INTO rezervimet_emrat (rezEmEmri, rezEmDatelindja, rezEmVendlindja, rezEmPass, rezEmDtLeshimit, rezEmDtSkadimit) VALUES 
    

    ...if i change the query and made it like this:

    $sqlSHTOADLT = "INSERT INTO rezervimet_emrat (rezEmEmri, rezEmDatelindja, rezEmVendlindja, rezEmPass, rezEmDtLeshimit, rezEmDtSkadimit, rezEmRezID, rezEmOfertaDC, rezEmOferta)			VALUES \n(" . join(",\n", $dataREZ).", $row[0], $ofertaDC, $ofertaKodi)";
    

    ...does not appear any error, too, but it didn't insert anything.The query looks like this:

    INSERT INTO rezervimet_emrat (rezEmEmri, rezEmDatelindja, rezEmVendlindja, rezEmPass, rezEmDtLeshimit, rezEmDtSkadimit, rezEmRezID, rezEmOfertaDC, rezEmOferta) VALUES (Name1 Surname1','1986-08-24','Somewhere','BD123654789','2009-08-25','2019-08-24', 'Name2 Surname2','1981-11-28','SomewhereElse','QW987654321','2008-05-05','2018-05-04', 207, 140, O-UNT-323)
    

    What i'm doing wrong?

    Thank you.

     

     

  3. I am using

     

    $db->real_escape_string($a['Emri'])

     

    You are trying to use

     

    $dbREZ->mysql_real_escape_string($a['Emri'])

     

    Spot the difference?

     

    Yep, but i have make some changes on your suggested code and the full code looks like this now:

    		define('HOST', 'localhost');
    		define('DBNAME', asdfg');
    		define('USERNAME', 'root');
    		define('PASSWORD', 'gfdsa');
    		$dbREZ = new mysqli(HOST,USERNAME,PASSWORD,DBNAME);
    		$dataREZ = array();			   
    		foreach ($_POST['adlt'] as $a) {
    		/**
    		* sanitize string data and format dates
    		*/
    		$dataREZ[] = sprintf("'%s','%s','%s','%s','%s','%s'",
    					$dbREZ->mysql_real_escape_string($a['Emri']),
    					date('Y-m-d', strtotime($a['Dtlindja'])),
    					$dbREZ->mysql_real_escape_string($a['Vendlindja']),
    					$dbREZ->mysql_real_escape_string($a['Pass']),
    					date('Y-m-d', strtotime($a['DtLeshimit'])),
    					date('Y-m-d', strtotime($a['DtSkadimit']))
    					);
    	}
    	$sqlSHTOADLT = "INSERT INTO rezervimet_emrat (rezEmEmri, rezEmDatelindja, rezEmVendlindja, rezEmPass, rezEmDtLeshimit, rezEmDtSkadimit, rezEmRezID, rezEmOfertaDC, rezEmOferta)
    			VALUES \n(" . join(",\n", $dataREZ).", $row[0], $ofertaDC, $ofertaKodi)";
    	$dbREZ->query($sqlSHTOADLT);
    
    

    Thanks

  4. Hello Barand,

       I have tried what you sugessted but seems that i'm making something wrong since i'm getting this error:

    Fatal error: Call to undefined method mysqli::mysql_real_escape_string() in D:\VertrigoServ\www\union\rezervo\rezervo.php on line 144
    

    ...and the lines 143-150 looks like this:

    		$dataREZ[] = sprintf("'%s','%s','%s','%s','%s','%s'",
    					$dbREZ->mysql_real_escape_string($a['Emri']),
    					date('Y-m-d', strtotime($a['Dtlindja'])),
    					$dbREZ->mysql_real_escape_string($a['Vendlindja']),
    					$dbREZ->mysql_real_escape_string($a['Pass']),
    					date('Y-m-d', strtotime($a['DtLeshimit'])),
    					date('Y-m-d', strtotime($a['DtSkadimit']))
    					);
    

    I have tried with real_escape_string as you suggested but the error is the same. Also, i have tried to remove  mysql_real_escape_string and it works, but the field is blank on the db. Any suggestion?

     

    Thank you!

  5. That array only contains data for one adult.

     

    If you form will containd data for several adults then you need to change your naming convention

     

    eg

    <input name="adlt[$xAdult][Emri]" type="text" id="adltEmri" style="width:98%;" />
    <input style="width:95%;" type="text" name="adlt[$xAdult][Dtlindja]" id="adltDtlindja" />
    

     

    so that the fields are grouped for each value of $xAdult

    Hello,

    Thank you very much for your help. Now is structured as follow:

    [adlt] => Array
        (
    	    [0] => Array
    		    (
    			    [Emri] => Adult 1
    			    [Dtlindja] => BirthDate
    			    [Vendlindja] => PlaceofBirth
    			    [Pass] => BB123654789
    			    [DtLeshimit] => 22.02.2012
    			    [DtSkadimit] => 21.02.2013
    		    )
    	    [1] => Array
    		    (
    			    [Emri] => Adult 2
    			    [Dtlindja] => Birthdate 2
    			    [Vendlindja] => PlaceofBirth 2
    			    [Pass] => CC987456321
    			    [DtLeshimit] =>02.01.2012
    			    [DtSkadimit] => 01.01.2012
    		    )
        )
    

    This is a big step ;-) Now, how sql query should look like for inserting those informations? Can you help me on this, too, pleease?

    Thanks again!

  6. start by using

     

    echo '<pre>',print_r($_GET, true),'</pre>';

     

    to see what is being sent from the form (if your form method is POST then use $_POST above)

    Thank you for your reply.

    It shows the informations as the users inputs on the form. For our case:

    [adlt] => Array
        (
    	    [0] => Array
    		    (
    			    [Emri] => Adult 1
    		    )
    	    [1] => Array
    		    (
    			    [Dtlindja] => 22.02.1910
    		    )
    	    [2] => Array
    		    (
    			    [Vendlindja] => Paris
    		    )
    	    [3] => Array
    		    (
    			    [Pass] => BD12345698
    		    )
    	    [4] => Array
    		    (
    			    [DtLeshimit] => 22.02.2012
    		    )
    	    [5] => Array
    		    (
    			    [DtSkadimit] => 21.02.2022
    		    )
    	    [6] => Array
    		    (
    			    [Emri] => adult 2
    		    )
    	    [7] => Array
    		    (
    			    [Dtlindja] => 02.02.2002
    		    )
    	    [8] => Array
    		    (
    			    [Vendlindja] => London
    		    )
    	    [9] => Array
    		    (
    			    [Pass] => LK987654321
    		    )
    	    [10] => Array
    		    (
    			    [DtLeshimit] => 02.02.2012
    		    )
    	    [11] => Array
    		    (
    			    [DtSkadimit] => 01.02.2013
    		    )
        )
    

    What i need is a way to get those informations separatly for each person/adult, and insert them in a row for each one person inserted in the form.

    Thanks again.

  7. I have an html form that, via javascript, depending on the user selection, appears some input fields in a row. This is the javascript:

    function addInputAdult(num){
    inputElementsAdult.innerHTML='';
    for(xAdult=0;xAdult<num;xAdult++)inputElementsAdult.innerHTML=inputElementsAdult.innerHTML +'<table width="100%" style="margin:0; padding:0;"><tr><th width="24%" scope="col">Adult '+(xAdult + 1)+' - Name</th><th width="13%" scope="col">Birthdate</th><th width="18%" scope="col">Place of Birth</th><th width="13%" scope="col">Passport Nr</th><th width="13%" scope="col">Issue Date</th><th width="16%" scope="col">Expiry Date</th></tr><tr><td> <input name="adlt[][Emri]" type="text" id="adltEmri" style="width:98%;" /></td><td> <input style="width:95%;" type="text" name="adlt[][Dtlindja]" id="adltDtlindja" /></td><td> <input style="width:90%;" type="text" name="adlt[][Vendlindja]" id="adltVendlindja" /></td><td> <input style="width:90%;" type="text" name="adlt[][Pass]" id="adltPass" /></td><td> <input style="width:90%;" type="text" name="adlt[][DtLeshimit]" id="adltDtLeshimit" /></td><td><input style="width:90%;" type="text" name="adlt[][DtSkadimit]" id="adltDtSkadimit" /></td></tr></table>';
    }
    

    So, the user make the selection and the form appears. Now, i want to add the user input details in my mysql database. Can you help me on this please? I'm not "sure" how to do this.

    My problem is on getting the informations from the form in a way that those information could be usable and understandable. What i have tried is:

    foreach ( $_POST['adlt'] as $adult) {
    $getd=implode(",",$adult);
    echo $getd;
    }
    

    ...but it shows all the information not separated and I don't know how to separate informations from each other. Output looks like this:

    adult1 Nameadult1Birthdateadult1Passportadult1PlaceofBirthadult1IssueDateadult1expirydateadult2 Nameadult2 Birthdate...and so on
    

    Can you help me on this, please?

    Thank you in advance

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