Re: [PHP-DB] json_encode
First of all, I suggest you use $_POST['verse_of_the_day_subscribe'] instead of $verse_of_the_day_subscribe to point to checkbox element value. To answer your question, if your data is encoded with json_encode() just decode it with json_decode() and use an if-else control structure to check the value and check the checkbox using checked='checked' (XHTML) depending on the condition. To illustrate it with an example: ?php // Assuming the $json_encoded_data variable contains the JSON data $html_form_element_values = json_decode($json_encoded_data); // The rookie way if ( $html_form_element_values-{'verse_of_the_day_subscribe'} == 1 /* or whatever */ ) { echo 'input type=checkbox name=verse_of_the_day_subscribe id=verse_of_the_day_subscribe checked=checked'; } else { echo 'input type=checkbox name=verse_of_the_day_subscribe id=verse_of_the_day_subscribe'; } ? On Sat, Jan 3, 2009 at 11:22 PM, Ron Piggott ron@actsministries.orgwrote: What value does json_encode need to assign to $verse_of_the_day_subscribe in order to cause this checkbox to be checked when the form is updated with the query to the database? input type=checkbox name=verse_of_the_day_subscribe id=verse_of_the_day_subscribe I have already figured out how to do ones such as: input type=text name=first_name id=first_name size=20 maxlength=40 / Thanks, Ron -- Isaak Malik Web Developer
Re: [PHP-DB] PHP Exercises
You're very welcome, after you get some experience it's also a very good thing to read other people's work, but I only recommend this when you already know the basics and have quite a thorough knowledge of the most used functions including: array, string and variable specific functions. There are plenty of PHP opensource projects on the net so you'll certainly have enough choices. You may also want to install a good IDE like openkomodo, phpeclipse, quanta or any other one that supports function argument suggestions (or calltips) And remember that the PHP manual contains priceless information Good luck
Re: [PHP-DB] PHP Exercises
In my opinion the best way to learn it is by getting a book from your local library as reading from the screen can get very exhausting after a while. The manual is only good to increase your knowledge when you already know the basics. -- Isaak Malik Web Developer
Re: [PHP-DB] PHP-MySQL connection for particular module
My mistake then, it's been a while that I used it that way so some things do fade away from my mind. On Thu, Jun 19, 2008 at 1:57 AM, Chris [EMAIL PROTECTED] wrote: Isaak Malik wrote: Because then the connection resource isn't stored in the $link variable and you will be able to use the mysql functions without passing that variable to each function. RTM again. The link parameter is completely optional. If you don't specify it, it uses the last connection created. I can do this and it's perfectly valid: $link = mysql_connect($server, $user, $pass); if (!$link) { die (Unable to connect to the database server); } $db_selected = mysql_select_db($databasename); if (!$db_selected) { die(Unable to connect to the database $databasename); } $result = mysql_query(select 1); -- Postgresql php tutorials http://www.designmagick.com/ -- Isaak Malik Web Developer
Re: [PHP-DB] PHP-MySQL connection for particular module
It's great that you got your problem solved :). On Thu, Jun 19, 2008 at 12:30 PM, bateivan [EMAIL PROTECTED] wrote: Hello Isaak, You've scored the bulleye! It works! Also, I tested by including common.php instead of database.php and it worked too. This solution is perfect for me as I can keep my code compact and tidy. I would, definetely, recommend this site to my fellow developers. Thank you very much, Isaak and all the rest of the guys who took interst in my problem. Best regards. Isaak Malik-3 wrote: To Evert: 4. I am posting some of my code to compare. Module carmade.php works v.s. login.php which does not. Also, I am posting my database.php which is establishing the connection and is included in every page through layout.php-common.php-database.php. To bateivan: I can only guess that the database.php file isn't correctly loaded via layout.php, did you already try to include database.php into the module in which it wasn't working? If so and it works then the issue is probably caused by incorrectly including that file, otherwise it has to be something else... And register_globals allows you to use short variables for super global arrays. Ex: $name instead of $_POST['name'], etc. On Wed, Jun 18, 2008 at 9:47 PM, Evert Lammerts [EMAIL PROTECTED] wrote: Pastebin works lots better when you're posting code: www.pastebin.com I don't see your database.php included in both of these modules. Where do you include it? EVert On Wed, Jun 18, 2008 at 9:38 PM, bateivan [EMAIL PROTECTED] wrote: Hello, To answer these qwestions: 1. I am using include in my code. 2. About the $link = mysql_connect('localhost', 'root', 'testing'); variable. I can just include this line before mysql_query function and it works even without entering into mysql_query the $link variable. (Like the connection is waking up). 3.My php.ini register_globals is off as suggested for new versions of PHP but include file should work instead according to the manual. 4. I am posting some of my code to compare. Module carmade.php works v.s. login.php which does not. Also, I am posting my database.php which is establishing the connection and is included in every page through layout.php-common.php-database.php. carmade.php: ?php include $_SERVER['DOCUMENT_ROOT']. '/layout.php'; // Quick Login session check login_check(); switch($_REQUEST['req']){ // Insert Case case create_carmade: myheader(Добавяне на автомобилни марки в списъка); // Double check form posted values are there // before performing INSERT query if(!$_POST['car_descr']){ echo 'p align=centerЛипсва информациятя от формата!/p'. 'p align=centerМоля, използвайте бутона'. 'Назад и въведете данните отново!/p'; footer(); exit(); } // Insert Query $sql = mysql_query(INSERT INTO carmade (car_descr) VALUES('{$_POST['car_descr']}')); // Insert query results if(!$sql){ echo Грешка при въвеждане на данните:.mysql_error(); } else { echo 'p align=centerМарката '.$_POST['car_descr']. 'е въведенаbr/с номер:'.mysql_insert_id(); echo 'br / /admin/carmade.php?req=new_carmade Искате ли да'. 'въведете друга марка? '; } break; // Create car made form case case new_carmade: myheader(Въвеждане на нова автомобилна марка); include $_SERVER['DOCUMENT_ROOT']. '/html/forms/carmade_insert.html'; footer(); break; default: myheader(Администриране на списъка с автомобилните марки); include $_SERVER['DOCUMENT_ROOT']. '/html/carmade_admin.html'; footer(); break; } ? login.php: ?php include $_SERVER['DOCUMENT_ROOT']. '/layout.php'; switch($_REQUEST['req']){ case validate: $validate = mysql_query(SELECT * FROM members WHERE username = '{$_POST['username']}' AND password = md5('{$_POST['password']}') ); $num_rows = mysql_num_rows($validate); if($num_rows == 1){ while($row = mysql_fetch_assoc($validate)){ $_SESSION['login'] = true; $_SESSION['userid'] = $row['member_id']; $_SESSION['first_name'] = $row['first_name']; $_SESSION['last_name'] = $row['last_name']; $_SESSION['email_address'] = $row['email_address']; if($row['admin_access'] == 1){ $_SESSION['admin_access'] = true; } $login_time = mysql_query(UPDATE members SET last_login=now
Re: [PHP-DB] PHP-MySQL connection for particular module
Because then the connection resource isn't stored in the $link variable and you will be able to use the mysql functions without passing that variable to each function. On Wed, Jun 18, 2008 at 1:51 AM, Chris [EMAIL PROTECTED] wrote: It means that either your mysql conenction details are not correctly set or the connection resource isn't accessible for your mysql functions. I suggest you first try by replacing: $link = mysql_pconnect('localhost', 'root', 'testing'); into: mysql_pconnect('localhost', 'root', 'testing'); Why? How is that going to help fix the problem? Personally I'd say to *not* use persistent connections as it will cause you problems later. Use a normal connection: $link = mysql_connect($server, $user, $pass); -- Postgresql php tutorials http://www.designmagick.com/ -- Isaak Malik Web Developer
[PHP-DB] Re: PHP-MySQL connection for particular module
You're very welcome, I understand that you need a solution which allows you to keep using the connection this way. I doubt that your php.ini is the cause so I'll suggest the following: Try executing your MySQL queries by passing the $link variable to the function as the connection resource: mysql_query(SELECT..., $link); Something that also might cause it is that you use (include|require)_once and that this module doesn't have access to the connection resource, if this is the case change it into include|require and see if that solves your issue. If not then could you please post some example code of your module if possible so we can be more helpful? Also be sure that you global $link; it in functions (I don't know if this required since I didn't use it this way for a long while). Could you also please answer to the list instead of directly to me as this might also be informative for others. On Tue, Jun 17, 2008 at 10:49 PM, [EMAIL PROTECTED] wrote: Thank you Isaak for interest in my subject. I have my connection set in a separate file which is included into the page. All my modules work except this one. When I use the following line $link = mysql_pconnect('localhost', 'root', 'testing'); actually, my module starts working which is a redundant line as long as I have all this set in my include file. The thing is that I would like to keep this code in an included file for clearness and readability and make it work. Any idea why this is happening only to this module. May be, it requires change of some settings in php.ini or I am doing something wrong but the code is actually working when I introduce the line above. Tanx Isaak Malik-3 wrote: If you get an error of this kind: Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php on line 17 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php on line 17 It means that either your mysql conenction details are not correctly set or the connection resource isn't accessible for your mysql functions. I suggest you first try by replacing: $link = mysql_pconnect('localhost', 'root', 'testing'); into: mysql_pconnect('localhost', 'root', 'testing'); On 6/17/08, bateivan [EMAIL PROTECTED] wrote: Hello, First of all, please, have in mind that I am new in this business. I have a problem connecting with data base in one particular module. That's right. The rest of the modules can connect to db, update tables with new info but this one is refusing giving me message like this: Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php on line 17 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php on line 17 It is a authentication module and this is the fragment of the code which is giving me a hard time: *** ?php include $_SERVER['DOCUMENT_ROOT']. '/layout.php'; switch($_REQUEST['req']){ case validate: $validate = mysql_query(SELECT * FROM members WHERE username = '{$_POST['username']}' AND password = md5('{$_POST['password']}') ); etc *** My platform is WinXP on drive F:\ (I have Win'98 on C:\) and as you can see my program files are on D:\. All this may not be important but I listed anyway. It is installed Apache 2.2.6 using windows installer, PHP 5.2.6 (I just replaced 5.2.5 hoping to fix the problem), and MySQL 5.0.45. I am using persisten connection which should be on until you restart the server. I have a file included in every page for connection with MySQL and data base. PHP manual says that mysql_query reuses the existing connection or try to create one if not present (I think, according to the warning is trying to create one). I had been checking after each step using phpinfo() if the connection is there and it's there but for some reason the above fragment does not work. As I mentioned above the rest of my modules are working fine with mysql. I checked the php.ini file. I compared it to php.ini.recomended from the .zip distribusion package and they are almost identical exept couple of things for error reporting. I, also checked FAQ, mail listings and other forums but it does not seem anybody had a similar problem. In one
Re: [PHP-DB] PHP-MySQL connection for particular module
= mysql_query('SET_COLLATION=CP1251_GENERAL_CI'); mysql_select_db('samek_db', $link) or die(mysql_error()); ? common.php: ?php // Include Meta Content Class include $_SERVER['DOCUMENT_ROOT'].'/classes/clsMetaContent.php'; // Include Email Class include $_SERVER['DOCUMENT_ROOT'].'/classes/clsEmail.php'; // Include Database Connection File include $_SERVER['DOCUMENT_ROOT'].'/includes/database.php'; // Include Session File include $_SERVER['DOCUMENT_ROOT'].'/includes/session.php'; ? Thank you for your help You're very welcome, I understand that you need a solution which allows you to keep using the connection this way. I doubt that your php.ini is the cause so I'll suggest the following: Try executing your MySQL queries by passing the $link variable to the function as the connection resource: mysql_query(SELECT..., $link); Something that also might cause it is that you use (include|require)_once and that this module doesn't have access to the connection resource, if this is the case change it into include|require and see if that solves your issue. If not then could you please post some example code of your module if possible so we can be more helpful? Also be sure that you global $link; it in functions (I don't know if this required since I didn't use it this way for a long while). Could you also please answer to the list instead of directly to me as this might also be informative for others. -- View this message in context: http://www.nabble.com/PHP-MySQL-connection-for-particular-module-tp17915108p17990192.html Sent from the Php - Database mailing list archive at Nabble.com. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Isaak Malik Web Developer
Re: [PHP-DB] PHP-MySQL connection for particular module
If you get an error of this kind: Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php on line 17 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php on line 17 It means that either your mysql conenction details are not correctly set or the connection resource isn't accessible for your mysql functions. I suggest you first try by replacing: $link = mysql_pconnect('localhost', 'root', 'testing'); into: mysql_pconnect('localhost', 'root', 'testing'); On 6/17/08, bateivan [EMAIL PROTECTED] wrote: Hello, First of all, please, have in mind that I am new in this business. I have a problem connecting with data base in one particular module. That's right. The rest of the modules can connect to db, update tables with new info but this one is refusing giving me message like this: Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php on line 17 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php on line 17 It is a authentication module and this is the fragment of the code which is giving me a hard time: *** ?php include $_SERVER['DOCUMENT_ROOT']. '/layout.php'; switch($_REQUEST['req']){ case validate: $validate = mysql_query(SELECT * FROM members WHERE username = '{$_POST['username']}' AND password = md5('{$_POST['password']}') ); etc *** My platform is WinXP on drive F:\ (I have Win'98 on C:\) and as you can see my program files are on D:\. All this may not be important but I listed anyway. It is installed Apache 2.2.6 using windows installer, PHP 5.2.6 (I just replaced 5.2.5 hoping to fix the problem), and MySQL 5.0.45. I am using persisten connection which should be on until you restart the server. I have a file included in every page for connection with MySQL and data base. PHP manual says that mysql_query reuses the existing connection or try to create one if not present (I think, according to the warning is trying to create one). I had been checking after each step using phpinfo() if the connection is there and it's there but for some reason the above fragment does not work. As I mentioned above the rest of my modules are working fine with mysql. I checked the php.ini file. I compared it to php.ini.recomended from the .zip distribusion package and they are almost identical exept couple of things for error reporting. I, also checked FAQ, mail listings and other forums but it does not seem anybody had a similar problem. In one of my tests I included a line for connection just before the problem lines, as described below, and it worked but my intention is to keep such lines in a separate files and include them in every page instead. *** ... $link = mysql_pconnect('localhost', 'root', 'testing'); $validate = mysql_query(SELECT * FROM members WHERE username = '{$_POST['username']}' AND password = md5('{$_POST['password']}') ); etc. *** As I metioned, this is an authentication module and, may be, that's why is behaving diferently from the rest or I need to do some setup changes in php.ini which I am not familiar with. If anyone has had simmilar problem I would appreciate his/her input. Please, help me resolve this mistery. -- View this message in context: http://www.nabble.com/PHP-MySQL-connection-for-particular-module-tp17915108p17915108.html Sent from the Php - Database mailing list archive at Nabble.com. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Isaak Malik Web Developer
Re: [PHP-DB] Fwd: PHP 5.2.6 integrating MYSQL 5.0.51b on APACHE 2.0.63 + Windows XP SP2)
Did you copy PHP's libmysql.dll to the Apache bin directory, restart Apache and tried again? Also add this to your httpd.conf file: Loadfile C:/php/php5ts.dll On Thu, May 15, 2008 at 9:48 AM, Jeff88 [EMAIL PROTECTED] wrote: I had done all that but not working either. Perhaps, I should described in details of what I had done so that you guys and gals can figure out for me where I had gone wrong. a. Installed APACHE 2.0.63 using downloaded file apache-2.0.63-win32-x86-no_ssl.msi under c:\webserver\apache group directory. Tested with localhost on the browser and able to see the Apache test page. b. Installed PHP 5.2.6 using downloaded file php-5.2.6-win32 zip package under Windows Binaries section and extracted the files under PHP directory c:\webserver\php c. Configured PHP.ini file by copying php.ini-recommended as php.ini and setting the followings: i. display_errors = On ii. log_errors = On iii. doc_root = c:\WebServer\Apache Group\Apache2\htdocs iv. extension_dir = C:\WebServer\PHP\ext d. Did php -v on command prompt and some PHP and Zend Engine version displayed. e. Configured httpd.conf file with the following settings: i. LoadModule php5_module c:/Webserver/php/php5apache2.dll ii. AddType application/x-httpd-php .php iii. PHPIniDir c:/WebServer/PHP/ iv. DirectoryIndex index.html index.php index.html.var f. Able to see PHP and APACHE info displayed when did a phpinfo(). Upto this stage, PHP and APACHE are talking g. Installed MYSQL 5.0.51b using downloaded file Windows ZIP/Setup.EXE (x86) package under directory c:\Webserver\MYSQL5 and tested with the command mysql -u root -p. h. Tried to configure PHP.ini file to talk to MYSQL where I am stuck! HELP!! i. uncommented extension=php_mysql.dll ii Restarted everything but not working, so I tried to be a hero by copying libmysql.dll from MYSQLdirectory to the PHP directory, restarted everything but not working either. When I did a phpinfo() no mysql info displayed, only the php and apache info can be seen. That's the end of my long story. Hope you guys and gals can figure things for me. Isaak Malik-3 wrote: -- Forwarded message -- From: Isaak Malik [EMAIL PROTECTED] Date: Wed, May 14, 2008 at 4:07 PM Subject: Re: [PHP-DB] PHP 5.2.6 integrating MYSQL 5.0.51b on APACHE 2.0.63 + Windows XP SP2) To: Jeff88 [EMAIL PROTECTED] Make sure that you have httpd.conf correctly configured to load the php.ini configuration. Your httpd.conf should also contain the PHPIniDir setting. If this doesn't solve your problem then copy PHP's libmysql.dll to the bin directory of Your Apache installation. On Wed, May 14, 2008 at 10:32 AM, Jeff88 [EMAIL PROTECTED] wrote: jeff88 wrote: chris smith-9 wrote: Did you restart apache? Stupid question I know but best to check. Any errors in the apache logs? Did you edit the right php.ini file? Look at the phpinfo() page and see which file it's loading from. --- I did restart the Apache and even the pc. I edited the right php.ini file as this is the one and only one file residing in my system. phpinfo() also shows the right path where it should read from. -- View this message in context: http://www.nabble.com/PHP-5.2.6-integrating-MYSQL-5.0.51b-on-APACHE-2.0.63-%2B-Windows-XP-SP2%29-tp17201936p17226151.html Sent from the Php - Database mailing list archive at Nabble.com. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Isaak Malik Web Developer -- Isaak Malik Web Developer -- View this message in context: http://www.nabble.com/PHP-5.2.6-integrating-MYSQL-5.0.51b-on-APACHE-2.0.63-%2B-Windows-XP-SP2%29-tp17201936p17247865.html Sent from the Php - Database mailing list archive at Nabble.com. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Isaak Malik Web Developer
Fwd: [PHP-DB] PHP 5.2.6 integrating MYSQL 5.0.51b on APACHE 2.0.63 + Windows XP SP2)
-- Forwarded message -- From: Isaak Malik [EMAIL PROTECTED] Date: Wed, May 14, 2008 at 4:07 PM Subject: Re: [PHP-DB] PHP 5.2.6 integrating MYSQL 5.0.51b on APACHE 2.0.63 + Windows XP SP2) To: Jeff88 [EMAIL PROTECTED] Make sure that you have httpd.conf correctly configured to load the php.ini configuration. Your httpd.conf should also contain the PHPIniDir setting. If this doesn't solve your problem then copy PHP's libmysql.dll to the bin directory of Your Apache installation. On Wed, May 14, 2008 at 10:32 AM, Jeff88 [EMAIL PROTECTED] wrote: jeff88 wrote: chris smith-9 wrote: Did you restart apache? Stupid question I know but best to check. Any errors in the apache logs? Did you edit the right php.ini file? Look at the phpinfo() page and see which file it's loading from. --- I did restart the Apache and even the pc. I edited the right php.ini file as this is the one and only one file residing in my system. phpinfo() also shows the right path where it should read from. -- View this message in context: http://www.nabble.com/PHP-5.2.6-integrating-MYSQL-5.0.51b-on-APACHE-2.0.63-%2B-Windows-XP-SP2%29-tp17201936p17226151.html Sent from the Php - Database mailing list archive at Nabble.com. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Isaak Malik Web Developer -- Isaak Malik Web Developer
Re: [PHP-DB] ordering date in varchar
I think you can try the SQL: Select STR_TO_DATE([field_name], '%d/%m/%Y') as newDate , [field_name] from [table] order by newDate asc; Thanks, Haitao -Original Message- From: Vaibhav Informatics [mailto:[EMAIL PROTECTED] Sent: 2008年3月13日 16:36 To: php-db@lists.php.net; [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: [PHP-DB] ordering date in varchar We have a problem. We have given the dates as date.month.year eg 27.12.2007 The field is named as varchar. We have to arrange ths list of dates in ascending order. Can anyone help? Varchar arranges the list by scanning from left side. Perhaps scanning from right side will do. How to do it? For the best functionality and performance you should use date fields for your database. -- Isaak Malik Web Developer [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php