Re: [PHP] mysql and php
Display the different ways in which you've seen php using mysql, and we'll see if any one of them is any more secure than another. Most Security issues can be left to MySQL and the MySQL API. A few pointers - Store parameters(username/password) outside the DocuementRoot. Put your server on local host - or create an ssh/ssl tunnel between the PHP machine, and the DB. Cast any numbers, and escape any strings. ( mysql_escape_string ) Configure mysql securely - this is outside the scope of an email. On 4/14/06, benifactor [EMAIL PROTECTED] wrote: i was wondering what is the most secure way to use mysql in php. is there a certain way it should be done or a way that is more secure than another? iv'e seen it done many ways and was wondering if it was just preference or a if there was a reason behind it. if you guys could post some examples of how you do it and why maybe you could help me understand or know of an article or tutorial on the subjecti would appreciate it.
Re: [PHP] mysql with php
$sql = select User_name, User_pass from user where User_name = '$_POST[user_id]' and User_pass = '$_POST[user_pass]'; assuming user_id isnt an int Rittwick Banerjee wrote: Hi friends, I am Rittwick Banerjee and i have made a mysql based user name and password program but I found that what ever I entered in the user name and password feild the php file dose not working. I set this code for user name and password $sql = SELECT `User_name` AND `User_pass` FROM `user` WHERE `User_name`= '$_POST[user_id]' AND `User_pass` = '$_POST[user_pass]' But this code dose not working properly. This code dosen't checking if the user name and password is correct or incorrect Please help me with some source code. Thank you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] mysql with php
-Original Message- From: Rittwick Banerjee [mailto:[EMAIL PROTECTED] Sent: Friday, May 20, 2005 3:59 AM To: php-general@lists.php.net Subject: [PHP] mysql with php Hi friends, I am Rittwick Banerjee and i have made a mysql based user name and password program but I found that what ever I entered in the user name and password feild the php file dose not working. I set this code for user name and password $sql = SELECT `User_name` AND `User_pass` FROM `user` WHERE `User_name`= '$_POST[user_id]' AND `User_pass` = '$_POST[user_pass]' But this code dose not working properly. This code dosen't checking if the user name and password is correct or incorrect Please help me with some source code. Thank you. Your code seems non-sensical to me. There are lots pf considerations to take into account with passwords and security, but on a very basic level. heres what I think you're after: $sql=select User_pass from user where user_name = $_POST[user_id]; $result=mysql_query($sql); $row=mysql_fetch_array($result); if($row[user_pass]==$_POST[user_pass]){ echo Access Granted! }else{ echo Access Denied! } JM -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] mysql with php
Noticed that there was still something missing in this: $sql = select User_name, User_pass from user where User_name = '$_POST['user_id']' and User_pass = '$_POST['user_pass']'; Quotes around the POST Args. George -Original Message- From: eoghan [mailto:[EMAIL PROTECTED] Sent: 20 May 2005 11:21 am To: Rittwick Banerjee Cc: php-general@lists.php.net Subject: Re: [PHP] mysql with php $sql = select User_name, User_pass from user where User_name = '$_POST[user_id]' and User_pass = '$_POST[user_pass]'; assuming user_id isnt an int Rittwick Banerjee wrote: Hi friends, I am Rittwick Banerjee and i have made a mysql based user name and password program but I found that what ever I entered in the user name and password feild the php file dose not working. I set this code for user name and password $sql = SELECT `User_name` AND `User_pass` FROM `user` WHERE `User_name`= '$_POST[user_id]' AND `User_pass` = '$_POST[user_pass]' But this code dose not working properly. This code dosen't checking if the user name and password is correct or incorrect Please help me with some source code. Thank you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql with php
try this: $sql = SELECT User_name, User_pass FROM `user` WHERE User_name= '$_POST[user_id]' AND User_pass = '$_POST[user_pass]' ; -afan Rittwick Banerjee wrote: Hi friends, I am Rittwick Banerjee and i have made a mysql based user name and password program but I found that what ever I entered in the user name and password feild the php file dose not working. I set this code for user name and password $sql = SELECT `User_name` AND `User_pass` FROM `user` WHERE `User_name`= '$_POST[user_id]' AND `User_pass` = '$_POST[user_pass]' But this code dose not working properly. This code dosen't checking if the user name and password is correct or incorrect Please help me with some source code. Thank you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] MySQL query/PHP logic?
select * from main left join fof on main.id = fof.id left join pub on main.id = pub.id left join gov on main.id = gov.id left join med on main.id = med.id left join ngo on main.id = ngo.id left join own on main.id = own.id left join sup on main.id = sup.id [snip] BUT, although it seems to be joining the tables correctly AND only returning the ones with the correct date criteria, it does NOT return the id or the information_sent fields correctly ( due to duplication in the result ) Can this be done in one query without sub-selects, or should it be broken up (in which case I would still need help with the logic and to minimize the amount of queries inside loops) Instead of select * list out the fields you want to select and alias the duplicates, for example select fof.id as fof_id, pub.id as pub_id, gov.id as gov_id etc. Then when you do you mysql_fetch_array the indexes will be the aliases you gave the columns so nothing will get overwritten. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL query/PHP logic?
Don't know whether it's just because it's late at night here in the UK or whether I'm being a bit dim, but wouldn't it be much, much easier to store all the data in your non-main tables in a single table and distinguish the type of data (i.e. fof, pub, gov, etc) by a field. This would simplify your query and no doubt improve performance. On Tuesday 29 Jul 2003 10:13 pm, Petre Agenbag wrote: Hi List OK, I've posted this on the MySQL list as well, but it seems a bit quiet there, and arguably it could definately be a PHP rather than mysql question depending on whether it can be done with one query (then it was/is a mysql query), or whether it should be done with some structures and multiple queries ( then it's arguably PHP). So, here goes. I'm trying to return from multiple tables, the records that have field information_sent between two dates. The tables are all related by means of the id of the entry in the main table, ie.. main identity_name ... fof id_fofid information_sent ... pub id_pubid information_sent ... etc. So, I tried the following join select * from main left join fof on main.id = fof.id left join pub on main.id = pub.id left join gov on main.id = gov.id left join med on main.id = med.id left join ngo on main.id = ngo.id left join own on main.id = own.id left join sup on main.id = sup.id left join tra on main.id = tra.id where ( (fof.information_sent '$date1' and fof.information_sent '$date2') OR (pub.information_sent '$date1' and pub.information_sent '$date2') OR (gov.information_sent '$date1' and gov.information_sent '$date2') OR (med.information_sent '$date1' and med.information_sent '$date2') OR (ngo.information_sent '$date1' and ngo.information_sent '$date2') OR (own.information_sent '$date1' and own.information_sent '$date2') OR (sup.information_sent '$date1' and sup.information_sent '$date2') OR (tra.information_sent '$date1' and tra.information_sent '$date2') ) order by entity_name BUT, although it seems to be joining the tables correctly AND only returning the ones with the correct date criteria, it does NOT return the id or the information_sent fields correctly ( due to duplication in the result ) Can this be done in one query without sub-selects, or should it be broken up (in which case I would still need help with the logic and to minimize the amount of queries inside loops) Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL query/PHP logic?
Try something like this. select fof.id AS fof_id, fof.information_sent AS fof_info, pub.id AS pub_id, pub.information_sent AS pub_info, gov.id AS gov_id, gov.information_sent AS gov_info, med.id AS med_id, med.information_sent AS med_info, ngo.id AS ngo_id, ngo.information_sent AS ngo_info, own.id AS own_id, own.information_sent AS own_info, sup.id AS sup_id, sup.information_sent AS tup_info, tra.id AS tra_id, tra.information_sent AS tra_info, from main left join fof on main.id = fof.id left join pub on main.id = pub.id left join gov on main.id = gov.id left join med on main.id = med.id left join ngo on main.id = ngo.id left join own on main.id = own.id left join sup on main.id = sup.id left join tra on main.id = tra.id where ( (fof.information_sent '$date1' and fof.information_sent '$date2') OR (pub.information_sent '$date1' and pub.information_sent '$date2') OR (gov.information_sent '$date1' and gov.information_sent '$date2') OR (med.information_sent '$date1' and med.information_sent '$date2') OR (ngo.information_sent '$date1' and ngo.information_sent '$date2') OR (own.information_sent '$date1' and own.information_sent '$date2') OR (sup.information_sent '$date1' and sup.information_sent '$date2') OR (tra.information_sent '$date1' and tra.information_sent '$date2') ) order by entity_name then in your loop you will need to look for something like this. while($row = mysql_fetch_array($results)){ if(!empty($row['fof_id'])) echo found; if(!empty($row['fof_id'])) echo found; etc... } You get my point, but the big part is the select * -- part of the sql call you have to identify each column that you want back with an alias otherwise they stomp all over one another. Jim Lucas - Original Message - From: Petre Agenbag [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, July 29, 2003 2:13 PM Subject: [PHP] MySQL query/PHP logic? Hi List OK, I've posted this on the MySQL list as well, but it seems a bit quiet there, and arguably it could definately be a PHP rather than mysql question depending on whether it can be done with one query (then it was/is a mysql query), or whether it should be done with some structures and multiple queries ( then it's arguably PHP). So, here goes. I'm trying to return from multiple tables, the records that have field information_sent between two dates. The tables are all related by means of the id of the entry in the main table, ie.. main id entity_name ... fof id_fof id information_sent ... pub id_pub id information_sent ... etc. So, I tried the following join select * from main left join fof on main.id = fof.id left join pub on main.id = pub.id left join gov on main.id = gov.id left join med on main.id = med.id left join ngo on main.id = ngo.id left join own on main.id = own.id left join sup on main.id = sup.id left join tra on main.id = tra.id where ( (fof.information_sent '$date1' and fof.information_sent '$date2') OR (pub.information_sent '$date1' and pub.information_sent '$date2') OR (gov.information_sent '$date1' and gov.information_sent '$date2') OR (med.information_sent '$date1' and med.information_sent '$date2') OR (ngo.information_sent '$date1' and ngo.information_sent '$date2') OR (own.information_sent '$date1' and own.information_sent '$date2') OR (sup.information_sent '$date1' and sup.information_sent '$date2') OR (tra.information_sent '$date1' and tra.information_sent '$date2') ) order by entity_name BUT, although it seems to be joining the tables correctly AND only returning the ones with the correct date criteria, it does NOT return the id or the information_sent fields correctly ( due to duplication in the result ) Can this be done in one query without sub-selects, or should it be broken up (in which case I would still need help with the logic and to minimize the amount of queries inside loops) Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql and php
great tutorial to do what you want: http://www.freewebmasterhelp.com/tutorials/phpmysql/4 regards, David. On Tue, 11 Mar 2003, Joseph Bannon wrote: How can I have php give me all the data in a table as I would using the prompt in mysql? Joseph __ Do you Yahoo!? Yahoo! Web Hosting - establish your business online http://webhosting.yahoo.com -- David Elías Sánchez Vásquez Bachiller en Educación PUCP [EMAIL PROTECTED] telf. (51)-1-5255601 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL or PHP question?
Should not it be: $SQL = SELECT * FROM table ORDER BY id asc LIMIT .($autoindex -5). ,5;; John Taylor-Johnston wrote: I don't know whether this is a MySQL or PHP quesiton. $SQL = SELECT * FROM table ORDER BY id asc LIMIT $autoindex -5 ,5;; I would like to get the autoindex value of my table and use it in my SQL. Can I get the autoindex? :) How? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL and PHP arrays
On Monday 10 March 2003 22:30, {R}ichard Ashton wrote: Is there a generally recommended way of storing an array created by PHP in a MySQL database field ? serialize() and unserialize(). What type of field should it be, and how do you get the whole array back in one go without reconstructing it row by row, if that is possible? Any text field will do, just make sure it's large enough for your data. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* QOTD: I'm not bald -- I'm hair challenged. [I thought that was differently haired. Ed.] */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] MySQL and PHP arrays
Serializing it would be the best way: seralize($myArray) then you can get the array back using unseralize($serializedarray) -Original Message- From: {R}ichard Ashton [mailto:[EMAIL PROTECTED] Sent: 10 March 2003 14:31 To: [EMAIL PROTECTED] Subject: [PHP] MySQL and PHP arrays Is there a generally recommended way of storing an array created by PHP in a MySQL database field ? What type of field should it be, and how do you get the whole array back in one go without reconstructing it row by row, if that is possible? {R} -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL and PHP arrays
On Mon, 10 Mar 2003 22:34:44 +0800, Jason Wong wrote: On Monday 10 March 2003 22:30, {R}ichard Ashton wrote: Is there a generally recommended way of storing an array created by PHP in a MySQL database field ? serialize() and unserialize(). What type of field should it be, and how do you get the whole array back in one go without reconstructing it row by row, if that is possible? Any text field will do, just make sure it's large enough for your data. Thanks that now makes much more sense. So when I look at the data in the database I see a:142:{i:1;s:52:[52characters];i:2;s:37:[37characters] and so on for the 142 elements of the array. But getting it out is not so easy. $result = mysql_query( select post from posts where id = '$id' ) Gives $result as a Resource id #6 which is OK but I cant find the PHP MySQL command to get the whole field back to unserialize it :( {R} -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* QOTD: I'm not bald -- I'm hair challenged. [I thought that was differently haired. Ed.] */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL and PHP arrays
You get at the data through $array = mysql_result($result,0,0); Mike {R}Ichard Ashton [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Mon, 10 Mar 2003 22:34:44 +0800, Jason Wong wrote: On Monday 10 March 2003 22:30, {R}ichard Ashton wrote: Is there a generally recommended way of storing an array created by PHP in a MySQL database field ? serialize() and unserialize(). What type of field should it be, and how do you get the whole array back in one go without reconstructing it row by row, if that is possible? Any text field will do, just make sure it's large enough for your data. Thanks that now makes much more sense. So when I look at the data in the database I see a:142:{i:1;s:52:[52characters];i:2;s:37:[37characters] and so on for the 142 elements of the array. But getting it out is not so easy. $result = mysql_query( select post from posts where id = '$id' ) Gives $result as a Resource id #6 which is OK but I cant find the PHP MySQL command to get the whole field back to unserialize it :( {R} -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* QOTD: I'm not bald -- I'm hair challenged. [I thought that was differently haired. Ed.] */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] MySQL and PHP arrays
mysql_fetch_array($result) works too. It fetches the data from the current row and is used in conjunction with a while loop: while($array=mysql_fetch_array($result)) { //stuff to do with the current array } Robbert van Andel -Original Message- From: Mike Mannakee [mailto:[EMAIL PROTECTED] Sent: Monday, March 10, 2003 8:45 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] MySQL and PHP arrays You get at the data through $array = mysql_result($result,0,0); Mike {R}Ichard Ashton [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Mon, 10 Mar 2003 22:34:44 +0800, Jason Wong wrote: On Monday 10 March 2003 22:30, {R}ichard Ashton wrote: Is there a generally recommended way of storing an array created by PHP in a MySQL database field ? serialize() and unserialize(). What type of field should it be, and how do you get the whole array back in one go without reconstructing it row by row, if that is possible? Any text field will do, just make sure it's large enough for your data. Thanks that now makes much more sense. So when I look at the data in the database I see a:142:{i:1;s:52:[52characters];i:2;s:37:[37characters] and so on for the 142 elements of the array. But getting it out is not so easy. $result = mysql_query( select post from posts where id = '$id' ) Gives $result as a Resource id #6 which is OK but I cant find the PHP MySQL command to get the whole field back to unserialize it :( {R} -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* QOTD: I'm not bald -- I'm hair challenged. [I thought that was differently haired. Ed.] */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL 4.0 + PHP 4
Anyone out there have anything to share as to using PHP4+MySQL4. I've been hearing good things on the MySQL list about v4.0 and I'm thinking of upgrading, since I run a rather small server. There's really no change from the PHP side. PHP just sends the data and receives something back The only change in PHP is that mysql_connect() now supports additional flags to connect over SSL. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL 4.0 + PHP 4
On Wednesday 22 January 2003 18:52, 1LT John W. Holmes wrote: There's really no change from the PHP side. PHP just sends the data and receives something back The only change in PHP is that mysql_connect() now supports additional flags to connect over SSL. Nope, I only forgot to remove a constant. SSL support will be available in PHP 5 (new mysql extension). Regards Georg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] MySQL 4.0 + PHP 4
On Wednesday 22 January 2003 18:52, 1LT John W. Holmes wrote: There's really no change from the PHP side. PHP just sends the data and receives something back The only change in PHP is that mysql_connect() now supports additional flags to connect over SSL. Nope, I only forgot to remove a constant. SSL support will be available in PHP 5 (new mysql extension). Regards Georg Ah, man... Now you made my article in the last issue of PHP|Architect incorrect! :) Oh well, I guess we'll have to wait. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MYSQL and PHP Storing and retrieving images getting corrupted
Try adding header('Content-length: ' .strlen($data)); header Darren McPhee wrote: I have written 2 programs (which are very common PHP programs) that A) Allows me to upload image files into a MYSQL database using a simple form. And B) Allows me to retrieve and display the image using a PHP script. This is my problem:- I can upload the images ok. I store the binary code, image type, name, and size within the MYSQL database. On checking the database directly using DBTools, I can see that the files have uploaded. The file sizes reflect exactly what was originally on the hard disk of my PC (not sure if this is a correct gauge). When I run my PHP program to display the images, maybe only 1 out of 10 actually displays correctly. The rest are broken up or non displayable images. One image even made a prompt window appear and somehow now causes Windows paint to load the image instead of the browser. God only knows how that occurred !! Below are my (designed by others) 2 programs. The first program is the upload form. This seems to work ok. HTML HEADTITLEStore binary data into SQL Database/TITLE/HEAD BODY ?php // code that will be executed if the form has been submitted: if ($submit) { // connect to the database require_once('../../Connections/TestServer.php'); mysql_select_db($database_TestServer, $TestServer); $data = addslashes(fread(fopen($form_data, r), filesize($form_data))); $result=MYSQL_QUERY(INSERT INTO master_products (image_thumbnail,image_thumbnail_name,image_thumbnail_size,image_thumbnail_t ype) . VALUES ('$data','$form_data_name','$form_data_size','$form_data_type')); $id= mysql_insert_id(); print pThis file has the following Database ID: b$id/b; MYSQL_CLOSE(); } else { // else show the form to submit new data: ? form method=post action=?php echo $PHP_SELF; ? enctype=multipart/form-data INPUT TYPE=hidden name=MAX_FILE_SIZE value=100 brFile to upload/store in database:br input type=file name=form_data size=40 pinput type=submit name=submit value=submit /form ?php } ? /BODY /HTML Here is the code to display the image:- ?php if($id) { require_once('../Connections/TestServer.php'); mysql_select_db($database_TestServer, $TestServer); $query = select image_thumbnail,image_thumbnail_type from master_products where item_id=$id; $result = MYSQL_QUERY($query); $data = MYSQL_RESULT($result,0,image_thumbnail); $type = MYSQL_RESULT($result,0,image_thumbnail_type); Header( Content-type: $type); echo $data; }; ? I run the above program in the following way: http://192.168.0.11/htdocs/displayimage2.php?id=9 The ID is the item_id primary key field for whichever record I want to display. I have tried these programs on a test server here in my room to a test Apache server and MYSQL test database, and also from my ISP to a MYSQL database at a server at my ISP. I get exactly the same problem. When I run the display image program, the images being displayed are always being displayed the same. Which points the problem towards the upload process (maybe). If anybody can tell me what the heck is wrong here, I'll give them a medal !! There is basically some kind of binary corruption going on (it looks like) For added information, below is my database table structure. At the moment, the only part I am actually using relates to the image_thumbnail sections. Darren. CREATE TABLE master_products ( item_id SMALLINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, item_code VARCHAR (10) UNIQUE, item_dateadded DATETIME DEFAULT '-00-00 00:00:00', item_datemodified DATETIME DEFAULT '-00-00 00:00:00', category ENUM (none,single herbs,general vitality,ageing,arthritis,eyesite,prostate,ahlzheimers, weight loss,menopause,depression,fatigue,headaches,insomnia,colds and flues,allergies, healthy heart,cancer prevention,aphrodisiacs,sexual herbs,for women,for men,books), name VARCHAR (30), name_dateadded DATETIME DEFAULT '-00-00 00:00:00', name_datemodified DATETIME DEFAULT '-00-00 00:00:00', INDEX idx_name (name), desc_brief VARCHAR (255), desc_brief_dateadded DATETIME DEFAULT '-00-00 00:00:00', desc_brief_datemodified DATETIME DEFAULT '-00-00 00:00:00', INDEX idx_desc_brief (desc_brief), desc_long TEXT, desc_long_dateadded DATETIME DEFAULT '-00-00 00:00:00', desc_long_datemodified DATETIME DEFAULT '-00-00 00:00:00', price DECIMAL (7,2), price_dateadded DATETIME DEFAULT '-00-00 00:00:00', price_datemodified DATETIME DEFAULT '-00-00 00:00:00', image LONGBLOB, image_name VARCHAR (50), image_size INT UNSIGNED, image_type VARCHAR (50), image_dateadded DATETIME DEFAULT '-00-00 00:00:00', image_datemodified DATETIME DEFAULT '-00-00 00:00:00', image_thumbnail LONGBLOB, image_thumbnail_name VARCHAR (50), image_thumbnail_size INT UNSIGNED, image_thumbnail_type VARCHAR (50), image_thumbnail_dateadded DATETIME DEFAULT '-00-00 00:00:00', image_thumbnail_datemodified
Re: [PHP] MYSQL and PHP Storing and retrieving images getting corrupted
Have you tried out mysql function load_file() to upload directly your file into the database without passing through php variable ? Like this: $result=MYSQL_QUERY(INSERT INTO master_products (image_thumbnail,image_thumbnail_name,image_thumbnail_size,image_thumbnail_t ype) VALUES (load_file('$form_data'),'$form_data_name','$form_data_size','$form_data_typ e')); If you are not allowed to upload directly $form_data using mysql load_file(), move first the file $form_data into another allowed directory with valid filename and try again. Finally, storing image or binary file into database is not good, put them into directory instead. - Original Message - From: Darren McPhee [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, November 05, 2002 11:24 PM Subject: [PHP] MYSQL and PHP Storing and retrieving images getting corrupted I have written 2 programs (which are very common PHP programs) that A) Allows me to upload image files into a MYSQL database using a simple form. And B) Allows me to retrieve and display the image using a PHP script. This is my problem:- I can upload the images ok. I store the binary code, image type, name, and size within the MYSQL database. On checking the database directly using DBTools, I can see that the files have uploaded. The file sizes reflect exactly what was originally on the hard disk of my PC (not sure if this is a correct gauge). When I run my PHP program to display the images, maybe only 1 out of 10 actually displays correctly. The rest are broken up or non displayable images. One image even made a prompt window appear and somehow now causes Windows paint to load the image instead of the browser. God only knows how that occurred !! Below are my (designed by others) 2 programs. The first program is the upload form. This seems to work ok. HTML HEADTITLEStore binary data into SQL Database/TITLE/HEAD BODY ?php // code that will be executed if the form has been submitted: if ($submit) { // connect to the database require_once('../../Connections/TestServer.php'); mysql_select_db($database_TestServer, $TestServer); $data = addslashes(fread(fopen($form_data, r), filesize($form_data))); $result=MYSQL_QUERY(INSERT INTO master_products (image_thumbnail,image_thumbnail_name,image_thumbnail_size,image_thumbnail_t ype) . VALUES ('$data','$form_data_name','$form_data_size','$form_data_type')); $id= mysql_insert_id(); print pThis file has the following Database ID: b$id/b; MYSQL_CLOSE(); } else { // else show the form to submit new data: ? form method=post action=?php echo $PHP_SELF; ? enctype=multipart/form-data INPUT TYPE=hidden name=MAX_FILE_SIZE value=100 brFile to upload/store in database:br input type=file name=form_data size=40 pinput type=submit name=submit value=submit /form ?php } ? /BODY /HTML Here is the code to display the image:- ?php if($id) { require_once('../Connections/TestServer.php'); mysql_select_db($database_TestServer, $TestServer); $query = select image_thumbnail,image_thumbnail_type from master_products where item_id=$id; $result = @MYSQL_QUERY($query); $data = @MYSQL_RESULT($result,0,image_thumbnail); $type = @MYSQL_RESULT($result,0,image_thumbnail_type); Header( Content-type: $type); echo $data; }; ? I run the above program in the following way: http://192.168.0.11/htdocs/displayimage2.php?id=9 The ID is the item_id primary key field for whichever record I want to display. I have tried these programs on a test server here in my room to a test Apache server and MYSQL test database, and also from my ISP to a MYSQL database at a server at my ISP. I get exactly the same problem. When I run the display image program, the images being displayed are always being displayed the same. Which points the problem towards the upload process (maybe). If anybody can tell me what the heck is wrong here, I'll give them a medal !! There is basically some kind of binary corruption going on (it looks like) For added information, below is my database table structure. At the moment, the only part I am actually using relates to the image_thumbnail sections. Darren. CREATE TABLE master_products ( item_id SMALLINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, item_code VARCHAR (10) UNIQUE, item_dateadded DATETIME DEFAULT '-00-00 00:00:00', item_datemodified DATETIME DEFAULT '-00-00 00:00:00', category ENUM (none,single herbs,general vitality,ageing,arthritis,eyesite,prostate,ahlzheimers, weight loss,menopause,depression,fatigue,headaches,insomnia,colds and flues,allergies, healthy heart,cancer prevention,aphrodisiacs,sexual herbs,for women,for men,books), name VARCHAR (30), name_dateadded DATETIME DEFAULT '-00-00 00:00:00', name_datemodified DATETIME DEFAULT '-00-00 00:00:00', INDEX idx_name (name),
Re: [PHP] MySQL and PHP
Brandon, Please do some 'homework': Will the native query run from the MySQL command line, or in a admin tool? Have you tried varying the number of fields? What are the column specifications? In and amongst this you might like to check where you should have spaces (a) for legibility (particularly if you're asking us to read it to help you), and (b) for machine parsing requirements. =dn - Original Message - From: hugh danaher [EMAIL PROTECTED] To: Brandon Orther [EMAIL PROTECTED] Cc: Php-General [EMAIL PROTECTED] Sent: 18 January 2002 01:14 Subject: Re: [PHP] MySQL and PHP Brandon, Try using single quotes rather than doubles in the values e.g. ('something','something else') hugh - Original Message - From: Brandon Orther [EMAIL PROTECTED] To: PHP User Group [EMAIL PROTECTED] Sent: Thursday, January 17, 2002 2:25 PM Subject: [PHP] MySQL and PHP Hello, I am trying to use mysql through php. When I try to run the following query it does nothing. I am trying to figure out if it is the query or php I am having a problem with. Does anyone see a problem with the below query? (Note: This is for mysql) QUERY: INSERT INTO page_properties (page_name,open_menu,top_image,title_image,side_images) VALUES(30daypolicy,comp_info2,top_aboutus,titlebar_aboutus,30da y); Thanx for your help, Brandon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] MySQL and PHP
What is the error that you are getting? --Sam - Original Message - From: Brandon Orther [EMAIL PROTECTED] To: PHP User Group [EMAIL PROTECTED] Sent: Thursday, January 17, 2002 5:25 PM Subject: [PHP] MySQL and PHP Hello, I am trying to use mysql through php. When I try to run the following query it does nothing. I am trying to figure out if it is the query or php I am having a problem with. Does anyone see a problem with the below query? (Note: This is for mysql) QUERY: INSERT INTO page_properties (page_name,open_menu,top_image,title_image,side_images) VALUES(30daypolicy,comp_info2,top_aboutus,titlebar_aboutus,30da y); Thanx for your help, Brandon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] MySQL and PHP
Brandon, Try using single quotes rather than doubles in the values e.g. ('something','something else') hugh - Original Message - From: Brandon Orther [EMAIL PROTECTED] To: PHP User Group [EMAIL PROTECTED] Sent: Thursday, January 17, 2002 2:25 PM Subject: [PHP] MySQL and PHP Hello, I am trying to use mysql through php. When I try to run the following query it does nothing. I am trying to figure out if it is the query or php I am having a problem with. Does anyone see a problem with the below query? (Note: This is for mysql) QUERY: INSERT INTO page_properties (page_name,open_menu,top_image,title_image,side_images) VALUES(30daypolicy,comp_info2,top_aboutus,titlebar_aboutus,30da y); Thanx for your help, Brandon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] mysql and php
On Thursday 05 April 2001 02:15, you wrote: I'm sending this command to mysql UPDATE fusuario u, fgrupos g SET g.cdgrupo=1, u.celular="99823640", u.nome="Augusto X", u.sobrenome="Cesar Castoldi", u.cidade="Florinpolis", u.emailpessoal="[EMAIL PROTECTED]", u.idade="19", u.sexo="M", u.operadora="T", u.email="", u.ddd="048" WHERE g.cdgrupo=1 and u.cdusuario=g.cdusuario and u.cdusuario=1 and u.celular="99823640" and u.ddd="048" and u.ativo=1 and g.ativo=1 and I receive this error message: Mensagens do MySQL : You have an error in your SQL syntax near 'u, fgrupos g SET g.cdgrupo=1, u.celular="99823640", u.nome="Augusto X", u.sobren' at line 1 Why? How can I update with 2 or more tables? use separate queries -- Christian Reiniger LGDC Webmaster (http://sunsite.dk/lgdc/) Error 032: Recursion error - see error 032 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] :: MySql and PHP Book
Hey Ray, I would suggest looking for books on SQL. I have one (and want more!), it is called "the practical sql handbook" and it's nice. Seems every PHP book deals with MySQL directly too. Anyway, my thought on the matter is go generic, go SQL. Philip On Thu, 11 Jan 2001, Ray Iftikhar wrote: I was looking for a good book that teaches you how to use PHP (mainly 3) with MySql. I went to Amazon.com and found "MySql" by Paul Dubois, which was supposed to be THE book for mySql programming. However, after reading some of the customer reviews, it said that it was "light" in the PHP section. Also the fact that the book was published in 1999 made me a little uneasy. What are some books that you have used to learn MySql with php? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]