PHP - Auto-post Data To .do
Hello,
I need to post plenty of data to a file with a java file with a .do extension using a php program. How do I get to auto-post mass data in php from a database straight to this java file? Put in mind that each mysql record is posted as its own form as in: <form ...>mysql record</form> Thanks in advance Similar Tutorials$post='{"cart_items":[{"configuration":{"price":100,"recharge_number":"9999999999"},"product_id":"999","qty":1}]}';i try this n reslut was :There are no valid items in cart: help me plz Edited by ShivaGupta, 30 November 2014 - 01:11 AM. original sql Code: [Select] -- -------------------------------------------------------- -- -- Table structure for table `countries` -- CREATE TABLE `countries` ( `id` int(6) NOT NULL auto_increment, `value` varchar(250) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=243 ; -- -- Dumping data for table `countries` -- INSERT INTO `countries` VALUES (1, 'Vancouver'); New Sql Code: [Select] -- -------------------------------------------------------- -- -- Table structure for table `countries` -- CREATE TABLE `countries` ( `id` int(6) NOT NULL auto_increment, `value` varchar(250) NOT NULL default '', `code` varchar(12) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=243 ; -- -- Dumping data for table `countries` -- INSERT INTO `countries` VALUES (1, 'Vancouver', 'BC-50'); PHP code for the job Code: [Select] <?php // PHP5 Implementation - uses MySQLi. // mysqli('localhost', 'yourUsername', 'yourPassword', 'yourDatabase'); $db = new mysqli('localhost', 'root' ,'password', 'weather'); if(!$db) { // Show error if we cannot connect. echo 'ERROR: Could not connect to the database.'; } else { // Is there a posted query string? if(isset($_POST['queryString'])) { $queryString = $db->real_escape_string($_POST['queryString']); // Is the string length greater than 0? if(strlen($queryString) >0) { // Run the query: We use LIKE '$queryString%' // The percentage sign is a wild-card, in my example of countries it works like this... // $queryString = 'Uni'; // Returned data = 'United States, United Kindom'; // YOU NEED TO ALTER THE QUERY TO MATCH YOUR DATABASE. // eg: SELECT yourColumnName FROM yourTable WHERE yourColumnName LIKE '$queryString%' LIMIT 10 $query = $db->query("SELECT your_column FROM your_db_table WHERE your_column LIKE '$queryString%' LIMIT 10"); if($query) { // While there are results loop through them - fetching an Object (i like PHP5 btw!). while ($result = $query ->fetch_object()) { // Format the results, im using <li> for the list, you can change it. // The onClick function fills the textbox with the result. // YOU MUST CHANGE: $result->value to $result->your_colum echo '<li onClick="fill(\''.$result->value.'\');">'.$result->value.'</li>'; } } else { echo 'ERROR: There was a problem with the query.'; } } else { // Dont do anything. } // There is a queryString. } else { echo 'There should be no direct access to this script!'; } } ?> What the original code does 1) you start typing your city (eg. Van) 2) when you type the first letter (eg. V), it looks into mysql and auto fills a dropdown menu with all possible cities What i need it to do 1) you start typing your city (eg. Van) 2) when you type the first letter (eg. V), it looks into mysql and auto fills a dropdown menu with all possible cities 3) when you find your city you click it or press enter, and it POST's the city code as well now how do i munipulate the script to do that... another thing, when i put the extra sql entry in "code", the auto fill stopped working, why? Thanks This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=343888.0 Currently I can use php snoopy class to auto login in wordpress, but when I try to use the same method to post some articles in wordpress. It does not work. Any one has any ideas? I have tried to use httpwatch to monitor the post data and cookies. It seems I have include everything, but still doesn't work. thanks very much. This really driving me crazy. <?php include "Snoopy.class.php"; $snoopy = new Snoopy; //login part $submit_url = "http://localhost/wordpress/wp-login.php"; $submit_vars["log"] = "baibai"; //username $submit_vars["pwd"] = "123456"; //password $submit_vars["rememberme"] = "forever"; $submit_vars["redirect_to"] = "http://localhost/wordpress/wp-admin/"; $submit_vars["testcookie"] = "1"; $submit_vars["wp_sumbit"] = "submit"; $snoopy->submit($submit_url,$submit_vars); print $snoopy->results; $snoopy->setcookies(); $cookies = $snoopy->cookies; print_r ($cookies); //above part runs perfectly //post $snoopy->fetchform("http://localhost/wordpress/wp-admin/press-this.php"); print $snoopy->results; preg_match('/name=\"_wpnonce\" value=\"([0-9a-z]+)/',$snoopy->results,$matches); print $submit_vars1["_wpnonce"] = $matches[1]; $submit_vars1["autosave"] = ""; $submit_vars1["newtag[post_tag]"] = ""; $submit_vars1["tax_input[post_tag]"] = ""; $submit_vars1["autosave"] = ""; $submit_vars1["title"] = "title"; $submit_vars1["content"] = "content this is what i want post in wordpress"; $submit_vars1["original_post_status"] = "draft"; $submit_vars1["prev_status"] = "draft"; $submit_vars1["post_type"] = "text"; $submit_vars1["publish"] = "发布"; $submit_vars1["_wp_http_referer"] = "/wordpress/wp-admin/press-this.php?u=http%3A%2F%2Flocalhost%2Fwordpress%2Fwp-admin%2Ftools.php&t=%E5%B7%A5%E5%85%B7%20%E2%80%B9%20ekeyvision%20%E2%80%94%20WordPress&s=&v=4"; $submit_url1 = "http://localhost/wordpress/wp-admin/press-this.php?action=post"; $snoopy->submit($submit_url1,$submit_vars1); print $snoopy->results; ?> Also I do not want to use XML-RPC to solve this issue, since xml-rpc are not available is some settings. thanks Hi. I am trying to get a PHP Query to refresh every 10 seconds. I have scoured the internet for days and could not find anything of much use. Plenty of Ajax going on (whatever that is) but the scripts were immense. I only want to refresh 7 lines of PHP Query Code. Can you please tell me if this is possible? Thanks in Advance. I have a form which creates a drop down list from data in a MySQL database. I would like to be able to have data from my database automatically populate based upon the selection from the list. How can I do that? Javascript? AJAX? Any help would be appreciated. Code: [Select] <?php $query2="SELECT tournament,id FROM 2011_Tournament"; $result2=mysql_query($query2); echo "<select name=2011_Tournament value='tournament'>Tournament</option>"; while($tournament=mysql_fetch_array($result2)){ echo "<option value='$tournament[tournament]'>$tournament[tournament]</option>"; } echo "</select>";?> Hi I have a little strange problem. I cannot get the post data from my form. It works fine if there is 10 or 15 user but reaching 40 or more than form values not posting. This is output of size: echo (int) $_SERVER['CONTENT_LENGTH']; ===== 22164 Code: [Select] if(isset($_POST['hiddenField'])) { // do some work; } $sql = mysql_query("SELECT id, name FROM user WHERE shop_id = '" .$_SESSION['id']. "' ORDER BY name ASC"); while($row = mysql_fetch_array($sql)) { echo ' <div style="width:100%; border:solid 1px #CCC; background-color:#f1e7e7; margin-bottom:5px;"> <table class="tableSmall"> <tr><th width="81">' .$row['name']. '</th><th width="71">'; echo $grl_pic .' </th> <td width="622"><table width="100%"> <tr>'; for($j=0; $j<7; $j++) { $sql2 = mysql_query("SELECT user_master_id, user_start, user_end FROM work_master WHERE user_master_id = '" .$row['id']. "' AND date = '" .$days_no_kanji[$j]. "'"); $row2 = mysql_fetch_array($sql2); if(mysql_num_rows($sql2) == 0) { $start = "00:00"; $end = "00:00"; $m = 0; } else { $start = $row2['user_start']; $end = $row2['user_end']; $m = 1; } echo ' <th><input type="hidden" name="userData[]" value="' .$row['id']. '_' .$j .'_' .$m. '" /> <select name="' .$row['id']. '_' .$j .'_' .$m. '_start">' .ShopHour($start). '</select><br />~<br /> <select name="' .$row['id']. '_' .$j .'_' .$m. '_end">' .ShopHour($end). '</select> </th>'; } echo ' </tr> </table></td> </tr> </table> </div>'; } Is there someone has any idea why php is not posting? Hi guys, I think I may be losing my marbles over this form I've put together. I'm trying to get my code to post the following to a database but my MySQL and PHP isn't that good, so wondering if any one could possibly suggest what I could do? Here is my code: Code: [Select] <?php // we check if everything is filled in if(empty($_POST['fname']) || empty($_POST['lname']) || empty($_POST['email'])) { die(msg(0,"All the fields are required")); } // is the sex selected? if(!(int)$_POST['sex-select']) { die(msg(0,"You have to select your sex")); } // is the birthday selected? if(!(int)$_POST['day'] || !(int)$_POST['month'] || !(int)$_POST['year']) { die(msg(0,"You have to fill in your birthday")); } // is the email valid? if(!(preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $_POST['email']))) die(msg(0,"You haven't provided a valid email")); // I think here is where I need to put something to get the data into a table! echo msg(1,"registered.html"); function msg($status,$txt) { return '{"status":'.$status.',"txt":"'.$txt.'"}'; } ?> How do I get the $_POST['day'] and $_POST['month'], $_POST['year'] etc into a table? It should be so easy but my head is hurting from trying lots of things and tutorials online. Any thoughts my PHP Freaks? im trying to understand this Post Data script it's not posting, no errors: postdata.php Code: [Select] <?php //create array of data to be posted //$post_data['firstName'] = 'Name'; $post_data['item_name'] = '12345'; //traverse array and prepare data for posting (key1=value1) foreach ( $post_data as $key => $value) { $post_items[] = $key . '=' . $value; } //create the final string to be posted using implode() $post_string = implode ('&', $post_items); //we also need to add a question mark at the beginning of the string $post_string = '?' . $post_string; //we are going to need the length of the data string $data_length = strlen($post_string); //let's open the connection $connection = fsockopen('www.example.com', 80); //sending the data fputs($connection, "POST /i.php HTTP/1.1\r\n"); fputs($connection, "Host: www.example.com \r\n"); fputs($connection, "Content-Type: application/x-www-form-urlencoded\r\n"); fputs($connection, "Content-Length: $data_length\r\n"); fputs($connection, "Connection: close\r\n\r\n"); fputs($connection, $post_string); //closing the connection fclose($connection); ?> reuslt should be posted here i.php Code: [Select] <?php require('database_connection.php');?> <?php if(isset($post_items[0])) { //$Subscription_id = mysql_real_escape_string($md5c); //$PropertyID = mysql_real_escape_string($rowData['ID']); //$User_ID = mysql_real_escape_string($rowData['User_ID']); $item_name=mysql_real_escape_string($post_items[0]); $query = 'INSERT INTO SP_subscriptions(id,) values("'.$item_name.'")'; //$query = 'INSERT INTO SP_subscriptions(id,PropertyID,User_ID) values("'.$item_name.'","'.$PropertyID.'","'.$User_ID.'")'; $success = mysql_query($query); } else { $item_name=54321; $query = 'INSERT INTO SP_subscriptions(id) values('.$item_name.')'; //$query = 'INSERT INTO SP_subscriptions(id,PropertyID,User_ID) values("'.$item_name.'","'.$PropertyID.'","'.$User_ID.'")'; $success = mysql_query($query);} //var_dump($_POST); //var_dump($query); echo $query; ?> Hi All, Not sure if this is a silly question so here we go. I have some divs that have data attributes (data-value). When i submit and post the form, can i use these values as part of the submission and put their data-value into the db? Thanks as always in advance. I'm doing an ajax call from javascript using jquery library: Code: [Select] ajaxCall: function(process, obj, type){ $.post("registration-post.php", type + "=" + process, function(data){ if(data==""){ $(obj).css(registration.errorNotificationType, registration.validatedColour); }else{ $('.error').append($.trim(data) + "<br />"); $(obj).css(registration.errorNotificationType, registration.errorColour); registration.progress = false; } } ); } When the ajax calls the php page, I want the php page to know what post information the javascript has sent, rather than pre-defining what the PHP should be trying to retrive from the POST data. Something like // pseudo $_POST["whateverwassentfromajax"] I want to do this because I want to have one function doing everything. So in my javascript I am saying, check if the username and email have already been used... But i dont want to call two different php functions. //pseudo function 1(){ $_POST["username"]; } function 2(){ $_POST["email"]; } Is there a special way to know which post data has been sent. Or do i need to do a few if statements in php. i am trying to fit this php code to so when ever i upload a video link to the database it prints in the divs from left to right. ( i have made blank boxes for where the videos should be, so you guys can see what i mean. i will give you the code here. Code: [Select] <?php $query = mysql_query("SELECT * FROM `G4V_Videos` ORDER BY `id` DESC") or die(mysql_error()); while ($data = mysql_fetch_array($query)) { ?> ID-nummer: <?php print $data['id']; ?> - Name: <?php print $data['navn']; ?> - <a href="/Video.php?id=<?php print $data['id']; ?>"><img src="http://i.ytimg.com/vi/<?php print $data['link'];?>/hqdefault.jpg" width="200" height="160" /></a><br /> <a href="/Video.php?=<?php print $data['id']; ?>"> <?php } ?> and the website is here, http://www.game4vids.com/index.php and i also want it so once i have used up all the boxes it posts the new video in box one and overwrites the old one if you get what i mean. This website is a great example of what i mean. http://www.retardo.dk So basically I'm using PHP to solve a math problem for me. The user puts in a few parameters and the program runs those numbers through the algorithm and spits out a bunch of xy coordinates. I'm using the PHP SELF method to retrieve the user input. This all works fine, but it's afterwords that I run into problems. I create a drop down menu of all the x values and I want the user to be able to choose any x value they wish and to have the corresponding y value be displayed. The problem is that I have to use another POST command for this and when I do, it wipes out all the computed data. Of course the y-value is never displayed, and there lies the problem. I'm sure there are many ways to get around this, but I could not find one out myself. Anyone have any ideas? Hello
I have a nusoap web service running, which is fine, but I need to send a new variable in the parameters which decides what database to use...
This is how I call the function:
$params = array( 'region' => '1' ); $response1 = $client->call('function1', array ($params)); // response will be in JSON Hi guys, I am creating a quiz system for my personal site, I am done with all the quiz questions creating part, but I am stuck with something like... user taking a random sql generated quiz and submitting it.. Here's randomly generated sql quiz, even the answers are in random order: <form method="post"> <b>1. What is color or sky</b> <ol> <li><input name="question_3_answer" type="radio" value="6" /> sky</li> <li><input name="question_3_answer" type="radio" value="8" />blue</li> <-- true <li><input name="question_3_answer" type="radio" value="3" />red</li> </ol> <b>2. What is name of my cat</b> <ol> <li><input name="question_6_answer" type="radio" value="9" />brat</li> <--true <li><input name="question_6_answer" type="radio" value="7" />rat</li> </ol> <b>3. What is name of my pet</b> <ol> <li><input name="question_18_answer" type="radio" value="9" />cat</li> <--true <li><input name="question_18_answer" type="radio" value="7" />dog</li> </ol> </form> Now this is tricky part for me is.. receiving these data in another page.. since it's randomly generated questions, how do I know which question it is? here's example I've tried : $list_all_quiz_questions = $db->get_row("SELECT question_id, its_true_ans_id FROM question_table WHERE quiz_group = 'ef23fsdfers3e' "); $i = 1; foreach ($list_all_quiz_questions as $myquestion) { $answer.$i == $_POST["question_".$myquestion->question_id."_answer"]; //?????????? not working lol ;(( $i++ } Hello guys. I have a form with 20 images. My user have to write a description for each image and when submitting the form the user will get an HTML code which will display an album. My problem is that my users want to choose a sequence of the images in the album. How do I solve that? I tried with making a select with 20 options (number 1-20) for each image and a desription for the user to place them in a correct sequence but I don't know how to do it. And another problem is when a user chooses the same number for more than one image. Thanks I've looked at various cURL tutorials and the PHP manual, but I don't see what I'm doing wrong here. My goal is to be able to send data to test.php and then have that page run a MySQL query to insert the TITLE and MESSAGE into the database. Any comments? :/ post.php <?php if(isset($_GET['title']) && isset($_GET['message']) && isset($_GET['times'])) { $array = array('title' => urlencode($_GET['title']), 'message' => urlencode($_GET['message'])); foreach($array as $key => $value) { $fields = $key.'='. $value .'&'; } rtrims($felds); //set our init handle $curl_init = curl_init(); //set our URL curl_setopt($curl_init, CURLOPT_URL, 'some url'); //set the number of fields we're sending curl_setopt($curl_init ,CURLOPT_POST, count($array)); for($i = 0; $i < $_GET['times']; $i++) { //send the POST data curl_setopt($curl_init, CURLOPT_POSTFIELDS, $fields); curl_exec($curl_init); echo 'post #'.$i. ' sent<br/>'; } //complete echo '<b>COMPLETE</b>'; //close session curl_close($curl_init); } else { ?> <form action="post.php" method="GET"> <table> <tr><td>Title</td><td><input type="text" name="title" maxlength="30"></td></tr> <tr><td>Content</td><td><textarea name="message" rows="20" cols="45" maxlength="2000"></textarea></td></tr> <tr><td>Process Amount</td><td><input type="text" name="times" size="5" maxlength="3"></td></tr> <tr><td>START</td><td><input type="submit" value="Initiate Posting"></td></tr> </table> </form> <?php } ?> test.php <?php mysql_connect('host', 'user', 'pass'); mysql_select_db('somedb'); if($_POST['title'] && $_POST['message']) { mysql_insert("INSERT INTO tests VALUES (null, '{$_POST['title']}', '{$_POST['message']}')"); } echo '<hr><br/>'; //query $query = mysql_query("SELECT * FROM tests ORDER BY id DESC"); while($row = mysql_fetch_assoc($query)) { echo $row['id'].'TITLE: '. $row['title'] .'<br/>MESSAGE: '. $row['message'] .'<br/><br/>'; } ?> Hi there, I am wanting to insert post data into my DB, this is guest information if i do a $safePost = filter_input_array(INPUT_POST); print_r($safePost); i get the following output. Array ( [action] => addGuestInfo [guestno] => 2 [bookingid] => 151 [customerid] => 22 [Guestname-0] => Jamie [Guestname-1] => Joe [GuestAge-0] => 4-3 [GuestInfo-0] => celiac [GuestAge-1] => 18 [GuestInfo-1] => wheat ) normally the guestname-0, guestage-0, guestinfo-0 would be in correct order but we have to ensure the just incase it isns't (see output above) we cater for that aswell, we can have upto 6 guest details coming in at once. so I need to loop through the data and insert into my DB. I have tried various for / foreach loops but cant seem to get it to group the data together I have tried things like below, but it inserts each record multiple times. $safePost = filter_input_array(INPUT_POST); foreach($safePost as $key => $value){ $exp_key = explode('-', $key); // for ($i =0; $i <= $guestcount; $i++) { switch ($exp_key[0]) { case 'Guestname': $booking->guestno = $exp_key[1]; $booking->guestname = $val; break; case 'GuestAge': $booking->guestno = $exp_key[1]; $booking->guestage = $val; break; case 'GuestInfo': $booking->guestno = $exp_key[1]; $booking->guestinfo = $val; break; default: break; } //CALLS FUNCTION TO INSERT TO DB result = lastInsertId(); $result= $booking->insertGuestDetails(); //} }
Iv tried asking a lot of people and have had no luck resolving this issue, so I will try here. I have created a Form which gathers its information from a Database. The first form is a Dropdown Option, which when submitted takes you to another page. The new page is Supposed to use the value from the Dropdown to search the database and return the proper rows to populate a few text areas to edit the values. This is where I am stuck. Compared to what most of you create this is probably sloppy and not too well structured, but I am new to this. Anyways, I will provide more information below now. The following is the initial page with the first form. This is where you would select what page you wish to edit. (I believe this may be where the issue resides) - (I included the 'num' value before the 'name' value so that I could see it is getting the value from the database, which it is) <form method="post" action="pageedit.php"><br /> <?php include "config.php"; echo "<select name=\"page\">\n"; $conn = mysql_connect("localhost", "$username", "$password"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("$database")) { echo "Unable to select $database: " . mysql_error(); exit; } $sql = "SELECT * FROM sitePages"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { echo "<option value='"; echo $row['num']; echo "'>"; echo $row['num']; echo " - "; echo $row['name']; echo "</option>"; } echo "</select>"; ?> <br /> <input type="submit" /> </form> And then the following is the page that the form is sent to when submitted: (I have attempted to Echo the 'num' value sent so that I could verify that it is indeed sent, but it is not. I will post the message I receive after the PHP snippet <form method="post" action="pageeditinsert.php"><br /> <?php include "config.php"; echo $_POST['num']; $num=$_POST['num']; $conn = mysql_connect("localhost", "$username", "$password"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("$database")) { echo "Unable to select $database: " . mysql_error(); exit; } $sql = "SELECT * FROM sitepages WHERE num = '$num'"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { echo "<input name'num' type='hidden' class='form1' value='"; echo $num; echo "' maxlength='10' id='cat' /><br /><br /><br />"; echo "<input name='name' type='text' class='form1' value='"; echo $row['name']; echo "' maxlength='20' id='name' /><br /><br />"; echo "<input name='desc' type='text' class='form1' value='"; echo $row['desc']; echo "' maxlength='100' id='desc' /><br /><br /><br />"; echo "<input name='title' type='text' class='form1' value='"; echo $row['title']; echo "' maxlength='100' id='title' /><br /><br /><br />"; echo "<input name'cat' type='hidden' class='form1' value='cat' maxlength='3' id='cat' /><br /><br /><br />"; } ?> <br /><br /><br /> <center><input type="submit" /><input type="reset" /></center> </form> Below is the message I receive when attempting to echo the POSTed 'num' value: Quote Notice: Undefined index: num in C:\wamp\www\gondieCOM\editor\edit\pageedit.php on line 16 Call Stack # Time Memory Function Location 1 0.0025 687600 {main}( ) ..\pageedit.php:0 (I am running the latest WAMP release on my personal PC for testing purposes until I have finished this and upload it to my hosting server) Anyways thanks for your time. Hopefully someone has an idea for me. Hello all, I have this issue: I have a form with several fields. I need to save to a session variable (in submit page) all of the fields upon submit and then post some of the fields to a https site using a POST request (i.e., doing a header('Location: https://mynewdomain.com/page.cfm?'.$data) won't cut it). Now, I can do it with javascript... a whole bunch of hidden fields in the between page and then auto submit the form to the mynewdomain.com domain using the post method. I am wondering whether there would be a better way for that. I know that Curl does it, with one glitch. When I set the parameter CURLOPT_FOLLOWLOCATION to true it redirects the user BUT it doesn't load any css or javascript from the new page. People say on the web to do a request for each file but I haven't figured out how to do it. Can anyone post an elegant/concrete solution to this problem or should I resort to Javascript? Thanks menwn |