PHP - Prepare Pdf Data In Byte[] Array.
Hi,
I will be creating pdf in php using following library. http://sourceforge.net/projects/pdf-php/ After creating pdf ,I want to send PDF data in byte[] to web service. Any idea how to read pdf and prepare pdf data in byte[] array. With Kind Regards, Zohaib. Similar TutorialsI'm creating a tool for building project proposals for clients, with pricing. I have a database with two tables: services and clients. The services table looks like this: Code: [Select] | code | name | cost | +-------------+-------------+------+ | logo_design | Logo design | 10 | | web_design | Web design | 20 | The clients table looks like this: Code: [Select] | id | client | logo_design | web_design | +----+---------+-------------+------------+ | 1 | Walrus | yes | yes | | 2 | Narwhal | no | yes | How would I link the results from these two tables so that I only pull out the services each person wants from the database? Here is what I have so far: Code: [Select] <? $sql = "SELECT * FROM services"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { echo $row{'name'} . ': $' . $row{'cost'} . '<br />'; } ?> This, of course, displays all the services, with all the prices, like so: Logo design: $10 Web design: $20 I want to add something here so that based on the selected client, we see only the services/prices they selected (ol' Narwhal's page would not show the "Logo Design" line). I've got the data from "clients" pulled in to this page as well, but don't know how to relate it to "services." Thanks in advance! Let me know if I've left out any info that would help you to point me in the right direction. i have a code in c# and here use GetBytes(msg) for SSlStream.write, here send and received data correctly, here all work fine, now i want to make the same event in php, but here i cant see a SslSteam or similar(i think no problem, becouse i working with socket_connection, and i think SSL is only for security), now for compare i stop the code in c# for see what data is sending and try to convert in php, for send here, i can see a data byte{} in c# and with `
$message=unpack('C*',$message);` i can convert the string to byte[], comparing with c# value is the same so, here all is ok, my problem is when i try to write the request, becouse in SslStream.write accpet byte[] but socket_write no accept whe i try send ` socket_write($socket, '\n', strlen($message))` i have a error : socket_write() expects parameter 2 to be string and obvius is becouse socket_write() only accept string, but so.. as i can send my byte[], becouse the server only accept a byte[] please help me Hello,
I am pretty new to PDO but have heard that it is good to use prepared statements to help avoid mysql injections.
What I'm wondering is, when using prepare, does one need to bind parameters or would one be able to do something like the following without risking security?
$db = new PDO(..); $r = $db->prepare("SELECT * FROM test WHERE col=$_POST['col']"); $r->execute();Thanks Hi, after banging my head against the wall for a while thinking this would be a simple task, I'm discovering that this is more complicated than I thought. Basically what I have is a link table linking together source_id and subject_id. For each subject there are multiple sources associated with each. I had created a basic listing of sources by subject... no problem. I now need a way of having a form to create an ordered list in a user-specified way. In other words, I can currently order by id or alphabetically (subject name lives on a different table), but I need the option of choosing the order in which they display. I added another row to this table called order_by. No problem again, and I can manage all of this in the database, however I want to create a basic form where I can view sources by subject and then enter a number that I can use for sorting. I started off looping through each of the entries and the database (with a where), and creating a foreach like so (with the subject_id being grabbed via GET from the URL on a previous script) Code: [Select] while($row = mysqli_fetch_array($rs)) { //update row order if (isset($_POST['submit'])) { //get variables, and assign order $subject_id = $_GET['subject_id']; $order_by = $_POST['order_by']; $source_id = $row['source_id']; //echo 'Order by entered as ' . $order_by . '<br />'; foreach ($_POST['order_by'] as $order_by) { $qorder = "UPDATE source_subject set order_by = '$order_by' WHERE source_id = '$source_id' AND subject_id = '$subject_id'"; mysqli_query($dbc, $qorder) or die ('could not insert order'); // echo $subject_id . ', ' . $order_by . ', ' . $source_id; // echo '<br />'; } } else { $subject_id = $_GET['subject_id']; $order_by = $row['order_by']; $source_id = $row['source_id']; } And have the line in the form like so: Code: [Select] echo '<input type="text" id="order_by" name="order_by[]" size="1" value="'. $order_by .'"/> (yes I know I didn't escape the input field... it's all stored in an htaccess protected directory; I will clean it up later once I get it to work) This, of course, results in every source_id getting the same "order_by" no matter what I put into each field. I'm thinking that I need to do some sort of foreach where I go through foreach source_id and have it update the "order_by" field for each one, but I must admit I'm not sure how to go about this (the flaws of being self-taught I suppose; I don't have anyone to go to on this). I'm hoping someone here can help? Thanks a ton in advance
I'd love to use anonymous placeholders on my ecommerce site project. I am writing half with php and half with golang. On the three examples below, when run, gives the following exception, " Error: Call to a member function execute() on string. " I tried it with a decimal too. Thanks in advance. $stmt = $dbo->prepare = ("SELECT * FROM products WHERE ProductName = ?"); //this one calls exception $stmt->execute(); $stmt = $dbo->prepare = ("SELECT * FROM products WHERE ProductName = ?"); //this one calls exception $stmt->bindParam(1, $productID, PDO::PARAM_INT); $stmt->execute(); $stmt = $dbo->prepare = ("SELECT * FROM products WHERE ProductName = ?"); //this one calls exception $stmt->bindValue(1, $productID, PDO::PARAM_INT); $stmt->execute(); Here is the rest of the code : <?php $filename = ""; $keyword1 = $_GET['keyword']; $titleOfSelectedDropDown = $_GET['val1']; $fileID = ""; $imageID = "a"; $displayID = ""; $keyword1 = "test"; $titleOfSelectedDropDown = "cc"; $host = 'localhost'; $user = 'root'; $pass = ''; $database = 'ecommerce'; $options = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false ); $gKeyword1 = ""; $gKeyword2 = ""; $gKeyword3 = ""; $key1ID = ""; $key2ID = ""; $key3ID = ""; $string1 = "<center><h1><u>Search Results</u><h1></center></p>"; $dbo = new PDO("mysql:host=$host;dbname=$database", $user, $pass, $options); $stmt = $dbo->prepare = ("SELECT * FROM products WHERE ProductName = ?"); $test = "1"; $stmt->execute([ $test ]); Edited March 17 by JoshEir mistake I'm trying to clean up all my functions with any queries which take dynamic parameters using PDO prepared statements. I originally thought I was using prepared statements and was told later I wasn't so it's been on my to-do list to go and clean them up. I have cleaned up a lot of them and tested them and they are working fine. This one is giving me a problem though.. /*fetch production data*/ if( isset( $field ) && isset( $type ) && isset( $value ) ) { $sql = 'SELECT id, job_number, enterprise, description, line_item, as400_ship_date FROM production_data WHERE :field :type :value ORDER BY enterprise, job_number, line_item LIMIT :offset, :records_per_page'; $stmt = $pdo->prepare($sql); $stmt->execute( [ 'field' => $field, 'type' => $type, 'value' => $value, 'offset' => $offset, 'records_per_page' => $records_per_page ] ); } else { $sql = 'SELECT id, job_number, enterprise, description, line_item, as400_ship_date FROM production_data ORDER BY enterprise, job_number, line_item LIMIT '. $offset . ', '. $records_per_page; }
It takes values from some drop downs (I'm using tabulator to generate a table and this part is related to it's pagination functions)...here is the HTML for those elements. <div class="table-controls"> <div class="form-row"> <div class="col"> <label for="filter-field" class="col-form-label-sm">Field: </label> <select id="filter-field" class="form-control form-control-sm"> <option></option> <option value="Job Number">Job Number</option> <option value="Enterprise">Enterprise</option> </select> </div> <div class="col"> <label for="filter-type" class="col-form-label-sm">Type: </label> <select id="filter-type" class="form-control form-control-sm"> <option value="like" selected="selected">Like</option> <option value="=">Equal to</option> </select> </div> <div class="col"> <label for="filter-value" class="col-form-label-sm">Value: </label> <input id="filter-value" class="form-control form-control-sm" style="float: left;" type="text" placeholder="Value to filter..."> </div> <div class="col d-flex align-content-end flex-wrap"> <button id="filter-clear" class="btn btn-primary btn-sm rounded-0">Clear Filters & Sorting</button> </div> </div> </div>
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '? ? ORDER BY enterprise, job_number, line_item LIMIT ?, ?' at line 3 in C:\wamp64\www\test\scripts\order_status.php on line 125 Just wondering if anyone knew of one? I have been looking for ages but can't find what I need. In java: Code: [Select] public class Test { public static void main(String[] args) { System.out.println((byte)0xff); } } Outputs: Code: [Select] -1 I've tried things like <?php $var = pack('H', 0xff); echo $var; ?> But that doesn't output anything Dear all, I'm trying to build an application to retrieve PDF documents from a site. The document being there is byte-served, so that I'm not able to get the complete document. When i do a curl get for the document I get only the below. Quote HTTP/1.1 302 Found Date: Mon, 02 Aug 2010 01:14:18 GMT Server: Microsoft-IIS/6.0 Via: 1.1 COMP-NLB-9C Content-Length: 176 Location: http://xxxxx.yyyy.com/0012345.pdf Content-Type: text/html; charset=utf-8 X-Powered-By: ASP.NET X-AspNet-Version: 1.1.4322 Cache-Control: private HTTP/1.1 404 Not Found Date: Mon, 02 Aug 2010 01:14:18 GMT Server: Microsoft-IIS/6.0 Via: 1.1 COMP-NLB-9C Content-Length: 1635 Content-Type: text/html; charset=ISO-8859-1 X-Powered-By: ASP.NET In firebug, I could see three GET requests. First one has the status '302 Found'. Second and third has status as '206 Partial Content'. How to get the complete file in this case. Or guide me, if I'm doing it in a wrong way. Regards, Ursvmg Hey, I am coding this forum and the following PDO prepare query calls the topic details. The prepare query works perfectly well, however when I add it into a function within another class and then call it, the script does not seem to work. I get errors like the following: Fatal error: Call to a member function fetch() on a non-object in C:\wamp\www\new\sources\forum\new.php on line 117 The prepare query fails to excute, this is because I do not know how to add it into a function. This is what I tried: Code: [Select] class FUNC { function userDetails($table, $column, $cVaulue, $oBy, $ASDSC) { global $dbh; $sth = $dbh->prepare('SELECT * FROM `'.$table.'` WHERE `'.$column.'` = '.$cVaulue.' ORDER BY `'.$oBy.'` '.$ASDSC.''); $sth->bindParam(':id', $id, PDO::PARAM_INT); $sth->execute(); } } The FUNC class is called as the $load variable, and in my forum class I have decalred it in my global so the variable can be passed: Code: [Select] $id = $forum_data['id']; $load->userDetails('db_topics', 't_forum_id', ':id', 't_whenlast', 'DESC'); $coll=$sth->fetch(PDO::FETCH_ASSOC); $this->html->RightForum($coll); The code is very silly, but the fact is I did not know how to do this.. Please help me put this query into a function because I need to make use of it in many other parts of the forum and I don't want to constantly declare this query. I have this at the top of my index.php: <?php session_start(); // start of script every time. // setup a path for all of your canned php scripts $php_scripts = '/home/larry/web/test/php/'; // a folder above the web accessible tree // load the pdo connection module require $php_scripts . 'PDO_Connection_Select.php'; require $php_scripts . 'GetUserIpAddr.php'; //******************************* // Begin the script here $ip = GetUserIpAddr(); if (!$pdo = PDOConnect("foxclone")): { echo "Failed to connect to database" ; exit; } else: { $stmt = $pdo->prepare("INSERT INTO 'download' ('IP_ADDRESS', 'FILENAME') VALUES (?, ?"); $stmt->bindParam(1, $ip); $stmt->bindParam(2, $filename); $stmt->execute(); } endif; //exit(); ?> I'm getting the following error at the $pdo->prepare line: Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''download' ('IP_ADDRESS','FILENAME') VALUES (?, ?' at line 1 in /home/larry/web/test/public_html/index2.php:23 Stack trace: #0 /home/larry/web/test/public_html/index2.php(23): PDO->prepare('INSERT INTO 'do...') #1 {main} thrown in /home/larry/web/test/public_html/index2.php on line 23 I verified the format of the statement at https://www.w3schools.com/php/php_mysql_prepared_statements.asp but am unsure if it needs to be in the PDO_Connection_Select.php, or it belongs where I have it since the db is already connected. Hello, I have this code
<?php $stmt = $db->prepare("INSERT INTO `members` (`playername`,`player_login_name`,`player_login_pass`,`my_email`, `my_gender`,`signup_IP`,`signup_time`) VALUES(?,?,?,?,?,?,?)"); $stmt->bind_param("ssssssi",$_POST['email'],$_POST['email'],md5($_POST['pass']),$_POST['email'],$_POST['gender'],$_POST['REMOTE_ADDR'],time()); $stmt->execute(); $stmt->close(); ?>and i will not insert into my database. I have check the syntax and there is no error, can anyore help me thanks with php pdo, the bindParam is not working. The query outputs :words and instead of the $words value. How can i get this code working?
$sql = "SELECT count(*) FROM posts WHERE MATCH (comments) AGAINST (':words' IN BOOLEAN MODE)"; $stmt = $db->prepare($sql); $stmt->bindParam(':words', $words); $stmt->execute();which code example is more safe? The code below now has $words instead of :words but is missing bindParam. $stmt = $db->prepare(SELECT count(*) FROM posts WHERE MATCH (comments) AGAINST ('$words' IN BOOLEAN MODE)"); $stmt->execute();$words is passed through both php $_get and $_post hi i am trying to make a payroll calculator script that takes employee info, calculates pay, displays submitted info in a table, stores info in an array, and updates the array when new info is submitted. i have most of these accomplished, i am having trouble with the "store into an array, and update the array when new info is submitted" parts of the project. i am still not very fluent in php so there may be easier ways to achieve what i have so far. any pointers would be a great help, this part has got me stumped. Using curl_multi, I have loaded up 3 url's and then printed the array. 1) How can I also set a timestamp on output to let me know when each url was run? 2) How can I explode the array to only display the data and timestamp, excluding the text "Array ( =>", "[1] =>", "[2] =>" and " )"? Code <?php function multiRequest($data, $options = array()) { // array of curl handles $curly = array(); // data to be returned $result = array(); // multi handle $mh = curl_multi_init(); // loop through $data and create curl handles // then add them to the multi-handle foreach ($data as $id => $d) { $curly[$id] = curl_init(); $url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d; curl_setopt($curly[$id], CURLOPT_URL, $url); curl_setopt($curly[$id], CURLOPT_HEADER, 0); curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1); // post? if (is_array($d)) { if (!empty($d['post'])) { curl_setopt($curly[$id], CURLOPT_POST, 1); curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']); } } // extra options? if (!empty($options)) { curl_setopt_array($curly[$id], $options); } curl_multi_add_handle($mh, $curly[$id]); } // execute the handles $running = null; do { curl_multi_exec($mh, $running); } while($running > 0); // get content and remove handles foreach($curly as $id => $c) { $result[$id] = curl_multi_getcontent($c); curl_multi_remove_handle($mh, $c); } // all done curl_multi_close($mh); return $result; } $data = array(array(),array()); $data[0]['url'] = 'http://search.yahooapis.com/VideoSearchService/V1/videoSearch?appid=YahooDemo&query=Pearl+Jam&output=json'; $data[1]['url'] = 'http://search.yahooapis.com/VideoSearchService/V1/videoSearch?appid=YahooDemo&query=Black+Eyed+Peas&output=json'; $data[2]['url'] = 'http://search.yahooapis.com/VideoSearchService/V1/videoSearch?appid=YahooDemo&query=Nirvana&output=json'; $r = multiRequest($data); print_r($r); ?> Output Array ( => Pearl Jam [1] => Black Eyed Peas [2] => Nirvana ) Preferred Output 01:00:01 Pearl Jam 01:00:02 Black Eyed Peas 01:00:03 Nirvana hey... found this website when googling for a php help forum... hopefully this is the right place. I am about to start a major project for a new high profile company contract my company is presently bidding on. One of the requirements is a web interface to communicate between the 2 companies. I recently read (and have been reading more into it) that MDB2 is (one of) the best methods to communicate with a database (using prepared statements). It seems to be extremely popular, and not to difficult to use... however, for some reason, it just wont work for me. Code: [Select] <?php require_once '/include/MDB2.php'; function connect(){ $SQL = array( 'driver' => 'mysql', 'user' => '***', 'pass' => '***', 'host' => '127.0.0.1', 'dbname' => '***', ); $SQL['sql'] = $SQL['driver']."://".$SQL['user'].":".$SQL['pass']."@".$SQL['host']."/".$SQL['dbname']; $mdb2 = MDB2::connect($SQL['sql']); $mdb2->setOption('emulate_prepared',true); if(PEAR::isError($mdb2))die("Error while connecting : " . $mdb2->getMessage()); return $mdb2; } $mdb2 = connect(); $statement = $mdb2->prepare("INSERT INTO `test` (id,name) VALUES (?, ?)", array('integer','text'), MDB2_PREPARE_MANIP); $statement->execute(array(1,'someuser')); $statement->free(); ?> For some reason, this is not working? However if I just execute a normal query, it works no problem: Code: [Select] <?php $mdb2 = connect(); $statement = $mdb2->query("INSERT INTO `test` (id,name) VALUES (1,'someuser')"); ?> So, I am connecting properly, everything is good... but this prepared statement just hates me Any help please? I've been pulling my hair out for the past couple of hours working with simplexml_load_file(). I was attempting to consume a web service generated by asp.net that I've been consuming using CURL and a function to remove the BOM (byte order marker) so that I could load it into simplexml_load_string(). When I switched over to simplexml_load_file() to call the file instead of using CURL and my function, I was getting errors that it could not find the beginning '<' and that the document was empty and so on.. I couldn't find anything about simplexml_load_file() handling BOM characters, so I went for a walk. I came back to my desk and refreshed the page.. and it just started working. I changed nothing! Guess I should be happy that it started working, but I'd sure like to know why it was breaking in the first place, and then why it would suddenly start working without me doing anything. Has anyone else seen anything like this? Excerpts of code: function addUser() { $username = $_POST['username']; $password = password_hash($_POST['password'], PASSWORD_DEFAULT); $bio = $_POST['bio']; $email = $_POST['email']; $c_status = 0; //$avatar = //$username_query = $pdo->prepare("SELECT * from profiles001 WHERE username=':username'"); //$username_query->bindValue(':username', $username); //$username_query->execute(); $query = $pdo->prepare("INSERT into profiles001 (username, password, email, c_status, bio) VALUES (:username, :password, :email, :cstat, :bio)"); $query->bindValue(':username', $username); $query->bindValue(':password', $password); $query->bindValue(':email', $email); $query->bindValue(':cstat', $c_status); $query->bindValue(':bio', $bio); $query->execute(); setAvatar(); } function setAvatar() { // check if avatar is set, if not give default avatar if (isset($file) && $fileError === UPLOAD_ERR_OK) { $file = $_FILES['userfile']; $fileName = $file['name']; $fileTmpName = $file['tmp_name']; $fileSize = $file['size']; $fileError = $file['error']; $fileType = $file['type']; $fileExt = explode('.', $fileName); $fileActualExt = strtolower(end($fileExt)); $allowedExtensions = array('jpg', 'jpeg', 'png'); } // if user has not assigned avatar, assign the default. if (empty($file)) { $avatar = "assets/soap.jpg"; $query = $pdo->prepare("INSERT INTO profiles001 (avatar) VALUES (:avatar)"); $query->bindValue(':avatar', $avatar); $query->execute(); } } addUser(); } From the database file: <?php $host = "localhost"; $database = "soapbox"; $username = "drb"; $password = "m1n3craft"; // Create connection $pdo = new PDO('mysql:host=localhost;dbname=soapbox;', $username, $password); /* Print error message and or code to the screen if there is an error. */ ?> NOTE: I also require dbcon.php at the top of the confirmation.php file which is NOT included in the excerpt at the top. Making pdo a global variable would probably fix it, but from what I heard globals are frowned upon. Hi All, I have the following code which works fine: $mysqli = new mysqli("server", "user", "pass", "database"); if($mysqli->connect_error) { exit('Could not connect'); } $sql = "SELECT customer_contactname, customer_companyname, customer_phonenumber, customer_emailaddress, customer_address1, customer_address2, customer_city, customer_postcode FROM ssm_customer WHERE customer_id = ?"; $stmt = $mysqli->prepare($sql); $stmt->bind_param("s", $_GET['q']); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($ccontname, $ccompname, $cphoneno, $cemail, $cad1, $cad2, $ccity, $cpost); $stmt->fetch(); $stmt->close(); however, when i use my dbconn.php as an include rather than the top section of this code, i get the following error: function prepare() on null The error references the following $stmt = $mysqli->prepare($sql); In my database connection file, i am using the following: $conn = mysqli_connect($db_servername, $db_username, $db_password, $db_name); This seems to be the issue and i believe i am mixing procedural and object based but not sure why there should be a difference here? when i used my database connection file, i do change $mysqli->prepare to $conn->prepare Kind Regards Edited February 4, 2019 by AdamhumbugHello, I have a variable called $Price, We are getting it through Mysql Database using While loop. We getting the data from database in ordered by ID. Now then i have requirement to store that data into Low to High form ... Like we are receiving $price lke unordered form .. 50 14 35 25 00 145 52 Here i just want to store it in Low to high form like 00, 14,25,35 ... and so on .. Please suggest me the appropriate code. While($myrow=mysql_fetch_array($result, MYSQL_ASSOC)) { some codes return value $price. // want to store in array } $array($price) // here want to store in Low to high with key value. Hi All, Just wondering whether it is possible to resize a jpg image to a specific size in bytes (while preserving height/width ratio). Thanks for any clues! |