hi, iam just a beginner with php and curl.i search a lot but not able to find out the find out the problem i am gating.
I am first sending data to a php a file then using CURL on the php file iam sending data to another php file.but its not working.PLZ help me .
THIS ism y html form by this i am posint some data to a php file named curlpostv.php
curlpostv.html -
-
<html>
-
<body>
-
<form name="f1" method="post" action="curlpostv.php">
-
Name:<input type="textbox" name="name"><br>
-
Sex: MALE<input type="radio" name=r1 value="MALE">
-
FEMALE<input type="radio" name=r1 value="FEMALE"> <br>
-
MBA <input type="checkbox" name=c1 value="MBA">
-
MCA <input type="checkbox" name=c2 value="MCA"> <br>
-
<input type="submit" value="click">
-
-
</form>
-
</body>
-
</html>
-
curlpostv.php -
<?php
-
$name=$_POST["name"];
-
$sex=$_POST["r1"];
-
-
if(isset($_POST["c1"])==true && isset($_POST["c2"])==true)
-
{
-
$qua=$_POST["c1"]+$_POST["c2"];
-
}
-
elseif(isset($_POST["c1"])==true)
-
{
-
$qua=$_POST["c1"];
-
}
-
elseif(isset($_POST["c2"])==true)
-
{
-
$qua=$_POST["c2"];
-
-
}
-
-
//echo $name.$sex,$qua;
-
-
$ch=curl_init();
-
curl_setopt($ch,CURLOPT_URL,"http://localhost/curl/curlpostval/cgrabval.php");
-
curl_setopt($ch,CURLOPT_POST,1);
-
curl_setopt($ch,CURL_POSTFIELDS,'N=$name&S=$sex&Q=$qua');
-
-
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
-
curl_exec($ch);
-
echo curl_error($ch);
-
curl_close($ch);
-
?>
-
cgrabval.php -
<?php
-
echo "You are".$_POST["N"];
-
echo $_POST["S"];
-
echo $_POST["Q"];
-
?>
-
i should see the outputs here but nothing shown
i am new to this community so no idea how i be informed if someone post a reply emailremoved@no emailsplease.co m this is my email address plz help me or send a offline msg
13 3887 Motoma 3,237
Recognized Expert Specialist
Try hard coding values for your cURL call to see narrow down where the error is happening.
This is not causing a problem, but I think just:
$qua=$_POST["c1"]+$_POST["c2"];
would do the same job as all your: if(isset($_POST ....
I know it's commented out, but the line:
//echo $name.$sex,$qua ;
has got a comma in it. Surely that will cause an error?
And now to get to the point!
Your problem might be that you need to urlencode() your form data.
When you send form data using cURL you need to replace any characters that are not letters or number with their 'special url' equivilents.
Your web browser does this for you, so if you typed
"Joe Bloggs" into the 'name' field, your web browser actually sends
"name=Joe+Blogg s". cURL does not do this for you, so you need to use the
urlencode() function to do this for you;
$name = urlencode($_POS T['name']);
You don't need to do it for the others because they are radio buttons/checkboxes and they don't have any non-alpha-numeric characters in the values.
Try that and see if it works
It still not working
i use the urlencode still not working
Another thing u said i donot have to use ulrencode() for radio button/checkbox so atleast i should see those value.
curlpostval.php
<?php
header('Content-Type: text/html');
$name=urlencode ($_POST["name"]);
$sex=$_POST["r1"];
if(isset($_POST["c1"])==true && isset($_POST["c2"])==true)
{
$qua=$_POST["c1"]+$_POST["c2"];
}
elseif(isset($_ POST["c1"])==true)
{
$qua=$_POST["c1"];
}
elseif(isset($_ POST["c2"])==true)
{
$qua=$_POST["c2"];
}
$ch=curl_init() ;
curl_setopt($ch ,CURLOPT_URL,"h ttp://localhost/curl/curlpostval/cgrabval.php");
curl_setopt($ch ,CURLOPT_POST,1 );
curl_setopt($ch ,CURL_POSTFIELD S,'N=$name&S=$s ex&Q=$qua');
curl_setopt($ch , CURLOPT_FOLLOWL OCATION, 1);
curl_exec($ch);
echo curl_error($ch) ;
curl_close($ch) ;
?>
cgrabval.php
<?php
echo "You are".$_POST["N"];
echo $_POST["S"];
echo $_POST["Q"];
?>
Ah. Try this:
In this line:
curl_setopt($ch ,CURL_POSTFIELD S,'N=$name&S=$s ex&Q=$qua');
You've got the variables ($name,$sex,$qu a) inside single quotation marks. So php wont put the values of $name,$sex etc into the post fields it will literally put in "$name" and "$sex". I'm surprised that when you print out the information in
cgrabval.php it doesn't print "You are$name". Try chaging your code to this:
curl_setopt($ch ,CURL_POSTFIELD S,'N='. $name .'&S='. $sex .'&Q='. $qua);
See what that does.
I don't think you need the line;
curl_setopt($ch , CURLOPT_FOLLOWL OCATION, 1);
You would only need that if cgrabval.php was going to redirect you to somewhere else.
Actually, no I'm not surprised that cgrabval.php doesn't print anything out because if you were to urlencode "$" it would get turned into "%24", so having $ in your post field is confusing the hell out of it!
Another thought: are you sure that cgrabval.php is successfully being called by cURL? I tried doing:
curl_setopt($ch ,CURLOPT_URL,"h ttp://localhost/myfile.php");
a couple of days ago and I couldn't get it to work. Not sure which operating system you're on, I'm on Max OS X (10.4.8)
Change curlpostval.php to just this:
[PHP]$ch=curl_init() ;
curl_setopt($ch ,CURLOPT_URL,"h ttp://localhost/curl/curlpostval/cgrabval.php");
curl_setopt($ch ,CURLOPT_HTTPGE T,1);
curl_exec($ch);
echo curl_error($ch) ;
curl_close($ch) ;[/PHP]
And change cgrabval.php to just;
[PHP]echo "this is cgrabval.php";[/PHP]
That way you've taken the $_POST stuff out of the equation completely. When you're sure that cURL is successfully connecting to cgrabval.php, then try putting the $_POST stuff back.
Thanks for the response again but its not working again.
Is this a php bug?
here is the output what iam gating
Cgrabval.php called
You are
i am using wamp5 in xpsp2 .
i havenot test it to linux yet but as other curl programming running successfully it should work here.
my other program of fatching a page by curl working successfully
Just this posting value not working.
this is what make change as u suggested
curlpostval.php
<?php
header('Content-Type: text/html');
$name=$_POST["name"];
$name=urlencode ($name);
$sex=$_POST["r1"];
if(isset($_POST["c1"])==true && isset($_POST["c2"])==true)
{
$qua=$_POST["c1"]+$_POST["c2"];
}
elseif(isset($_ POST["c1"])==true)
{
$qua=$_POST["c1"];
}
elseif(isset($_ POST["c2"])==true)
{
$qua=$_POST["c2"];
}
$ch=curl_init() ;
curl_setopt($ch ,CURLOPT_URL,"h ttp://localhost/curl/curlpostval/cgrabval.php");
curl_setopt($ch ,CURLOPT_POST,1 );
curl_setopt($ch ,CURL_POSTFIELD S,'N='.$name.'& S='.$sex.'&Q='. $qua);
curl_exec($ch);
echo curl_error($ch) ;
curl_close($ch) ;
?>
cgrabval.php
<?php
echo "Cgrabval.p hp called"."<br>";
echo "You are".$_POST['N'];
echo $_POST['S'];
echo $_POST['Q'];
?>
curlpostv.html
<html>
<body>
<form name="f1" method="post" action="curlpos tv.php">
Name:<input type="textbox" name="name"><br >
Sex: MALE<input type="radio" name=r1 value="MALE">
FEMALE<input type="radio" name=r1 value="FEMALE"> <br>
MBA <input type="checkbox" name=c1 value="MBA">
MCA <input type="checkbox" name=c2 value="MCA"> <br>
<input type="submit" value="click">
</form>
</body>
</html>
Motoma 3,237
Recognized Expert Specialist
Would you PLEASE use the PHP tags?
very sorry but
i am using php tags
<?php
?>
what u mean by tag.i am very new to php and this kind of community so no idea.
Motoma 3,237
Recognized Expert Specialist
If you read through the Posting Guidelines, it states quite clearly that when you post code to the forum, you are to use appropriate code tags, to enable color, syntax highlighting, and proper tab spacing. You can do this in the PHP forum by placing [PHP ] [/PHP] around your code, or by utilizing the PHP button at the top of the text entry field.
<?php
$phrase = "This is what inappropriately tagged PHP code looks like";
print $phrase;
?>
[PHP]
<?php
$phrase = "This is what appropriately tagged PHP code looks like";
print $phrase;
?>
[/PHP]
Doing this will help us without webserver nearby debug your code.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Peter Valdemar M?rch |
last post by:
Hi,
In short, how to modify selected tags/sections of a HTML file, using
PHP as the "modifier"/filter? I would have thought this was a very
common usage for PHP...
I have a set of existing .html files that are plain and ugly. I'd like
to create a showdoc.php filter that adds consistent menus, css, look
and feel, so that http://me/showdoc.php?d=story shows a nicely
formatted http://me/story.html
|
by: benji |
last post by:
I have set up a system to download datafeeds in pain text or zipped.
The download part of this system uses the curl extension to download
the files.
All was well when I tested it with various datafeeds in zipped and
unzipped formats until I came to download zipped files from the
affiliate program we are starting with.
I have verified that the datafeeds download properly in Internet
Explorer but interestingly they also fail in Firefox.
|
by: jimb |
last post by:
I need some advice on how to securely transfer data between two servers.
Here is the situation. We have two sql servers that hold student data.
I have full access to my sql server, but only write access to the main
sql server on campus. I hope to use XML and SSL to transfer student
data to the main server.
As for generating the XML, I'll have an asp.net page set up in a secure
directory that will generate the data in xml format. The...
|
by: Tommaso Caldarola |
last post by:
I'm using a Remoting to manage small set of data, now the customer wants to
transfer big binary files (up to 10 Gb) between 2 computers.
It's better to use socket or other technology or I can continue using Remoting
without problems with great quantity of data to pass through boundaries.
TIA
--
|
by: meetalps |
last post by:
Hi All,
Can you please help me with a step by step procedure to transfer files
from my PC to DB2-AIX and vice versa. I am new to both.
Example transferring a sql file to run from PC to DB2 on AIX.
PC-OS windows
DB2 on AIX platform.
Thanks.
| |
by: Raj |
last post by:
Hi,
I am newbie to programming with libcurl. the problem is i want to send
my gmail username and password outside the browser and get access to my
mail. this i am doing with LibCurl. Though i dont get any errors, i am
nt able to get the o/p Can anyone kindly help. i will attach the
program here
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
|
by: Raj |
last post by:
Hi,
I am newbie to programming with libcurl. the problem is i want to send
my gmail username and password outside the browser and get access to my
mail. this i am doing with LibCurl. Though i dont get any errors, i am
nt able to get the o/p Can anyone kindly help. i will attach the
program here
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
|
by: Norman Peelman |
last post by:
From: "Norman Peelman" <npeelman@cfl.rr.com>
Subject: Re: posting form data to two php scripts at once
Date: Sunday, December 17, 2006 12:06 AM
<one.1more@gmail.comwrote in message
news:1166317725.715320.309280@80g2000cwy.googlegroups.com...
Yes, you just have to call the second script from the first. You could
try:
|
by: cbs81 |
last post by:
hi all,
problem:
transferring data from workbooks that are stored in a particular directory from excel to a table in access. when done, the workbooks that have been processed are automatically moved into a directory named “processed” . all using vba.
this is the pretty complex vb problem that i need some expert solution to.
overview.
i have created a cash reconciliation application in excel saved by month for each of my bus...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |