PHP - Call A Php Function Using Forms?
Similar TutorialsThis topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=319682.0 I can call the following function successfully as a single php program // Acknowledge and clear the orders function ack($client, $merchant, $id) { $docs = array('string' => $id); $params = array('merchant' => $merchant, 'documentIdentifierArray' => $docs); $result = $client->call('postDocumentDownloadAck', $params); return $result; } with $result = ack($t, $merchant,'2779540483'); successful output [documentDownloadAckProcessingStatus] => _SUCCESSFUL_ [documentID] => 2779540483 I'm trying to figure out how to call this function as an object from another program. Trying the following gives error ***Call to a member function call() on a non-object*** function postDocumentDownloadAck($t, $merchant, $id) { $this->error = null; $docs = array('string' => $this->id); $params = array('merchant' => $this->merchant, 'documentIdentifierArray' => $docs); ** I've tried the following which does nothing $result = $this->soap->call('postDocumentDownloadAck', $params); ** I've tried the following - which gives error "Call to a member function call() on a non-object" $result = $this->t->soap->call('postDocumentDownloadAck', $params); if($this->soap->fault) { $this->error = $result; return false; } return $result; } *** calling program snippet for above function $merchant= array( "merchant"=> $merchantid, "merchantName" => $merchantname, "email"=> $login, "password"=> $password); $t = new AmazonMerchantAPI($merchantid, $merchantname, $login, $password); $documentlist= $t->GetAllPendingDocumentInfo('_GET_ORDERS_DATA_'); $docid = $documentlist['MerchantDocumentInfo'][$i]['documentID']; $docs = array('string' => $docid); $ackorders = $t->postDocumentDownloadAck($t, $merchant,$docs); Any ideas of what I'm doing wrong are greatly appreciated. Hi I have a table class and functions I want to call in another function but can't get it working. Some help will be very welcome. It seesm that the new table class is not working in this function if I pass the values to it, I have tested the class, it does get the post values I post to it so $_POST['id'] are being received as well as all the other $_POST's but the table class and find function is not working, it works fine if I don't put it in a function.. function edit() { if (isset($error)){ $error.="Please fix the error(s) above";} else { if ($_POST['id'] <> "") { $update =& new table($db, 'publisher'); $update->find($_POST['id']); $update->name = $_POST['name']; $update->url = $_POST['url']; $update->contact = $_POST['contact']; $update->address = $_POST['address']; $update->phone = $_POST['phone']; $update->email = $_POST['email']; $update->save(); $error = "The Publisher has been edited"; } } } Hi all, I want to call a javascript function from a php function like this: public function Buscar() { $HoraInicio = $_POST['edtHoraInicio']; $HoraFin = $_POST['edtHoraFin']; $FechaInicio = $_POST['edtFec1']; $FechaFin = $_POST['edtFec2']; $FechaMax = $FechaFin." ".$HoraFin.":00"; $FechaMin = $FechaInicio." ".$HoraInicio.":00"; $_GET["FechaMax"] = $FechaMax; $_GET["FechaMin"] = $FechaMin; echo $FechaMin; echo "<script language=javascript>alert('Hi.')</script>"; } but the function Buscar never show the alert but shows the $FechaMin I hopu u guys can help me out with this probem Thanks, Siddhartha Hi im new to php Im excellent in C# more but lets not go into that I was wondering how to call this function. What am i doing wrong.. <?php if(isset($_POST['submit'])) { $startDate = strtotime($_POST['startdate']); $endDate = strtotime($_POST['enddate']); if($startDate != false && $endDate != false) { $startDate = date("y-m-d",$startDate); $endDate = date('y-m-d',$endDate); SearchForBookedRooms($startDate,$endDate); } else { echo "Please select both dates!"; } function SearchForBookedRooms($startDate,$endDate)//Calling this Function Here?? { } } ?> Hi
I'm trying to get the layout like i want but it's not easy
I have this file
<?PHP require_once("./include/membersite_config.php"); if(!$fgmembersite->CheckLogin()) { $fgmembersite->RedirectToURL("login.php"); exit; } if(isset($_POST['submitted'])) { $fgmembersite->PesquisarPorDatas(); } ?> <div id='fg_membersite_content'> <div class="CSSTableGenerator" > //I want the result here </div> <br>I want the result of this $fgmembersite->PesquisarPorDatas(); in "//I want the result here" the r of my code, when the user use the "Pesquisar" button this fucntion is called but the result comes out of my css any help please?? Edited by alphasil, 04 December 2014 - 10:32 AM. okay in modlogs.php i have a function Code: [Select] <?php function modmenu($page) { ?> <dl><dt class="<?php if ($page == 'modlogs') echo '';else echo 'ust'; ?> LEFT" style='margin-left:5px'><a href='mlogs.php'><b>User Logs</b></a> </dt><dt class="<?php if ($page == 'modlogs1') echo '';else echo 'ust'; ?> LEFT"><a href="modlogs1.php">Topic/Forum Actions</a></dt> <dd> <?php } ?> in modlogs1.php i try to echo Code: [Select] modmenu('modlogs1'); to show the menu but i get unidentified function? lol isn't functions global wtf? Is this even possible? I'm trying to call function nameGen from in the function nameGen but I just get an error saying cannot redeclare. I only want it to return $newName when it is not in the array $takenVals. can this only be done with another loop and a constant somewhere? Code: [Select] $newVarVals = array(); $takenVals = array(); $varCount = count($varArray); // contents are set else where and is fine for($i = 0 ; $i < $varCount; ++ $i) { function nameGen(&$varCount,&$takenVals){ $newName = rand(0,$varCount); if(in_array($newName,$takenVals)) { nameGen(&$varCount,&$takenVals); } else{ return $newName; } } $newName = nameGen(&$varCount,&$takenVals); $takenVals[] = $newName; $newNameToKeep = '$_'.$newName; $newVarVals[] = array('oldName' => $varArray[$i], 'newName' => $newNameToKeep); } error: Cannot redeclare nameGen() I'm writing a program that allows users to input a stock and view a historical price chart. Code is straight out of libchart charting library. Problem is, user is supposed to enter the stock symbol from a form handler (index.php) which then passes the symbol as a variable to the charting function, which doesn't get called at all:
<? php
function index() { chart($_POST['userinput']};
} ?> .
<?php
function chart($stock)
{
$prices=getdata($stock); //returns array of prices from yahoo finance
$data=analyzer($prices); //produces metrics to be charted
graph($data); } ?> //plots the metrics, outputs .html
chart.php works on its own, as I've verified by hardcoding $argv='ibm'; in its code body. But index.php can't seem to call chart.php, as I've verified by including an echo/var_dump line in chart.php (doesn't get executed at all). It doesn't have anything to do with form handling either, as chart('ibm'); doesn't call chart.php either. I don't understand how a 6-line piece of code can be so problematic. All files are in the same folder, btw.
Thanks.
Code: [Select] <html> <center> <form method="post" action=""> <b>Email</b><br><input type="text" name="email"/><br> <b>Password</b><br><input type="password" name="password"/><br> <input type="submit" name="submit" value="Login"/><br> </form> <?php if(isset($_POST['submit'])){ echo echo_post($_POST['email']); function echo_post($postvar){ return $postvar; } } ?> </center> </html> the filename is index.php How come I get the undefined function echo_post on line 14? I know it is probably something simple but I am kind of new to this, if you could help me out that would be great I've made this code for a very simple registration form practice:
//assign form variables $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $username = $_POST['username']; function clean_names($dirty_name) { strip_tags($dirty_name); str_replace(' ', '', $dirty_name); ucfirst(strtolower($dirty_name)); //return $dirty_name; } $names = array($firstname, $lastname, $username); if(isset($_POST['register_button'])) { // WHY IS THIS FUNC CALL NOT WORKING?? foreach($names as $name) { clean_names($name); } echo "First Name: " . $firstname . "<br>"; echo "Last Name: " . $lastname . "<br>"; echo "Username: " . $username . "<br>"; }
The values are returned but they haven't been put through the clean_names function. This is the error that I am getting... Quote <br /> <b>Fatal error</b>: Call to undefined function readChatOnload() in <b>C:\server\xampp\htdocs\php\chat\readChat.php</b> on line <b>18</b><br /> And this is my php file... if(isset($_POST['function'])) { $function = $_POST['function']; switch($function) { case 'readNamesOnload': readNamesOnload(); break; case 'readNamesLoop': readNamesLoop(); break; case 'readChatOnload': readChatOnload(); break; case 'readChatLoop': readChatLoop(); break; } //READ NAMES ONLOAD function readNamesOnload() { die('readNamesOnload'); } //READ NAMES LOOP function readNamesLoop() { die('readNamesLoop'); } //READ CHAT ONLOAD function readChatOnload() { die('readChatOnload'); } //READ CHAT LOOP function readChatLoop() { die('readChatLoop'); } } I don't understand why this is happening. Thanks I'd like to set my own error handler function to clear some session variables, but I do not want to completely replace php's internal error handler message reporting. Is there any way to mimic the internal error message reporting so I can define my own error handler function. function myErrorHandler(){ unset($_SESSION['var']); // HERE EXECUTE Normal PHP error message reporting } Thanks I am getting this error: Parse error: syntax error, unexpected '[', expecting ')' in C:\xampp\htdocs\Work\Store\store.php on line 154 when I run the following code: Code: [Select] function categorySearch($sql) { $res = mysqli_query($this->conn,$sql); $this->results='<table>'; while($cRow = mysqli_fetch_array($res)) { function getCategoryName($cRow[0]) $this->results .= '<tr><td style="border: thin solid #000000;">' . $this->cat_str . '</td></tr>'; } $this->results.='</table>'; return $this->results; } Line 154 refers to this line: function getCategoryName($cRow[0]) Can anyone see what the problem is? Firstly i am new to php.Iv currently got this while loop iterating through a database drawing polygons from the info in the datatable.each polygon has its own id stored in the datatable and with the on click event i am trying to just output to the screen the specific id of the polygon clicked on.It looks ok to me but it doesnt work for some reason. Below is the loop and the function it is trying to call. /////////////////////////////////////////////////////////////////////// <?php while($info = mysql_fetch_array( $data )){ echo "<polygon fill=".$info['fill_colour']." stroke=\"black\" id=".$info['id']." onclick=\"buildingClick(id)\" points=".$info['coordinates']." />"; } ?> ///////////THIS IS THE FUNCTION/////////////////////////// <?php function buildingClick($id) { echo "building id : {$id}"; } ?> /////////////////////////////////////////////////////////////////// If anyone could help it would be hugely appreciated. Eoin Error: call to undefined function mcrypt_module_open() I have copied this code form net. And i think so that mcrypt_module_open() would be a built in function. But I think it is not so. How can i define this function. OR any other way to solve this problem?? Code: [Select] $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, ''); $iv_size = mcrypt_enc_get_iv_size($cipher); printf("iv_size = %d\n",$iv_size); $key256 = '12345678901234561234567890123456'; $key128 = '1234567890123456'; $iv = '1234567890123456'; printf("iv: %s\n",bin2hex($iv)); printf("key256: %s\n",bin2hex($key256)); printf("key128: %s\n",bin2hex($key128)); $cleartext = 'The quick brown fox jumped over the lazy dog'; printf("plainText: %s\n\n",$cleartext); if (mcrypt_generic_init($cipher, $key256, $iv) != -1) { // PHP pads with NULL bytes if $cleartext is not a multiple of the block size.. $cipherText = mcrypt_generic($cipher,$cleartext ); mcrypt_generic_deinit($cipher); // Display the result in hex. printf("256-bit encrypted result:\n%s\n\n",bin2hex($cipherText)); } if (mcrypt_generic_init($cipher, $key128, $iv) != -1) { // PHP pads with NULL bytes if $cleartext is not a multiple of the block size.. $cipherText = mcrypt_generic($cipher,$cleartext ); mcrypt_generic_deinit($cipher); // Display the result in hex. printf("128-bit encrypted result:\n%s\n\n",bin2hex($cipherText)); }Thanks In advance I am getting this error while building OOP portal.
Fatal error: Call to a member function count() on a non-object in C:\Users\Rishi\Documents\xampp\htdocs\PDO\Pitch_It\index.php on line 6
My index.php file:
<?php Hello I am on to OOP now and I dont know how to write the syntax to print the results I want The scenario is I have the abstract class, its subclass and then the object that calls the subclass, all in different files. So: part of the subclass reads: Code: [Select] function __construct($v1, $v2, $v3) { $this->speed[] = $v1; // I dont like this either, it is not elegant. I tried to put an array as argument of the constructor and send the parameters $this->speed[] = $v2; // from the object being created, but it did not work, so I leave it like this for now, but I would have preferred to put that $this->speed[] = $v3; // array and then populate it by some looping. } // METHOD TO REPORT TABLE OF ACCELERATION public function acceleration() { return $this->acceleration1 = ($this->speed[1] - $this->speed[0])/5; // I actually need to return the other two speed differences from the other stages, but as you know, once the first return acts, it exits the function // so sure this "return" has to be abandoned and the results of the function have to be printed otherwise. That is the question. } =================================== And now from the Object file I am trying to call the function, but of course, I only get one value, even if I write 3 times return Code: [Select] $objeto = new Motorbike($v1, $v2, $v3); echo '<p>The speeds are ' . $objeto->acceleration() . '</p>'; // Yes, this call works, of course, but that is about it. I cant print any other result. Thanks a lot Hi, I have the following class: class User { private $_db; public function __construct($user = null) { $this->_db = DB::getInstance(); ....... } public function find($user = null) { if($user) { $field = (is_numeric($user)) ? 'id' : 'username'; $data = $this->_db->get('users', array($field, '=', $user)); if($data->count()) { ......... return true; } } return false; }In class DB I have: public static function getInstance() { if(!(self::$_instance)): self::$_instance = new self(); endif; return self::$_instance; }public function get() in class DB, after processing, returns $this, the single instance of class DB, this is assigned to $data which is then used to invoke public function count(), a member function of class DB. I am getting the following error: Fatal error: Call to a member function count() on a non-object. I would be very grateful if someone can point out my mistake. |