1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help with C++ and WWW POST Method

Discussion in 'C++' started by dnn_gb, Feb 21, 2007.

  1. dnn_gb

    dnn_gb New Member

    Joined:
    Feb 21, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi all,

    I need urgent help! I write windows service wich communicates with a web server with php.
    I'm using class W3Client ( http://www.codeproject.com/internet/w3client.asp ) for web requests. I have a directory content stored in C++ vector and need to post it to webpage.

    Here is stored file or dir information information:
    Code:
    class DirectoryElement
    {
          private:
                 string Name;
                 string fullPath;
                 int Type;
                 long Size;
          public:
                 DirectoryElement();
                 void setName( string name );
                 string getName();
                 void setFullPath( string name );
                 string getFullPath();
                 void setType( int type );
                 int getType();
                 void setSize( long size );
                 long getSize();
    };
    This is storage for all files and folders in one dir:
    vector<DirectoryElement> Elements;

    And I try to send them with this function:
    Code:
    void Commandexec::sendDir()
    {
         W3Client w3;
         cout<<"Using server: "<<cmdIng.getCommandingServer()<<" for sending dirs"<<endl;
         if( w3.Connect( cmdIng.getCommandingServer().c_str() ) ){
             w3.AddPostArgument("start_session", 1);
             w3.AddPostArgument("currpath", dirList.GetCurrentPath().c_str());
             if(w3.Request("/commanding/dirs.php", W3Client::reqPost)){
                   for( int j = 0; j<dirList.Elements.size(); j++ ){
                       w3.AddPostArgument("start_session", 0);
                       w3.AddPostArgument("FileNo", j);
                       w3.AddPostArgument("File", dirList.Elements[j].getName().c_str());
                       w3.AddPostArgument("FullPath", dirList.Elements[j].getFullPath().c_str());
                       w3.AddPostArgument("Type", dirList.Elements[j].getType());
                       w3.AddPostArgument("Size", dirList.Elements[j].getSize());
                       if(w3.Request("/commanding/dirs.php", W3Client::reqPost)){
                       } 
                   }                      
             }      
         }
         w3.Close(); 
    }
    And this function do not work.... :mad:

    This is php code:
    Code:
    <?php
    	include("config.php");
    
    	$ip = $REMOTE_ADDR;
    	$conn = mysql_connect($host, $user, $pass);
    	if(!$conn) die(0);
    	$dbselect = mysql_select_db($database, $conn);
    	if(!$dbselect) die(0);
    
    	$dbret = mysql_query("SELECT * FROM command WHERE id=0", $conn);
    	$dbdata = mysql_fetch_array($dbret);
    	if($dbdata[3] == $ip){
    		if($_POST["start_session"] == 1 ){
    			mysql_query("DELETE FROM dirlist", $conn);
    			$query = sprintf("INSERT INTO dirlist(id, Name, FullPath, Type, Size) VALUES(0, '%s', 'currpath', 0, 0)", $_POST["currpath"]);
    			mysql_query($query, $conn);
    		}else{
    			$query = sprintf("INSERT INTO dirlist(id, Name, FullPath, Type, Size) VALUES(%d, '%s', '%s', %d, %d)", $_POST["FileNo"], $_POST["File"], $_POST["FullPath"], $_POST["Type"], $_POST["Size"]);
    			mysql_query($query, $conn);
    
    		}
    	}
    	mysql_close($conn);
    ?>
    All code is dirty, stupid and ... but I have no time! Please help me! I'm hurry!
     

Share This Page