snk Posted November 21, 2007 Share Posted November 21, 2007 hello, I run this code from the page sendUrl.php $card = $_POST['card']; $cvs = $_POST['cvs']; echo $card . " "; echo $cvs; $fields="card=$card&cvs=$cvs"; $ch = curl_init("http://www.myfoxnet.com/project/curltest.php"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); // set the fields to post curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // make sure we get the response back $buffer = curl_exec($ch); // execute the post curl_close($ch); echo "OK"; I take back every echo in right way. in curltest.php i have this code $card = $_POST['card']; $cvs = $_POST['cvs']; $db = mysql_connect("localhost", "testDB","pppp"); mysql_select_db("testTbl",$db); $addinfo = "INSERT INTO `cw-hotel`.`bank` ( `key` , `card` , `cvs` ) VALUES ( NULL , '$card', '$cvs' )"; mysql_query($addinfo) or die(mysql_error()); echo "OK"; I have tested curltest.php by sending post by a form and works fine, i mean data are being inserted in DB. The problem is with cURL if somebody is more observant than me plz help Quote Link to comment https://forums.phpfreaks.com/topic/78187-problem-with-curl/ Share on other sites More sharing options...
teng84 Posted November 21, 2007 Share Posted November 21, 2007 and whats the problem? Quote Link to comment https://forums.phpfreaks.com/topic/78187-problem-with-curl/#findComment-395661 Share on other sites More sharing options...
snk Posted November 21, 2007 Author Share Posted November 21, 2007 Thanks for replying, im trying to figure it out... ??? Data are not inserted in the DB. I suspect that i dont do something right, but as far i have searched on internet everything looks fine. but i insert values to the DB when i post data to curltest.php from a page with web form thanks for your effort. Quote Link to comment https://forums.phpfreaks.com/topic/78187-problem-with-curl/#findComment-395670 Share on other sites More sharing options...
teng84 Posted November 21, 2007 Share Posted November 21, 2007 check your variable .. print_r($_POST); to see if your having post data Quote Link to comment https://forums.phpfreaks.com/topic/78187-problem-with-curl/#findComment-395672 Share on other sites More sharing options...
snk Posted November 21, 2007 Author Share Posted November 21, 2007 sendURL.php is having post data coz i echo them curltest.php is having post data when i call it from a normal web form and also places data in DB i run via browser http://myfoxnet.com/project/curltest.php?card=8888&cvs=88 and DB inserted just the key which is auto_increment, but not the 8888 and 88 if curl was running smoothly i think that record in DB should be increased as well. Where to put the print_r($_POST); i dont see the curltest.php in my browser at all, i just call it thanks again Quote Link to comment https://forums.phpfreaks.com/topic/78187-problem-with-curl/#findComment-395683 Share on other sites More sharing options...
teng84 Posted November 21, 2007 Share Posted November 21, 2007 <? $card = $_POST['card']; $cvs = $_POST['cvs']; print_r($_POST); $db = mysql_connect("localhost", "testDB","pppp")or die(mysql_error(); mysql_select_db("testTbl",$db)or die(mysql_error(); $addinfo = "INSERT INTO `cw-hotel`.`bank` (`key` ,`card` ,`cvs`)VALUES (NULL , '$card', '$cvs')"; mysql_query($addinfo) or die(mysql_error()); echo "OK"; ?> try that ans paste the result Quote Link to comment https://forums.phpfreaks.com/topic/78187-problem-with-curl/#findComment-395685 Share on other sites More sharing options...
snk Posted November 21, 2007 Author Share Posted November 21, 2007 i run directly http://myfoxnet.com/project/curltest.php?card=8888&cvs=88 and i get the below msg Array ( ) OK OK is coming from my echo. Also puts an empty row to my table does it help? cheers Quote Link to comment https://forums.phpfreaks.com/topic/78187-problem-with-curl/#findComment-395689 Share on other sites More sharing options...
teng84 Posted November 21, 2007 Share Posted November 21, 2007 you get array() because post data is not set .. maybe your field id not null that try to add static value in your insert statement to know if the prob lies within your curl or sql statement Quote Link to comment https://forums.phpfreaks.com/topic/78187-problem-with-curl/#findComment-395690 Share on other sites More sharing options...
snk Posted November 21, 2007 Author Share Posted November 21, 2007 i updated the curl $buffer = curl_exec($ch); // execute the post curl_close($ch); print $buffer; but it doesnt print anything. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/78187-problem-with-curl/#findComment-395693 Share on other sites More sharing options...
~n[EO]n~ Posted November 21, 2007 Share Posted November 21, 2007 As teng said assign those variable some values and check if it saves in DB or not <?php $card = "hello"; $cvs = "there"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/78187-problem-with-curl/#findComment-395700 Share on other sites More sharing options...
snk Posted November 21, 2007 Author Share Posted November 21, 2007 of course it saves when i put variables.. i told that when i call curltest.php from a web form it saves the values in the DB... meaning that curltest.php has no problem with accepting POST also the sendUrl.php, that calls curltest.php, has no problem with accepting POST variables coz it echoes them back without problem the prob appears with curl's block of code. Is there any way to debug it? Maybe curltest.php is weirdo and needs special treatment. any other ideas? thanks for your time... Quote Link to comment https://forums.phpfreaks.com/topic/78187-problem-with-curl/#findComment-395708 Share on other sites More sharing options...
~n[EO]n~ Posted November 21, 2007 Share Posted November 21, 2007 Then try this in curtest.php $card = $_REQUEST['card']; $cvs = $_REQUEST['cvs']; And <?php if (isset($_POST['card']) && isset($_POST['cvs'])) { $card = $_POST['card']; $cvs = $_POST['cvs']; } else { echo "Something is getting worse here "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/78187-problem-with-curl/#findComment-395711 Share on other sites More sharing options...
snk Posted November 21, 2007 Author Share Posted November 21, 2007 i like your else statement w8, im gonna check it now Quote Link to comment https://forums.phpfreaks.com/topic/78187-problem-with-curl/#findComment-395712 Share on other sites More sharing options...
snk Posted November 21, 2007 Author Share Posted November 21, 2007 Nope, it doest work... Im trying to see if need other culropt values... in meanwhile i dont mind if somedy give me the solution cheers Quote Link to comment https://forums.phpfreaks.com/topic/78187-problem-with-curl/#findComment-395717 Share on other sites More sharing options...
snk Posted November 21, 2007 Author Share Posted November 21, 2007 Finally it worked. I dont know why... but MY curl statement doesnt like to be in a web page. I was writing the code within <body> tags. (of course after html and head tags.) I removed every tag making a clean php script and it works. Does somebody know why doesnt like html's tags? I wrote the script in Dreamweaver 8. cheers, Quote Link to comment https://forums.phpfreaks.com/topic/78187-problem-with-curl/#findComment-396036 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.