PHP - Multiple Radios With Searchbox To Functions Tophp_self (perform A Script) Issues
quick layout trying to accomplish
Radio Boxes O O O O O O O SEARCH .............. -OK- OK is the submit button POST should be radiox (function to run) +search user select radiobox 4 and then searches xxxaaa then presses OK then POST PHP_SELF same page being used (index.php) im having an issue trying to get the radio to be selected with teh SEARCH then SUBMIT and RUN a function to perform with the DATA //later looking at trying to view it as the script in the backend is running rather then waiting for it BUT thats just me a google to find lol <?php if (isset($_REQUEST['search'])) { $search = escapeshellcmd($_REQUEST['search']); $command = '/etc/SCRIPT/BLAHLOG ' . $search; printCmd($command, true); } ?> <?php if radio3 SELECTED THEN $search = escapeshellcmd($_REQUEST['search']); $command = '/etc/SCRIPT/BLAHSQLscript ' . $search; printCmd($command, true); ?> <form> <div id="radio"> <input type="radio" id="radio1" name="radio" /><label for="radio1">BLAhscript</label> <input type="radio" id="radio2" name="radio" /><label for="radio2">BLAHTEST</label> <input type="radio" id="radio3" name="radio" /><label for="radio3">BLAHSQLscript</label> <input type="radio" id="radio4" name="radio" /><label for="radio4">BLAHTEST</label> <input type="radio" id="radio5" name="radio" /><label for="radio5">BLAHREAD</label> <input type="radio" id="radio6" name="radio" /><label for="radio6">BLAHLOG</label> <input type="radio" id="radio7" name="radio" /><label for="radio7">BLAHUSAGE</label> <input type="radio" id="radio8" name="radio" /><label for="radio8">BLAHNETWORK</label> <input type="radio" id="radio9" name="radio" /><label for="radio9">BLAH9</label> <input type="radio" id="radio10" name="radio" /><label for="radio10">BLAH10</label> </div> </form> <p> </p> <p><strong>Enter a site:</strong> <input type="text" name="search" id="search" /> <input type="submit" value="OK"/> (PUT IT IN THE SAME PAGE from the response of RADIO4 selected ---PLUS ----SEARCH) <div id="RESPONSE" style="width: 540px"></div> Similar TutorialsHello I have a question. I'm trying to perform multiple queries based off the results from a query. Is this possible ? $result = mysql_query("SELECT id FROM sometable"); for each id returned $result1 = mysql_query("SELECT * FROM someothertable WHERE id=result from $result query"); Any help would be GREAT You would think the answer would be all over the Internet and easy to find, but it’s not. I have searched many times, and in all the multitude of search results I have still never found an adequate usable answer. The MOST you ever find is someone saying how easy it is with PHP, but they don’t tell you how, even when the person they are answering asks them (odd). You can be that one in a billion person who finally answers it for real and helps someone out. I have a simple HTML form with data fields first_name, last_name, email, phone, country, a few hidden inputs, and a single submit button, like so: (Please note: the method is GET, not Post.) <form action="https://MyDomainOnMyServer.com/MyPHPScript.php”> <input type="text" name="first_name" value="" /> <input type="text" name="last_name" value="" /> <input type="text" name="email" value="" /> <input type="text" name="phone" value="" /> <input type="hidden" name="type" value="type123"> <input type="hidden" name="project" value="new123"> <select required name="country"> <option value="">Choose your country</option> <option value="US">United States</option> <option value="CA">Canada</option> <option value="GB">United Kingdom</option> <option value="Many More">Many More Countries</option> </select> <input type="submit" value="Submit Form" /> </form> NOTE: Originally, the form action would have been: action="https://TheirExampleDomainOnTheirRemoteServer.com/TheirRemotePHPScript.php" name="form1234" Upon clicking the single submit button only, what I need to have happen is this: 1. Send me an email to whatever@whatever.tld containing all the form submission data 2. Place the form submission data into a MySQL database having the corresponding data fields 3. Send the form submission contents including the hidden input values to "https://TheirExampleDomainOnTheirRemoteServer.com/TheirRemotePHPScript.php" name="form1234" AS IF that had remained set as the original form action to begin with So basically what I’m trying to obtain is the cleanest possible PHP script that will do those three things, which is essentially what others have asked for over the years in search results I have found, but no one has ever provided it in a clear instance that works. If I can just see such a script, I should be able to see how it works and then do what I need. Thanks. Reply So I have a search function (part posted below). I have it set up that a user passes asterisk in the way that quotes would work in a normal search function. Due to the scope of the search function a pagination function can not handle quotes because it breaks the html. So what I need to do is transform the quotes a user would type into the search box into asterisks so the function will handle everything. I am assuming this is done with preg_match, but I am not familiar with preg_match at all other then what is written in manuals. Code: [Select] <?php $arr['searchterms'] = trim($arr['searchterms']); if (strstr($arr['searchterms'],'*+')) { $terms = explode('*+*',substr($arr['searchterms'],1,-1)); $case = "AND"; } else if (strstr($arr['searchterms'],'*')) { $terms = explode('* *',substr($arr['searchterms'],1,-1)); $case = " OR"; } else { $terms = explode(" ",$arr['searchterms']); $case = " OR"; } ?> I have this function: Code: [Select] function echo_exist($pre1,$ee,$post1) { if ($ee!='') { return $pre1; return $ee; return $post1; } else { //do nothing } } But when I try to echo it Code: [Select] echo_exist("(","$row['payment_type']",")"); I get syntax error, unexpected T_ENCAPSED_AND_WHITESPACE If $row['payment_type'] exists, I want it to be displayed in parentheses like: (AUTO) I suspect it has to do with my ' characters for the associative array, but I am new with functions so perhaps it is the multiple arguments that are wrong? 've create a SOAP Server using the PHP Soap functions. It has 3 functions in it and is initialised as follows; // Initialise the SOAP Server $opts = Array(); $opts['compression'] = SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP; $server = new SoapServer('SOTBWSDL.wsdl', $opts); $server->addFunction('getAvailability'); $server->addFunction('putReservation'); $server->addFunction('putCancelBooking'); $server->handle();
There are then 3 Functions as defined with the code in for each . $client = new SoapClient('http://xxxxxxxxx/SOTBWSDL.wsdl',array('trace'=>1,'exceptions=>1')); $res = $client->getAvailability($xmlparams);
This works and returns data as expected. $res = $client->putReservation($xmlparams); (To another function)
it is the first function (get Availability) that is executed. I am currently building my own MVC Framework and I have run into an issue that I can't solve when attempting to use 2 methods from a single model. I know that this isn't an issue with the queries or information being return. I am unsure of the proper way that I can call 2 methods when checking to see if a user is logged in... The issue that I face is both methods are calling the DB and it throws a PDO error which I don't know how to get around the issue.. Any guidance would be nice as I have been banging my head over this issue. Thank you!
Fatal error: Uncaught Error: Call to undefined method PDO::Select() in C:\xampp\htdocs\PicWrist\app\models\user.class.php:318 Stack trace: #0 C:\xampp\htdocs\PicWrist\app\controllers\home.php(21): User->getUser('4') #1 C:\xampp\htdocs\PicWrist\app\core\app.php(36): Home->index() #2 C:\xampp\htdocs\PicWrist\app\init.php(47): App->__construct() #3 C:\xampp\htdocs\PicWrist\public\index.php(5): require('C:\\xampp\\htdocs...') #4 {main} thrown in C:\xampp\htdocs\PicWrist\app\models\user.class.php on line 318
//Controller <?php /** * Load the View */ class Controller{ public function view($view, $data = []) { if (file_exists('../app/views/' . $view . '.php')) { require_once '../app/views/' . $view . '.php'; } } public function model($model, $data = []) { if (file_exists('../app/models/' . $model . '.class.php')) { require_once '../app/models/' . $model . '.class.php'; return new $model(); } else return false; } } ?> //Home Controller <?php Class Home extends Controller { public static $user; public $errors; public function __construct() { self::$user = $this->model('user'); } public function index() { $userdata = []; $data = []; show(self::$user); $isLoggedin = self::$user->isLoggedin; show($isLoggedin); $userdata = self::$user->getUser($_SESSION['user_id']); show($userdata); $this->view('home', $data); } } ?> <?php /** * Users */ class User { private $db; private $errors = ''; public $isLoggedin = False; public $isAdmin = False; public function __construct() { $this->isLoggedIn(); } public function isLoggedIn() { if(isset($_SESSION['user_id'])){ $data['user_id'] = $_SESSION['user_id']; $db = Database::getInstance(); $query = "SELECT * FROM users WHERE user_id = :user_id LIMIT 1"; $results = $db->Select($query, $data); if (is_array($results)) { $this->isLoggedIn = True; } } } public function getUser($id) { if(isset($id)) { $data['user_id'] = intval($id); $db = Database::getInstance(); $query = 'SELECT * FROM users WHERE user_id = :user_id'; $results = $db->Select($query, $data); if (is_array($results)) { return $results; } else { return False; } } else { return False; } } //DB <?php /** * Database Connection */ class Database { private $dbHost = DB_HOST; private $dbUser = DB_USER; private $dbPass = DB_PASS; private $dbName = DB_NAME; private $statment; private static $dbHandler; private $error; public function __construct() { $conn = 'mysql:host=' . $this->dbHost . ';dbname=' . $this->dbName; $options = array( PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ); try { self::$dbHandler = new PDO($conn, $this->dbUser, $this->dbPass, $options); } catch (PDOException $e) { self::$error = $e->getMessage(); echo self::$error; } } public static function getInstance() { if(self::$dbHandler) { return self::$dbHandler; } return $instance = new Self(); } public function Select($query, $data = array()) { $statement = self::$dbHandler->prepare($query); $result = $statement->execute($data); If($result) { $data = $statement->fetchAll(PDO::FETCH_OBJ); if(is_array($data)) { // show($data); return $data; } } return False; } public function Update($query, $data = array()) { $statement = self::$dbHandler->prepare($query); $result = $statement->execute($data); If($result) { return True; } return False; } } ?> Edited July 14 by avargas94 Wrong Code Hi, As the title suggests I am unsure on how to first run a query which stores values into an array. I then need to run a function multiple times but use the array within the function. How is this possible? I have had no luck figuring it out yet. 1. RUN QUERY 2. BUILD ARRAY USING QUERY RESULTS 3. RUN FUNCTION MULTIPLE TIMES 4. WITHIN FUNCTION I NEED TO USE ARRAY Many thanks Simon I have this script Code: [Select] <?php header("content-type: image/png"); include '../../api/config.php'; include "../../api/api.php"; $gamercard = getInfo($_GET['gamertag']); updateStats($gamercard['Gamertag'], "Nxe", 75); $type = $_GET['type']; switch ($type) { case "dark": $type = "dark.png"; break; case "light": $type = "light.png"; break; default: $type = "dark.png"; break; } $image = imagecreatefrompng("$type"); $img = imagecreatetruecolor(imagesx($image), imagesy($image)); $avatar_l = imagecreatefrompng($gamercard["Avatarpic-l"]); $avatar_body = imagecreatefrompng($gamercard["Avatarpic-body"]); imagecopy($img, $image, 0, 0, 0, 0, imagesx($image), imagesy($image)); imagecopy($img, $avatar_l, 64, 7, 0, 0, imagesx($avatar_l), imagesy($avatar_l)); imagecopy($img, $avatar_body, 175, -40, 0, 0, imagesx($avatar_body), imagesy($avatar_body)); for($i = 1; $i <=count($gamercard["RecentGames"]); $i++) { $gameimg = imagecreatefromjpeg($gamercard["RecentGames"][$i]["Icon"]); $x = ($i-1)*35 + 10; imagecopy($img, $gameimg, $x, 77, 0, 0, imagesx($gameimg), imagesy($gameimg)); } $ColorText = imagecolorallocate($img, 255, 255, 255); ImageTTFText($img, 10, 0, 10, 127, $ColorText, "font.ttf", $gamercard['Gamertag']); ImageTTFText($img, 10, 0, 135, 127, $ColorText, "font.ttf", $gamercard['Gamerscore']); imagepng($img); imagedestroy($img); ?> which is made to call the updateStats() function 1 time everytime the page loads. Heres the function (its in api.php) Code: [Select] function updateStats($gamertag, $type, $size) { $query = mysql_query("SELECT * FROM loadstats where Gamertag = '$gamertag' && Type = '$type'") or die(mysql_error()); $exists = mysql_num_rows($query); if ($exists == 0) { mysql_query("INSERT INTO loadstats (Gamertag, Type, Loads, Data) VALUES('$gamertag', '$type', '1', '$size' )") or die(mysql_error()); } else { $row = mysql_fetch_array($query); $newloads = $row['Loads'] + 1; $newdata = $row['Data'] + $size; mysql_query("UPDATE loadstats SET Loads = '$newloads' WHERE gamertag = '$gamertag' && Type = '$type'") or die(mysql_error()); mysql_query("UPDATE loadstats SET Data = '$newdata' WHERE gamertag = '$gamertag' && Type = '$type'") or die(mysql_error()); } } The wierd thing that is happening is, When i have the Header() set in the script, the updateStats() function appears to be called twice, but when the header is commented out, it is only called once. I can tell this by the change of data in the MYSQL database, the Loads value increases by 2 when the header is set, and it only creases by 1 when it isnt set. Any insight as to why this is happening would be greatly appreciated. This is a bit of a more advanced question so I am hoping there are some advanced programmers online at this time . Anyways basically I want to be able to "queue" functions from a class in a single call and am wondering if I am doing it correctly or if there is a better way to do it. Here is my code: <?php class test { private static $one; private static $two; private static $three; public function callOne($val){ $one .= $val; return $this; } public function callTwo($val){ $two .= $val; return $this; } public function callThree($val){ $three .= $val; return $this; } public function print(){ echo $this->one.' '.$this->two.' '.$this->three; } } ?> now when I want to call this I can do: $test = new test(); $test->callOne('one')->callTwo('two')->callThree('three'); $test->callOne('another one'); $test->print(); Is there a better way to do this or is there a different method of doing this? Just wanna make sure I am doing it right lol. i had this login script,i lowerized its functions a little bit but cant do more it too complicated for a newb like me can some one help me delete the activation throu email codes in these files,and those extra fields on registration form and their DB's fields for me please? all i want from this script is that i want to login wit 3 different user access 1. Create a denomination program. See the example below. Input amount: 3897 1000: 3 500: 1 200: 1 100: 1 50: 1 20: 2 10:0 5:1 1: 2 2. Create a program that will compute the ideal age of a man's wife. See the example below. Input Man's Age: 27 Formula: Man'sAge/2 + 7 Your ideal Wife's age is: 20
Please send the Output as reply and please include the codes Edited June 14 by Given-kunEdit Hi Guys Sorry for the lame title but I have absolutely no idea how to word this. I have the following code which pulls message from a database: $messages_query = mysql_query("SELECT * FROM messages WHERE id='$message_id' AND recipient='$username'"); $messages_row = mysql_fetch_assoc($messages_query); $sender = $messages_row['sender']; $date = $messages_row['date']; $time = $messages_row['time']; $subject = $messages_row['subject']; $message = $messages_row['message']; $recipient = $message_query['recipient']; echo $sender . "<br />"; echo $date . "<br />"; echo $time . "<br />"; echo $subject . "<br />"; echo $message . "<br />"; As you can see, it only pulls the data if id='$message_id' AND recipient='$username'. I wish to perform a die ("You are not authorised to view this message!"); if id='$message_id' or recipient='$username' is different. Example: The database reads id: 1 & username: user The data would be displayed if $message_id = 1 and $username = user. The die would be performed if $message_id = 5 and $username = user I hope that makes sense, iv had a problem trying to word it correctly let alone come up with a solution. Does anybody know what i could do? Thanks Hi,
I'm using an example below regarding a whole URL. I'm looking for some conditional PHP that will display certain content depending on if the URL contains the word 'liz' if not, display else.
$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; if($host == 'liz-4.website.com') Hi every one, Here is the problem.. I have a string which looks like this '(243/433)*100' , i want to calculate its value, but dont know how to do. if i use type conversion then value becomes zero. Please help. Hi , Presently we are preparing an excel for download report by querying to data base. We are querying to DB and looping through each result row and writing to excel. for 2lacs data its too much time. I found the time taken max in DB query and processing the DB data . Ant way I can make it faster ? Any parallel processing I can apply to get it faster......I expecting Huge data report in future. This is more of a logic question. I have built a beta version of my site and I am currently working on getting beta V2 out, but I want to implement location based searching of users (particularly with a google api integration). Aside from the API stuff, how do I perform location based searches on the backend. For instance, I have all of my users locations (city, state, country), but how can I say to grab all users by that state when that state is typed in or grab all users by that city when the city is typed in and the same thing for country? Is there anyway to set this up with a default radius too? So if I search for a town, I get a 20 Mile radius result? I really have no idea how to go about the dynamic look up match. Any good tutorials on this? Hello, my name Rustam, do the work - PHP MySQL JS jQuery and Yii framework.
Quickly. I am currently working on an application to schedule conferences. I have everything completed to create a conference including start time and duration. The problem I have now though is how do I monitor MySQL for the conferences that are created and perform actions when the duration of the conference is up? I was looking into MySQL events but those seem to be only internal events and are not able to execute anything outside of that. I was thinking about a infinite loop that queries MySQL and sleeps for one second but thought that this might be a lot of load on the server. Any thoughts I really appreciate it. I want to loop through a MySQL table, and perform a calculation based on the current row the loop is on and the previous loop. Say my table has 2 columns - Film_id and FilmRelease, how would I loop through and echo out a calculation of the current FilmRelease and the previous row's column value? Thanks guys I have got to this stage, but for some reason it's not printing out anything Code: [Select] <?php mysql_connect("localhost", "****", "*****") or die(mysql_error()); mysql_select_db("*****") or die(mysql_error()); $sql = mysql_query("SELECT FilmRelease FROM Films_Info") or die(mysql_error()); $last_value = null; while ($row = mysql_fetch_assoc($sql)) { if (!is_null($last_value)) { print date_diff($row['FilmRelease'], $last_value) . "<BR>"; } $last_value = $row['FilmRelease']; } |