[PHP] Re: [PHP-DB] Re: [PHP] Problems w/ goto
On Sat, Dec 18, 2010 at 17:02, David Hutto smokefl...@gmail.com wrote: or maybe it's saturday morning and i'm drunk? This seems to be the most likely, and considering how all messages are permanently and independently archived and propagate throughout the Internet, it might be a good reason not to go nuts in sending unrelated and unintelligible messages of this nature in the future. -- /Daniel P. Brown Network Infrastructure Manager Documentation, Webmaster Teams http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with Include
On Mon, Dec 20, 2010 at 02:49, Simcha Younger sim...@syounger.com wrote: Since it is being included by PHP, and not served by Apache, the extension is not important. Correct, but keep in mind that it will likely be served as plain text if accessed directly, if the web server is not properly configured (which, by default, it isn't). -- /Daniel P. Brown Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting (866-) 725-4321 http://www.parasane.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance Improvement on Calling C++ executable from PHP
On Sun, Dec 19, 2010 at 15:35, Shiplu shiplu@gmail.com wrote: === Recently I my this php-general doesn't accept my mail for some reason. So I send it again from anther email === No, actually, you sent it from the exact same address --- but both came through anyway. I am developing a php application that interfaces with an external executable binary. The program is written in C++. I open the program (say a.out) using proc_open. Write some command at its stdin and fetch data stdout. Then close the program. The timing of only a.out is real 490ms usr 160ms sys 290ms When I invoke it using proc_open in php-cli, the timing becomes real 530ms usr 50ms sys 450ms Look closely, the cpu time and the real elapsed time increases. I run the php version from command line. As an apache handler this will surly take more time. Is this just the processing time of the a.out file, or is this considering the PHP script's execution time including the a.out processing? If so, this increase is, of course, to be completely expected. Also, were the input and output exactly the same size in bytes as the direct test? The program a.out can not be converted in php unless I write an extension. But this will need a lot of effort to write it in PHP. Extensions aren't written in PHP, they're binary packages. Some of my ideas are, 1. Create a standalone multi-threaded server that calls a.out and php calls that server. This is the same basic idea that Facebook's HipHop project uses. 2. Call a.out as a CGI and convert it that way. This would likely be your best bet, as you're stripping away all of the excess interfacing by PHP (or another scripting language), and would instead just be accessing it directly via the web server. That said, it would depend on whether or not your program is (or could be) written to handle everything itself, so that PHP - or any capable language, for that matter - would no longer be necessary. -- /Daniel P. Brown Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting (866-) 725-4321 http://www.parasane.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [PHP-DB] Re: [PHP] Problems w/ goto
On Mon, Dec 20, 2010 at 7:37 AM, Daniel Brown danbr...@php.net wrote: On Sat, Dec 18, 2010 at 17:02, David Hutto smokefl...@gmail.com wrote: or maybe it's saturday morning and i'm drunk? This seems to be the most likely, and considering how all messages are permanently and independently archived and propagate throughout the Internet, it might be a good reason not to go nuts in sending unrelated and unintelligible messages of this nature in the future. Yeah, that hindsights 20/20 ain't it? -- /Daniel P. Brown Network Infrastructure Manager Documentation, Webmaster Teams http://www.php.net/ -- They're installing the breathalyzer on my email account next week. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] [SOLVED] Re: Upgraded system and now $_SERVER['SERVER_NAME'] is not more working
I do not know HOW, but it wors again... Thanks, Greetings and nice Day/Evening Michelle Konzack -- # Debian GNU/Linux Consultant ## Development of Intranet and Embedded Systems with Debian GNU/Linux itsyst...@tdnet France EURL itsyst...@tdnet UG (limited liability) Owner Michelle KonzackOwner Michelle Konzack Apt. 917 (homeoffice) 50, rue de Soultz Kinzigstraße 17 67100 Strasbourg/France 77694 Kehl/Germany Tel: +33-6-61925193 mobil Tel: +49-177-9351947 mobil Tel: +33-9-52705884 fix http://www.itsystems.tamay-dogan.net/ http://www.flexray4linux.org/ http://www.debian.tamay-dogan.net/ http://www.can4linux.org/ Jabber linux4miche...@jabber.ccc.de ICQ#328449886 Linux-User #280138 with the Linux Counter, http://counter.li.org/ signature.pgp Description: Digital signature
[PHP] Re: PHPmailer.. best way to send to many recipients?
followup question, please see below the OP: I just started using PHPmailer for one project that requires SMTP authentication (if I said that right).. and all is well.. but I want to ask now before it might get outta hand later: How many comma-delim'ed addresses can I stuff in $BCC_recipients before I have problems (need to restructure the design)? -- require(php_inc/class.phpmailer.php); $mail = new PHPMailer(); $BCC_recipients = x...@host.com,y...@server.com; // ---just an example $arrBCC_recipients = explode(,, $BCC_recipients); foreach ($arrBCC_recipients as $email2stuffInBCC) { $mail-AddBcc($email2stuffInBCC); } if(!$mail-Send()) { // problem -- For now there will be less than 100 Bcc recipients.. but later, more. I don't know if/when it will ever grow past 1,000. I see from reading on a PHPmailer list that the main concern people expressed from this (above) approach is to not go over limits set by the host/server as to how many emails can go out before being marked as spam. OK, understood. Here I am just asking about the code. I mean does it make any difference in terms of code reliability whether I loop on $mail- Send() -versus- looping on/concatenating the Bcc addresses? Govinda -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problems w/ goto
On Fri, Dec 17, 2010 at 10:05 AM, la...@garfieldtech.com la...@garfieldtech.com wrote: What PHP has implemented is named break statements, as I understand it. Not exactly. You can jump to arbitrary (labeled) lines within the same context (method/function), but you cannot enter loop constructs--only exit them. While the last bit implies they are only named break statements, you can use them outside of loops as a normal goto statement. firingSequence: if (!acquireTarget()) goto done; fireMainCannon(); fireMissiles(); if (enemiesInView()): goto firingSequence; done: The above implements a convoluted do...while loop using goto. Recommended? Certainly not! David
Re: [PHP] Does ReflectionMethod::setAccessible() do anything?
On Thu, Dec 16, 2010 at 6:09 PM, Nathan Nobbe quickshif...@gmail.comwrote: you just have to invoke the function from the context of the ReflectionMethod instance ?php class Foo { protected function bar() { echo foobar\n; } } $m = new ReflectionMethod('Foo', 'bar'); $m-setAccessible(true); $m-invokeArgs(new Foo(), array()); ? Thank you, Nathan. That makes perfect sense and would be a good addition to the documentation page for setAccessible(). Even better, I may even be able to make use of it in my testing framework since I only want the method to be exposed for one call from the test method. David -- David Harkness Senior Software Engineer High Gear Media
Re: [PHP] Common session for all subdomains?
Hi! You should use the function session_set_cookie_params to set the session cookie domain to .oire.org like this comment explains: php.net/manual/en/function.session-set-cookie-params.php#94961 Regards, Jonathan On Mon, Dec 20, 2010 at 7:18 PM, Andre Polykanine an...@oire.org wrote: Hello php-general, I've got a question: I have a site http://oire.org/. Then we started developing some applications at http://apps.oire.org/. How can I manage it in the way so the session valid at http://oire.org/ would be also valid at http://apps.oire.org/? Thanks! -- With best regards from Ukraine, Andre Skype: Francophile Twitter: http://twitter.com/m_elensule Facebook: http://facebook.com/menelion -- 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] Problems w/ goto
On Mon, Dec 20, 2010 at 4:47 PM, David Harkness davi...@highgearmedia.com wrote: On Fri, Dec 17, 2010 at 10:05 AM, la...@garfieldtech.com la...@garfieldtech.com wrote: What PHP has implemented is named break statements, as I understand it. Not exactly. You can jump to arbitrary (labeled) lines within the same context (method/function), but you cannot enter loop constructs--only exit them. While the last bit implies they are only named break statements, you can use them outside of loops as a normal goto statement. firingSequence: if (!acquireTarget()) goto done; fireMainCannon(); fireMissiles(); if (enemiesInView()): goto firingSequence; done: The above implements a convoluted do...while loop using goto. Recommended? Is the problem with using the goto convolutedness(as I've seen other senior programmers in other languages when explaining, or 'showing off'), or is their an actual functional problem with it? Is it just the 'sphagetti code' aspect that it can lead to, meaning confusing another programmer? Not to hijack from the op, or dilute the conversation any further than I did over the weekend. Certainly not! David -- They're installing the breathalyzer on my email account next week. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PDO Prepared Statements and stripslashes
Hi. In an article about SQL Injection by Chris Shiflett he mentions the following in a comment: The process of escaping should preserve data, so it should never be necessary to reverse it. When I'm auditing an application, things like stripslashes() alert me to design problems. Now, I'm always using PHP PDO with prepared statements and as such data with quotes gets slashed automatically by PDO when inserted into the database. When I need to pull out the data something might be slashed and I need to use stripslashes() or some str_replace() to make sure that the slashes are removed. So what's the mistake here and what's the correct way to do it? Kind regards Rico -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PDO Prepared Statements and stripslashes
On Tue, Dec 21, 2010 at 05:31:15AM +0100, Rico Secada wrote: Hi. In an article about SQL Injection by Chris Shiflett he mentions the following in a comment: The process of escaping should preserve data, so it should never be necessary to reverse it. When I'm auditing an application, things like stripslashes() alert me to design problems. Now, I'm always using PHP PDO with prepared statements and as such data with quotes gets slashed automatically by PDO when inserted into the database. Just out of idle curiosity, are you using MySQL? PDO shouldn't be backslashing quotes for PostgreSQL, as the PostgreSQL convention for values containing single quotes is to double the quotes, as: ''. When I need to pull out the data something might be slashed and I need to use stripslashes() or some str_replace() to make sure that the slashes are removed. So what's the mistake here and what's the correct way to do it? I don't see a mistake. If the values come out of the database backslashed, then you need to remove them to work with the data. My only question would be whether you're sure the data is backslashed before PDO ever sees it. In which case, yes, you have a problem. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problems w/ goto
On Mon, Dec 20, 2010 at 7:45 PM, David Hutto smokefl...@gmail.com wrote: Is the problem with using the goto convolutedness(as I've seen other senior programmers in other languages when explaining, or 'showing off'), or is their an actual functional problem with it? It works perfectly well and is a great solution in extremely limited cases. The problem is that it can be used in many cases where other control flow statements are more clear. It was more of a problem before because people came from languages that had goto but not the other high-level control flow statements. Using goto often leads to hard-to-follow code. For example, rearranging the above code yields do { if (!acquireTarget()) { break; fireMainCannon(); fireMissiles(); } while (enemiesInView()); Even this doesn't get away from using break--a special form of goto for loops. One way around that is to introduce a loop variable like $done, but I think break is cleaner here. Sometimes goto, break, and continue are simply the best tools for the job. I wouldn't say never use goto, but I do feel that 99 times out of 100 you're probably better off using something else. One thing to keep in mind is that under the hood the PHP interpreter turns while(), for(), etc. into a bunch of gotos. for ( init ; check ; increment ) block is just a shorter way to write init goto check; loop: block increment check: if (check) goto loop; The same can be done for all the other control flow statements. David
Re: [PHP] PDO Prepared Statements and stripslashes
On Tue, 21 Dec 2010 00:32:19 -0500 Paul M Foster pa...@quillandmouse.com wrote: On Tue, Dec 21, 2010 at 05:31:15AM +0100, Rico Secada wrote: Hi. In an article about SQL Injection by Chris Shiflett he mentions the following in a comment: The process of escaping should preserve data, so it should never be necessary to reverse it. When I'm auditing an application, things like stripslashes() alert me to design problems. Now, I'm always using PHP PDO with prepared statements and as such data with quotes gets slashed automatically by PDO when inserted into the database. Just out of idle curiosity, are you using MySQL? PDO shouldn't be backslashing quotes for PostgreSQL, as the PostgreSQL convention for values containing single quotes is to double the quotes, as: ''. Currently I'm working with MySQL, but I have just tested PDO with PostgreSQL 8.3 and in this case PDO backslashes PostgreSQL as well. When I need to pull out the data something might be slashed and I need to use stripslashes() or some str_replace() to make sure that the slashes are removed. So what's the mistake here and what's the correct way to do it? I don't see a mistake. If the values come out of the database backslashed, then you need to remove them to work with the data. My only question would be whether you're sure the data is backslashed before PDO ever sees it. In which case, yes, you have a problem. No, the data is not slashed before PDO sees them. I didn't see a mistake either, but then what does Chris mean? Stripping slashes from output from the DB alerts him to a design problem, and I'm just wondering if there another way of doing things I just haven't heard of then. Paul -- Paul M. Foster -- 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] PDO Prepared Statements and stripslashes
Hello, The plug-in PDO has nothing to do with the backslashes being inserted into the database. The backslashes are used to escape characters like in D's...it would show D's. That's the safe behavior of it. You can change your programming code to fix that. Ravi. On Tue, Dec 21, 2010 at 12:59 AM, Rico Secada coolz...@it.dk wrote: On Tue, 21 Dec 2010 00:32:19 -0500 Paul M Foster pa...@quillandmouse.com wrote: On Tue, Dec 21, 2010 at 05:31:15AM +0100, Rico Secada wrote: Hi. In an article about SQL Injection by Chris Shiflett he mentions the following in a comment: The process of escaping should preserve data, so it should never be necessary to reverse it. When I'm auditing an application, things like stripslashes() alert me to design problems. Now, I'm always using PHP PDO with prepared statements and as such data with quotes gets slashed automatically by PDO when inserted into the database. Just out of idle curiosity, are you using MySQL? PDO shouldn't be backslashing quotes for PostgreSQL, as the PostgreSQL convention for values containing single quotes is to double the quotes, as: ''. Currently I'm working with MySQL, but I have just tested PDO with PostgreSQL 8.3 and in this case PDO backslashes PostgreSQL as well. When I need to pull out the data something might be slashed and I need to use stripslashes() or some str_replace() to make sure that the slashes are removed. So what's the mistake here and what's the correct way to do it? I don't see a mistake. If the values come out of the database backslashed, then you need to remove them to work with the data. My only question would be whether you're sure the data is backslashed before PDO ever sees it. In which case, yes, you have a problem. No, the data is not slashed before PDO sees them. I didn't see a mistake either, but then what does Chris mean? Stripping slashes from output from the DB alerts him to a design problem, and I'm just wondering if there another way of doing things I just haven't heard of then. Paul -- Paul M. Foster -- 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] Common session for all subdomains?
That's a good question. There should be a setting on php.ini to allow cross session. Ravi. On Mon, Dec 20, 2010 at 7:05 PM, Jonathan Tapicer tapi...@gmail.com wrote: Hi! You should use the function session_set_cookie_params to set the session cookie domain to .oire.org like this comment explains: php.net/manual/en/function.session-set-cookie-params.php#94961 Regards, Jonathan On Mon, Dec 20, 2010 at 7:18 PM, Andre Polykanine an...@oire.org wrote: Hello php-general, I've got a question: I have a site http://oire.org/. Then we started developing some applications at http://apps.oire.org/. How can I manage it in the way so the session valid at http://oire.org/ would be also valid at http://apps.oire.org/? Thanks! -- With best regards from Ukraine, Andre Skype: Francophile Twitter: http://twitter.com/m_elensule Facebook: http://facebook.com/menelion -- 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] Problem with Include
Why mess with something that is already working? If you are trying to make it pretty then you are not solving a problem. You are creating one. Ravi. On Mon, Dec 20, 2010 at 7:40 AM, Daniel P. Brown daniel.br...@parasane.netwrote: On Mon, Dec 20, 2010 at 02:49, Simcha Younger sim...@syounger.com wrote: Since it is being included by PHP, and not served by Apache, the extension is not important. Correct, but keep in mind that it will likely be served as plain text if accessed directly, if the web server is not properly configured (which, by default, it isn't). -- /Daniel P. Brown Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting (866-) 725-4321 http://www.parasane.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] All records not displaying...
I would say enabled error_reporting(E_ALL); error_reporting(-1); Then use die(mysql_error()); with your mysql function to get some debugging data. Also use var_dump($query_name) to find out what is spits out. Debugging is your best friend here. If you don't use die() or error_reporting() then you will see a blank screen. Ravi. On Sun, Dec 19, 2010 at 9:01 PM, Gary gp...@paulgdesigns.com wrote: Tamara Temple tamouse.li...@gmail.com wrote in message news:c6993909-dd90-4f52-bf6b-ab888c281...@gmail.com... On Dec 19, 2010, at 9:46 AM, Gary wrote: I have an issue that the first record in a query is not being displayed. It seems that the first row in alphabetical order is not being brought to the screen. I have run the query in the DB and it displays the correct result, so it has to be in the php. I have a MySQL DB that lists beers. I have a column for 'type' of beer (imported, domestic, craft, light). The queries: $result = MySQL_query(SELECT * FROM beer WHERE type = 'imported' AND stock = 'YES' ORDER by beername ); When I run the query if (mysql_num_rows($result) == !'0') { $row = mysql_fetch_array($result); echo 'h3Imported Beers/h3'; echo 'table width=100% border=0 cellspacing=1 cellpadding=1 id=tableone summary= thBeer/th thMaker/th thType/th thSingles/th th6-Packs/th thCans/th thBottles/th thDraft/th thSize/th thDescription/th'; while ($row = mysql_fetch_array($result)) { echo 'tr td' . $row['beername'].'/td'; echo 'td' . $row['manu'] . '/td'; echo 'td' . $row['type'] . '/td'; echo 'td width=40' . $row['singles'] . '/td'; echo 'td width=20' . $row['six'] . '/td'; echo 'td width=40' . $row['can'] . '/td'; echo 'td width=20' . $row['bottles'] . '/td'; echo 'td width=40' . $row['tap'] . '/td'; echo 'td' . $row['size'] . '/td'; echo 'td' . $row['descrip'] . '/td'; '/tr'; } echo '/tablebr /'; } All but the first row in alphabetical order are displayed properly. Can anyone tell me where I am going wrong? -- Gary BTW, I do have a bonus question that is about javascript in this same file, so if anyone want to take a stab at that, I'll be happy to post it. This code will totally eliminate the first row of data. if (mysql_num_rows($result) == !'0') { $row = mysql_fetch_array($result); Fetches the first row, but is not output. Because: while ($row = mysql_fetch_array($result)) { Fetches the second row before you do any output of the data. Eliminate the first fetch_array and you're code should work fine. BTW, if you put the td attributes 'width=n' in the preceding th tags, you won't have to output them for each row. You should also put the units those numbers are associated with. Tamara Thank you for your help and thank you for the explaination. I removed the line and it works fine. I dont remember where or why I had that line in there, it is code that I have recycled for a while now. Gary __ Information from ESET Smart Security, version of virus signature database 5716 (20101219) __ The message was checked by ESET Smart Security. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with Include
On Tue, Dec 21, 2010 at 2:29 AM, Ravi Gehlot r...@ravigehlot.net wrote: Why mess with something that is already working? If you are trying to make it pretty then you are not solving a problem. You are creating one. Define working. I've had programs 'work', but more experienced would say it's flawed in some respect. Does it perform the immediate task? Now define pretty. Is it aesthetically pleasing to you, or to someone else with less, or maybe more experience. By defining the two above, you then define whether it's a problem. To you, or to them, or to the original designer? Ravi. On Mon, Dec 20, 2010 at 7:40 AM, Daniel P. Brown daniel.br...@parasane.netwrote: On Mon, Dec 20, 2010 at 02:49, Simcha Younger sim...@syounger.com wrote: Since it is being included by PHP, and not served by Apache, the extension is not important. Correct, but keep in mind that it will likely be served as plain text if accessed directly, if the web server is not properly configured (which, by default, it isn't). -- /Daniel P. Brown Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting (866-) 725-4321 http://www.parasane.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- They're installing the breathalyzer on my email account next week. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array question
Jim Lucas has it. You can use the preg_match function to find it. I would use regexp for that reason. regexp is good for making sure things are typed the way they need to (mostly used for). Ravi. On Sat, Dec 18, 2010 at 5:17 PM, Jim Lucas li...@cmsws.com wrote: On 12/17/2010 12:52 PM, Sorin Buturugeanu wrote: Hello all! I have a question regarding arrays and the way I can use a value. Let's say I have this string: $s = 'banana,apple,mellon,grape,nut,orange' I want to explode it, and get the third value. For this I would normally do: $a = explode(',', $s); echo $s[2]; That's all fine, but is there a way to get the value directly, without having to write another line in my script. I mean something like this: echo explode(',', $s)[2]; or echo {explode(',', $s)}[2]; I couldn't find out this answer anywhere, that's why I posted here. Cheers and thanks! Sure it CAN be done. Nobody laugh too loud here... But... ?php $s = 'banana,apple,mellon,grape,nut,orange'; echo preg_replace('/([^,]+,){3}([^,]+).*/', '$2', $s); ? Outputs: grape The {3} part is equivalent to the array position. Change that number, and you change which word will get displayed. Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHPInfo disabled due to security
Hello there, If you have a small to medium size web site then go to GoDaddy. Do not believe all that you see from php_info(). I will give you an example. The memory_limit it gives on shared hosting does not reflect the one intended for your shared account. It shows what was set for overall use. But blocking php_info() isn't right (at least I don't think so). Ravi. On Fri, Dec 17, 2010 at 10:25 AM, Daniel Brown danbr...@php.net wrote: On Thu, Dec 16, 2010 at 23:39, Paul S pau...@roadrunner.com wrote: Well, I was hoping for stronger arguments to get that DONE. I would think there be something in the PHP license that would FORBID disabling functionality. Really? You would really think that? Because we wouldn't. After all, 'phpinfo' is essential, really, to achieving secure applications, isn't it? No. Writing good code is essential. -- /Daniel P. Brown Network Infrastructure Manager Documentation, Webmaster Teams http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Error Querying Database
Trying to connect to the database can involve setting up your database. Make sure that you have a valid login/password that is recognized by MySQL. Please keep in mind that MySQL works on permission by hosts. So your host IP must be matched with the username/password on the database for a successful authentication. One way to know that you can connect successfully to your remote database is to actually test it. Download MySQL Workbench from Mysql.com and then try to connect to remote from the same host that your php application is sitting at. If it works, thumbs up. If it does not then you have a permission issue there. Add your username/host appropriately. If you can connect without a hitch then you are doing something wrong on your code. Use mysql_connect(), mysql_select_db() and then send an statement and use the resource to see if it returns TRUE or FALSE. At this point, on FALSE it means that you have a bad written statement. There is so much that can go wrong. Debug step by step. Ravi. On Thu, Dec 16, 2010 at 9:26 PM, Phred White phpl...@planetphred.comwrote: It seems like there are several questions emerging, but ... Try echoing your query to the page by putting echo $query in your code before you call mysql, then copy it and run it in phpmyadmin. If it runs then you know your problem is somewhere else like the connection. This can really help you find typos that can cause mysterious results. If you want to use the same page to process the form (my preference) then put a hidden field in your form like: input type=hidden name=phpaction id=phpaction value=process / and wrap the form processing code like so: if (isset($_POST['phpaction'])) { //process submitted form data } else { //processing for initial form entry } When the form is initially loaded it will ignore the first part There are a 1000 ways to do this, but this is pretty straightforward. On Dec 15, 2010, at 1:34 PM, Gary wrote: Steve Staples sstap...@mnsi.net wrote in message news:1292440837.5460.8.ca...@webdev01... On Wed, 2010-12-15 at 13:42 -0500, Gary wrote: I cant seem to get this to connect. This is to my local testing server, which is on, so we need not worry that I have posted the UN/PW. This is a duplicate of a script I have used countless times and it worked. The error message is 'Error querying database.' Some one point out the error of my ways? Gary form action=?php echo $_SERVER[PHP_SELF]; ? method=post tr td labelName of Beer/label/tdtdinput name=beername type=text / /td /tr tr td labelMaker of Beer/label/tdtdinput name=manu type=text / /td /tr tr td labelType of Beer/label/td tdselect name=type size=1 id=type optionImported/option optionDomestic/option optionCraft/option optionLight/option /select !--select name=avail size=1 id=avail optionAvailable/option optionSold/option /select-- /td /tr tr tdlabelSold in/label /tdtdinput type=checkbox name=singles value=Yes / Singlesbr / input type=checkbox name=six value=Yes / Six Packs br / input type=checkbox name=can value=Yes / Cansbr / input type=checkbox name=bottles value=Yes / Bottles br / input type=checkbox name=tap value=Yes / Draft br / tr td labelSize/label/tdtdinput name=size type=text / /td/tr trtd labelDescription/label/tdtdtextarea name=desc cols=40 rows=5/textarea /td/tr trtd input name=submit type=submit value=Submit //td/tr /form /table /div div id=list ?php $beername = $_POST['beername']; $manu = $_POST['manu']; $type = $_POST['type']; $singles = $_POST['singles']; $six = $_POST['six']; $can = $_POST['can']; $bottles = $_POST['bottles']; $tap = $_POST['tap']; $size = $_POST['size']; $desc = $_POST['desc']; $ip= $_SERVER['REMOTE_ADDR']; $dbc = mysqli_connect('localhost','root','','rr')or die('Error connecting with MySQL Database'); $query = INSERT INTO beer (beername, manu, type, singles, six, can, bottles, tap, size, desc, ip ). VALUES ('$beername', '$manu', '$type', '$singles', '$six', '$can', '$bottles', '$tap', '$size', '$desc', '$ip' ); $result = mysqli_query($dbc, $query) or die('Error querying database.'); mysqli_close($dbc); -- Gary Read Ash's reply... but basically, you're running the query with POST variables, and inserting them on page display as well as on form submit. can you ensure that you can connect from the command line? if you may take some criticism, you should rethink your database design, as well as the page flow/design... you should either post the form to a new page, or if it is back to itself, you should check to see that you have in fact posted it before just blindly inserting into the database (as currently, every time you view the page, you will insert into the database, even if completely empty values). Steve Thank you for your reply. I did not see a
Re: [PHP] Problem with Include
My point is that you tried to take code from one page and put it all organized in another page and the include that page of includes back into the pages that you want it to feed off from. If stuff works the way that it does then there a reason for it to have been done that way. That's why documenting code is so important. 99% doesn't do it (including me). Ravi. On Tue, Dec 21, 2010 at 2:35 AM, David Hutto smokefl...@gmail.com wrote: On Tue, Dec 21, 2010 at 2:29 AM, Ravi Gehlot r...@ravigehlot.net wrote: Why mess with something that is already working? If you are trying to make it pretty then you are not solving a problem. You are creating one. Define working. I've had programs 'work', but more experienced would say it's flawed in some respect. Does it perform the immediate task? Now define pretty. Is it aesthetically pleasing to you, or to someone else with less, or maybe more experience. By defining the two above, you then define whether it's a problem. To you, or to them, or to the original designer? Ravi. On Mon, Dec 20, 2010 at 7:40 AM, Daniel P. Brown daniel.br...@parasane.netwrote: On Mon, Dec 20, 2010 at 02:49, Simcha Younger sim...@syounger.com wrote: Since it is being included by PHP, and not served by Apache, the extension is not important. Correct, but keep in mind that it will likely be served as plain text if accessed directly, if the web server is not properly configured (which, by default, it isn't). -- /Daniel P. Brown Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting (866-) 725-4321 http://www.parasane.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- They're installing the breathalyzer on my email account next week.