php-general Digest 26 Feb 2009 12:47:57 -0000 Issue 5980
php-general Digest 26 Feb 2009 12:47:57 - Issue 5980 Topics (messages 288795 through 288813): non-auto increment question 288795 by: PJ 288796 by: Gary W. Smith 288797 by: Ashley Sheridan 288801 by: Ashley Sheridan 288802 by: PJ 288803 by: Jerry Schwartz 288804 by: Jerry Schwartz 288807 by: Jim Lucas 288808 by: Jim Lucas 288809 by: Lester Caine Can't set expect.timeout 288798 by: Clement Yui-Wah Lee 288799 by: Ashley Sheridan 288800 by: Clement Yui-Wah Lee Re: Web Development work 288805 by: phphelp -- kbk 288806 by: 9el Re: Spaces Not Detected from Regular Expression preg_match 288810 by: Alice Wei Converting Euro sign 288811 by: Merlin Morgenstern 288812 by: Per Jessen A puzzler (well, for me at least) 288813 by: Richard Heyes Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- I want to insert a new table entry 1 number higher than the highest in the field (id). I cannot use auto-increment. And I want to show the value of the field to be added in an input field on the web page: if (isset($_REQUEST[AddNewBooksRequest])) { $SQL = SELECT MAX(id) FROM book; $result = mysql_query($sql, $db); $bookCount = mysql_num_rows($result); for ($i=0; $i $bookCount; $i++) { $row = mysql_fetch_array($result); $idIN= $row[id]+1; } $idIN= $_POST[idIN]; $titleIN= $_POST[titleIN]; ...snip... td colspan=2 ? echo input type='text' name='titleIN' value='$idIN' disabled size='2'; ? /td What am I doing wrong? (The query works and returns the right nr. but what do I have to do to add 1 to that number and then display it in the on page and post it to the table? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com ---End Message--- ---BeginMessage--- Not sure that this is the problem BUT you should probably qualify the name of the variable such that SELECT MAX(id) AS id FROM book. But you don't want max(id) as id but rather max(id) + 1 as id. With that you can then just return the final value. Also, if you don't want to alias the value (or whatever it's called) you should use $row[0] to get it by ordinal posistion. As for now wanting to use autoincrement, you can run into a race condition where two people are inserting at the same time, thus having the same generated id. Hope that helps. From: PJ [mailto:af.gour...@videotron.ca] Sent: Wed 2/25/2009 2:01 PM To: MySql; php-gene...@lists.php.net Subject: non-auto increment question I want to insert a new table entry 1 number higher than the highest in the field (id). I cannot use auto-increment. And I want to show the value of the field to be added in an input field on the web page: if (isset($_REQUEST[AddNewBooksRequest])) { $SQL = SELECT MAX(id) FROM book; $result = mysql_query($sql, $db); $bookCount = mysql_num_rows($result); for ($i=0; $i $bookCount; $i++) { $row = mysql_fetch_array($result); $idIN= $row[id]+1; } $idIN= $_POST[idIN]; $titleIN= $_POST[titleIN]; ...snip... td colspan=2 ? echo input type='text' name='titleIN' value='$idIN' disabled size='2'; ? /td What am I doing wrong? (The query works and returns the right nr. but what do I have to do to add 1 to that number and then display it in the on page and post it to the table? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.ptahhotep.com/ http://www.chiccantine.com http://www.chiccantine.com/ -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=g...@primeexalia.com ---End Message--- ---BeginMessage--- On Wed, 2009-02-25 at 14:10 -0800, Gary W. Smith wrote: Not sure that this is the problem BUT you should probably qualify the name of the variable such that SELECT MAX(id) AS id FROM book. But you don't want max(id) as id but rather max(id) + 1 as id. With that you can then just return the final value. Also, if you don't want to alias the value (or whatever it's called) you should use $row[0] to get it by ordinal posistion. As for now wanting to use autoincrement, you can run into a race condition where two people are inserting at the same time, thus having the same generated id. Hope that helps. From: PJ [mailto:af.gour...@videotron.ca] Sent: Wed 2/25/2009 2:01 PM To: MySql;
RE: [PHP] Re: Spaces Not Detected from Regular Expression preg_match
To: php-general@lists.php.net Date: Wed, 25 Feb 2009 14:42:36 -0600 From: nos...@mckenzies.net Subject: [PHP] Re: Spaces Not Detected from Regular Expression preg_match Shawn McKenzie wrote: Shawn McKenzie wrote: Alice Wei wrote: Hi, I have a code as in the following: ?php $file = test.txt; $fp = fopen($file, r); while(!feof($fp)) { $data = fgets($fp, 1024); if ((preg_match(/0/,$data)) || (preg_match(/\\s\/,$data)) || (preg_match(/\\s\/,$data))) { //Don't do a thing } } fclose($fp); ? This is the input file: 1 23kd 3dkd2 4 5 6 For the output, I get nothing running it from the command prompt, but I would like to have in the output, could anyone please give me some guides on what I have done wrong in my regular expression? Thanks for your help. Alice _ Search from any Web page with powerful protection. Get the FREE Windows Live Toolbar Today! http://get.live.com/toolbar/overview Ummm... #1 you haven't output anything in your code. Your code says, if is found in $data, then Don't do a thing. So if your wanting to see if there is a match in the line and return the match (which in this example seems pointless because you know that you are matching ), then something like this: if (preg_match(/0/,$data, $matches) || preg_match(/\\s\/,$data, $matches)) { print_r($matches); } BTW, the second and third conditions in your if appeared to be the same, also \s matches whitespace, spaces, tabs, returns, etc... I'll wait for a reply with more information as the more I look at your code it seems your off on a strange track. I don't know the variability of your input data, but if you had a line 0 then the first preg_match would match the 0 and not the . Maybe that's what you want, dunno... Thanks, but I found that using line numbers of each and its remainder by a certain number works etter than using regular expressions here, since there is a lot of variability in the data from line to line. Alice -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Express yourself with gadgets on Windows Live Spaces http://discoverspaces.live.com?source=hmtag1loc=us
[PHP] Converting Euro sign
Hello everybody, I have an xml-file where a euro sign is in. Now the sign shows up as questionmark after importing into a mysql db. On the utf_8_decode site I found that iconv will help here, but first of all I do not even know if the xml file is utf8encoded (I doubt it), and secondly I do not want to install another module just for this. Any ideas on how to build a workaround? Thank you for any hint, Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting Euro sign
Merlin Morgenstern wrote: Hello everybody, I have an xml-file where a euro sign is in. Now the sign shows up as questionmark after importing into a mysql db. Check the character set of your mysql table. On the utf_8_decode site I found that iconv will help here, but first of all I do not even know if the xml file is utf8encoded (I doubt it), It should say in the XML file. -- Per Jessen, Zürich (3.2°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] A puzzler (well, for me at least)
Hi, I've been recently wondering (musing if you will) about timings, and roughly how long, in a very real sense, it takes on a modern computer for a single line of PHP, or Javascript (or interpreted code in general) to execute. Nanoseconds? Quicker? You could say I have too much time on my hands... Cheers. -- Richard Heyes HTML5 Canvas graphing for Firefox, Chrome, Opera and Safari: http://www.rgraph.org (Updated February 14th) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A puzzler (well, for me at least)
On Thu, 2009-02-26 at 12:47 +, Richard Heyes wrote: Hi, I've been recently wondering (musing if you will) about timings, and roughly how long, in a very real sense, it takes on a modern computer for a single line of PHP, or Javascript (or interpreted code in general) to execute. Nanoseconds? Quicker? It depends on the processor and the line of instructions. You could say I have too much time on my hands... You could try washing them ;) Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A puzzler (well, for me at least)
Richard Heyes wrote: Hi, I've been recently wondering (musing if you will) about timings, and roughly how long, in a very real sense, it takes on a modern computer for a single line of PHP, or Javascript (or interpreted code in general) to execute. Nanoseconds? Quicker? Not taking pipelining into account, a 3GHz processor will execute one instruction in 333 picoseconds, so three instructions in a nanosecond. How many instructions to a line of code? 10,000 ? -- Per Jessen, Zürich (4.6°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Web Development work
From: Ernie Kemp It seems to me that there must to other places a freelance Web Developer fines work. How do you find work in PHP Web programming? Work a company, through this site and from God. I wish to know more than handing out a business card. 1. Create a personal/business page on a local server. That page serves as an advertisement and a sample of what you can do. Include a data entry form for prospects to request your services and make sure it's not susceptible to HTML or SQL injection. 2. Check with any local ISP or web server providers. See if they have a referral service or help wanted section for customers that want help updating or creating pages. While you're talking to them, find out what services they offer and what tools are available on their servers. Make sure you know how to use them. 3. Talk to the folks at Kinko's, Staples, etc. to see if they get requests for help with web pages. Possibly they can pass out your cards for you. In my case there were two events that directed me into web development. First, about 15 years ago I helped two friends set up a web site with a specific purpose. It was all Perl, CGI and flat files at the time, but it was useful experience. The effort died after three years because we couldn't figure out how to make it pay for itself. Second, after 20 years of designing embedded communications devices and programming credit card terminals, my employer decreed all of those devices to be legacy. But they had started moving some of those same services over to the web. So I became a web developer. I am now doing OJT for XHTML, CSS, Postgres, PHP, PCI DSS, Apache and RedHat Linux; all at the same time. I have done three releases of a product that was already online, but still have a long way to go. I figure another two years to complete my apprenticeship. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Web Development work
Ooops, I forgot one. 0. Invest some time studying the top 25 errors list from either SANS http://www.sans.org/top25errors/ or CWE http://cwe.mitre.org/top25/. Make sure you don't have _any_ of them in your code. (This list includes and extends the OWASP guidelines http://www.owasp.org/index.php/Main_Page.) Bob McConnell -Original Message- From: Bob McConnell Sent: Thursday, February 26, 2009 8:58 AM To: php-general@lists.php.net Subject: RE: [PHP] Web Development work From: Ernie Kemp It seems to me that there must to other places a freelance Web Developer fines work. How do you find work in PHP Web programming? Work a company, through this site and from God. I wish to know more than handing out a business card. 1. Create a personal/business page on a local server. That page serves as an advertisement and a sample of what you can do. Include a data entry form for prospects to request your services and make sure it's not susceptible to HTML or SQL injection. 2. Check with any local ISP or web server providers. See if they have a referral service or help wanted section for customers that want help updating or creating pages. While you're talking to them, find out what services they offer and what tools are available on their servers. Make sure you know how to use them. 3. Talk to the folks at Kinko's, Staples, etc. to see if they get requests for help with web pages. Possibly they can pass out your cards for you. In my case there were two events that directed me into web development. First, about 15 years ago I helped two friends set up a web site with a specific purpose. It was all Perl, CGI and flat files at the time, but it was useful experience. The effort died after three years because we couldn't figure out how to make it pay for itself. Second, after 20 years of designing embedded communications devices and programming credit card terminals, my employer decreed all of those devices to be legacy. But they had started moving some of those same services over to the web. So I became a web developer. I am now doing OJT for XHTML, CSS, Postgres, PHP, PCI DSS, Apache and RedHat Linux; all at the same time. I have done three releases of a product that was already online, but still have a long way to go. I figure another two years to complete my apprenticeship. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A puzzler (well, for me at least)
Your answer is neither relevant nor funny. :-| -- Robert Cummings rob...@interjinn.com pí¹e v diskusním pøíspìvku news:1235653678.13128.32.ca...@localhost... On Thu, 2009-02-26 at 12:47 +, Richard Heyes wrote: Hi, I've been recently wondering (musing if you will) about timings, and roughly how long, in a very real sense, it takes on a modern computer for a single line of PHP, or Javascript (or interpreted code in general) to execute. Nanoseconds? Quicker? It depends on the processor and the line of instructions. You could say I have too much time on my hands... You could try washing them ;) Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A puzzler (well, for me at least)
Your answer is neither relevant nor funny. :-| Someone didn't get any last night... -- Richard Heyes HTML5 Canvas graphing for Firefox, Chrome, Opera and Safari: http://www.rgraph.org (Updated February 14th) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A puzzler (well, for me at least)
Not taking pipelining into account, a 3GHz processor will execute one instruction in 333 picoseconds, so three instructions in a nanosecond. How many instructions to a line of code? 10,000 ? Ooh, less than that - round about 1000. I have some Javascript that I'm curious about, and since it's usually got most of the CPU to play with, I reckon it will be plenty fast enough. Nice to know that I can be sloppy though if I wanted to. -- Richard Heyes HTML5 Canvas graphing for Firefox, Chrome, Opera and Safari: http://www.rgraph.org (Updated February 14th) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A puzzler (well, for me at least)
Sorry i've missed the first sentence, i thought the answer was only the very last sentence. my fault. -- S pozdravem Ondrej Kulatý - Winternet s.r.o. odd. vývoje aplikací tel. 585 209 132 www.winternet.cz Richard Heyes rich...@php.net píse v diskusním príspevku news:af8726440902260659u3c8f0fa4pe3aa7b526192a...@mail.gmail.com... Your answer is neither relevant nor funny. :-| Someone didn't get any last night... -- Richard Heyes HTML5 Canvas graphing for Firefox, Chrome, Opera and Safari: http://www.rgraph.org (Updated February 14th) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A puzzler (well, for me at least)
On Thu, 2009-02-26 at 15:50 +0100, Ondrej Kulaty wrote: Your answer is neither relevant nor funny. :-| It was very relevant. You cannot easily ascertain the time at which a particular line of script is processed. You especially cannot ascertain the specific time taken to process a line of script code without controlling for processor speed, architecture, compiler, memory, network, etc, etc and the exact line of script being considered. As for funny... some people have no sense of humour and to them I pointedly point my tongue. Cheers, Rob. -- Robert Cummings rob...@interjinn.com pe v diskusnm pspvku news:1235653678.13128.32.ca...@localhost... On Thu, 2009-02-26 at 12:47 +, Richard Heyes wrote: Hi, I've been recently wondering (musing if you will) about timings, and roughly how long, in a very real sense, it takes on a modern computer for a single line of PHP, or Javascript (or interpreted code in general) to execute. Nanoseconds? Quicker? It depends on the processor and the line of instructions. You could say I have too much time on my hands... You could try washing them ;) Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regular Expression Problem
Hi, I have two lines here as follows: 1 -0.123701962557954E+03 0.460967618024691E+02 -0.12354765900E+03 0.46259109000E+02 What I am trying to do here is to only have 1 -0.123701962557954E+03 0.460967618024691E+02 be the output so I can do further processing with it, however, with the code I have in the following, I have both lines in the output. Here is the code: $file = test.txt; $fp = fopen($file, r); $lines = file($file); foreach($lines as $line_num = $line) { if (preg_match(/([^0-9]+\s+)(\-?\d+\.?\d+(\+?E?\d+)?){2}/, $line)) echo $line; } Could anyone please tell me that even when I specify that the line has to start with [^0-9]+\s with one occurrence, why I still get -0.12354765900E+03 0.46259109000E+02? Thanks a lot for your help. Alice _ Express yourself with gadgets on Windows Live Spaces http://discoverspaces.live.com?source=hmtag1loc=us
Re: [PHP] Regular Expression Problem
Alice Wei wrote: Hi, I have two lines here as follows: 1 -0.123701962557954E+03 0.460967618024691E+02 -0.12354765900E+03 0.46259109000E+02 What I am trying to do here is to only have 1 -0.123701962557954E+03 0.460967618024691E+02 be the output so I can do further processing with it, however, with the code I have in the following, I have both lines in the output. Here is the code: $file = "test.txt"; $fp = fopen($file, "r"); $lines = file($file); foreach($lines as $line_num = $line) { if (preg_match("/([^0-9]+\s+)(\-?\d+\.?\d+(\+?E?\d+)?){2}/", $line)) echo $line; } Could anyone please tell me that even when I specify that the line has to start with [^0-9]+\s with one occurrence, why I still get -0.12354765900E+03 0.46259109000E+02? Thanks a lot for your help. Alice _ Express yourself with gadgets on Windows Live Spaces http://discoverspaces.live.com?source=hmtag1loc=us [^0-9] means not a digital ^[0-9] is the right way.. -- Laruence's Signature 惠 新宸 xinchen.hui | SYS | (+8610)82602112-7974 | :laruence
RE: [PHP] Regular Expression Problem
Hi, I have two lines here as follows: 1 -0.123701962557954E+03 0.460967618024691E+02 -0.12354765900E+03 0.46259109000E+02 What I am trying to do here is to only have 1 -0.123701962557954E+03 0.460967618024691E+02 be the output so I can do further processing with it, however, with the code I have in the following, I have both lines in the output. Here is the code: $file = test.txt; $fp = fopen($file, r); $lines = file($file); foreach($lines as $line_num = $line) { if (preg_match(/([^0-9]+\s+)(\-?\d+\.?\d+(\+?E?\d+)?){2}/, $line)) echo $line; } Could anyone please tell me that even when I specify that the line has to start with [^0-9]+\s with one occurrence, why I still get -0.12354765900E+03 0.46259109000E+02? Thanks a lot for your help. Alice _ Express yourself with gadgets on Windows Live Spaces http://discoverspaces.live.com?source=hmtag1loc=us [^0-9] means not a digital ^[0-9] is the right way.. Thanks for your help. I cannot imagine that I have missed that. Alice _ Use Messenger to talk to your IM friends, even those on Yahoo! http://ideas.live.com/programpage.aspx?versionId=7adb59de-a857-45ba-81cc-685ee3e858fe
[PHP] What in Hades?
Something is rotten here. Twist it any way you like and it just does not work. I am trying to figure out the working of SELECT LAST_INSERT_ID() and cannot get beyond the first $sql - But it works fine from command-line! ? include (lib/db1.php);// Connect to database $sql1 = INSERT INTO test (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if ( !$result) { echo(PError performing query: . mysql_error() . /P); exit(); } THIS IS WHERE IT STOPS WITH ERROR.$sql1 just refuses to work. db connection is fine and the INSERT works from xterm on remote puter. Can't figure this out. $sql = SELECT LAST_INSERT_ID() FROM test; $result = mysql_query($sql,$db); if (!$result) { echo(PError performing query: . mysql_error() . /P); exit(); } while ( $row = mysql_fetch_array($result) ) { echo(P . $row[id] . /P); } ? What am I missing here? Or how can I trace the error? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression Problem
On Thu, 2009-02-26 at 10:09 -0500, Alice Wei wrote: Hi, I have two lines here as follows: 1 -0.123701962557954E+03 0.460967618024691E+02 -0.12354765900E+03 0.46259109000E+02 What I am trying to do here is to only have 1 -0.123701962557954E+03 0.460967618024691E+02 be the output so I can do further processing with it, however, with the code I have in the following, I have both lines in the output. Here is the code: $file = test.txt; $fp = fopen($file, r); $lines = file($file); foreach($lines as $line_num = $line) { if (preg_match(/([^0-9]+\s+)(\-?\d+\.?\d+(\+?E?\d+)?){2}/, $line)) echo $line; } Could anyone please tell me that even when I specify that the line has to start with [^0-9]+\s with one occurrence, why I still get -0.12354765900E+03 0.46259109000E+02? Thanks a lot for your help. Alice _ Express yourself with gadgets on Windows Live Spaces http://discoverspaces.live.com?source=hmtag1loc=us what about a regex something like: /^(\d{1,})\s+([\d\.E\+\-])+\s+([\d\.E\+\-])+$/ The brackets () allow you to then extract the specific portions of the string as you wish, so the first match is the whole line, the second is the 1 (or whatever other number), the third is the first floating-point number, etc. I'm assuming that the 1 here is some sort of line number possibly? The bit inside the curly braces ({1,}) just says to match the digit 1 or more times. You can limit it by adding a number after the comma, so {1,3} for 1-3 digits. Hope this helps? Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What in Hades?
On Thu, 2009-02-26 at 11:14 -0500, PJ wrote: Something is rotten here. Twist it any way you like and it just does not work. I am trying to figure out the working of SELECT LAST_INSERT_ID() and cannot get beyond the first $sql - But it works fine from command-line! ? include (lib/db1.php);// Connect to database $sql1 = INSERT INTO test (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if ( !$result) { echo(PError performing query: . mysql_error() . /P); exit(); } THIS IS WHERE IT STOPS WITH ERROR.$sql1 just refuses to work. db connection is fine and the INSERT works from xterm on remote puter. Can't figure this out. $sql = SELECT LAST_INSERT_ID() FROM test; $result = mysql_query($sql,$db); if (!$result) { echo(PError performing query: . mysql_error() . /P); exit(); } while ( $row = mysql_fetch_array($result) ) { echo(P . $row[id] . /P); } ? What am I missing here? Or how can I trace the error? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com PHP has a built-in function for retrieving the last inserted auto id, called mysql_insert_id (http://uk2.php.net/mysql_insert_id) which is a lot easier than using another query to do the same. So in your above line, you would replace $sql = SELECT LAST_INSERT_ID() FROM test; with: $sql = mysql_insert_id($result1); and then remove the $result line, as you don't need to execute a query for it now. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What in Hades?
On Thu, Feb 26, 2009 at 9:14 AM, PJ af.gour...@videotron.ca wrote: Something is rotten here. Twist it any way you like and it just does not work. I am trying to figure out the working of SELECT LAST_INSERT_ID() and cannot get beyond the first $sql - But it works fine from command-line! ? include (lib/db1.php);// Connect to database $sql1 = INSERT INTO test (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if ( !$result) { // notice the $result, should be $result1 echo(PError performing query: . mysql_error() . /P); exit(); } Hope that helps Richard THIS IS WHERE IT STOPS WITH ERROR.$sql1 just refuses to work. db connection is fine and the INSERT works from xterm on remote puter. Can't figure this out. $sql = SELECT LAST_INSERT_ID() FROM test; $result = mysql_query($sql,$db); if (!$result) { echo(PError performing query: . mysql_error() . /P); exit(); } while ( $row = mysql_fetch_array($result) ) { echo(P . $row[id] . /P); } ? What am I missing here? Or how can I trace the error? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Richard Whitney phpmy...@gmail.com http://phpmydev.com 602-288-5340 310-943-6498 You come up with ideas, I come up with solutions.
Re: [PHP] RE: non-auto increment question
Jerry Schwartz wrote: Being rather new to all this, I understood from the MySql manual that the auto_increment is to b e used immediately after an insertion not intermittently. My application is for administrators (the site owner designates) to update the database from and administration directory, accessed by user/password login... so there's really very little possibility of 2 people accessing at the same time. By using MAX + 1 I keep the id number in the $idIn and can reuse it in other INSERTS [JS] Are you looking for something like LAST_INSERT_ID()? If you INSERT a record that has an auto-increment field, you can retrieve the value that got inserted with SELECT LAST_INSERT_ID(). It is connection-specific, so you'll always have your own value. You can then save it to reuse, either as a session variable or (more easily) as a hidden field on your form. Thanks, Jerry, You hit the nail on the head.:) To refine my problem (and reduce my ignorance),here's what is happening on the form page: There is a series of INSERTs. The first inserts all the columns of book table except for the id, which I do not specify as it if auto-insert. In subsequent tables I have to reference the book.id (for transitional tables like book_author(refers authors to book) etc. If I understand it correctly, I must retrieve (SELECT LAST_INSERT_ID()) after the first INSERT and before the following insert; and save the id as a string ($id)...e.g. $sql = SELECT LAST_INSERT_ID() AS $id I need clarification on the AS $id - should this be simply id(does this have to be turned into a value into $id or does $id contain the value? And how do I retrieve it to use the returned value for the next $sql = INSERT ... - in other words, is the id or $id available for the next directive or do I have to do something like $id = id? I'm trying to figure this out with some trials but my insert does not work from a php file - but it works from command-line... that's another post. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RE: non-auto increment question
On Thu, 2009-02-26 at 11:27 -0500, PJ wrote: Jerry Schwartz wrote: Being rather new to all this, I understood from the MySql manual that the auto_increment is to b e used immediately after an insertion not intermittently. My application is for administrators (the site owner designates) to update the database from and administration directory, accessed by user/password login... so there's really very little possibility of 2 people accessing at the same time. By using MAX + 1 I keep the id number in the $idIn and can reuse it in other INSERTS [JS] Are you looking for something like LAST_INSERT_ID()? If you INSERT a record that has an auto-increment field, you can retrieve the value that got inserted with SELECT LAST_INSERT_ID(). It is connection-specific, so you'll always have your own value. You can then save it to reuse, either as a session variable or (more easily) as a hidden field on your form. Thanks, Jerry, You hit the nail on the head.:) To refine my problem (and reduce my ignorance),here's what is happening on the form page: There is a series of INSERTs. The first inserts all the columns of book table except for the id, which I do not specify as it if auto-insert. In subsequent tables I have to reference the book.id (for transitional tables like book_author(refers authors to book) etc. If I understand it correctly, I must retrieve (SELECT LAST_INSERT_ID()) after the first INSERT and before the following insert; and save the id as a string ($id)...e.g. $sql = SELECT LAST_INSERT_ID() AS $id I need clarification on the AS $id - should this be simply id(does this have to be turned into a value into $id or does $id contain the value? And how do I retrieve it to use the returned value for the next $sql = INSERT ... - in other words, is the id or $id available for the next directive or do I have to do something like $id = id? I'm trying to figure this out with some trials but my insert does not work from a php file - but it works from command-line... that's another post. Here's how I mostly do it (albeit simplified): $query = INSERT INTO `sometable`(`title`,`content`) VALUES('$title','$content'); $result = mysql_query($query); $autoId = mysql_insert_id($result); $query = INSERT INTO `another_table`(`link_id`,`value`) VALUES($autoId,'$value'); $result = mysql_query($query); No need to call another query to retrieve the last inserted id, as it is tied to the last query executed within this session. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What in Hades?
--- Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get a Free CD of Ubuntu mailed to your door without any cost. Visit : www.ubuntu.com -- 2009/2/26 PJ af.gour...@videotron.ca Something is rotten here. Twist it any way you like and it just does not work. I am trying to figure out the working of SELECT LAST_INSERT_ID() and cannot get beyond the first $sql - But it works fine from command-line! ? include (lib/db1.php);// Connect to database $sql1 = INSERT INTO test (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if ( !$result) { At the above line $result1 ? echo(PError performing query: . mysql_error() . /P); exit(); } THIS IS WHERE IT STOPS WITH ERROR.$sql1 just refuses to work. db connection is fine and the INSERT works from xterm on remote puter. Can't figure this out. $sql = SELECT LAST_INSERT_ID() FROM test; $result = mysql_query($sql,$db); if (!$result) { echo(PError performing query: . mysql_error() . /P); exit(); } while ( $row = mysql_fetch_array($result) ) { echo(P . $row[id] . /P); } ? What am I missing here? Or how can I trace the error? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What in Hades?
Richard Whitney wrote: On Thu, Feb 26, 2009 at 9:14 AM, PJ af.gour...@videotron.ca mailto:af.gour...@videotron.ca wrote: Something is rotten here. Twist it any way you like and it just does not work. I am trying to figure out the working of SELECT LAST_INSERT_ID() and cannot get beyond the first $sql - But it works fine from command-line! ? include (lib/db1.php);// Connect to database $sql1 = INSERT INTO test (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if ( !$result) { // notice the $result, should be $result1 echo(PError performing query: . mysql_error() . /P); exit(); } Hope that helps Richard It helps, thanks for catching that... and it doesn't help... if the result is correct, then the query should have entered the data into the table...and regardless of the printout, the program should continue and I would get the second query however, nothing is entered in the db I check with phpMyAdmin on the host computer (FreeBSD 7.0) THIS IS WHERE IT STOPS WITH ERROR.$sql1 just refuses to work. db connection is fine and the INSERT works from xterm on remote puter. Can't figure this out. $sql = SELECT LAST_INSERT_ID() FROM test; $result = mysql_query($sql,$db); if (!$result) { echo(PError performing query: . mysql_error() . /P); exit(); } while ( $row = mysql_fetch_array($result) ) { echo(P . $row[id] . /P); } ? What am I missing here? Or how can I trace the error? -- Phil Jourdan --- p...@ptahhotep.com mailto:p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Richard Whitney phpmy...@gmail.com mailto:phpmy...@gmail.com http://phpmydev.com 602-288-5340 310-943-6498 You come up with ideas, I come up with solutions. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What in Hades?
Ashley Sheridan wrote: On Thu, 2009-02-26 at 11:14 -0500, PJ wrote: Something is rotten here. Twist it any way you like and it just does not work. I am trying to figure out the working of SELECT LAST_INSERT_ID() and cannot get beyond the first $sql - But it works fine from command-line! ? include (lib/db1.php);// Connect to database $sql1 = INSERT INTO test (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if ( !$result) { echo(PError performing query: . mysql_error() . /P); exit(); } THIS IS WHERE IT STOPS WITH ERROR.$sql1 just refuses to work. db connection is fine and the INSERT works from xterm on remote puter. Can't figure this out. $sql = SELECT LAST_INSERT_ID() FROM test; $result = mysql_query($sql,$db); if (!$result) { echo(PError performing query: . mysql_error() . /P); exit(); } while ( $row = mysql_fetch_array($result) ) { echo(P . $row[id] . /P); } ? What am I missing here? Or how can I trace the error? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com PHP has a built-in function for retrieving the last inserted auto id, called mysql_insert_id (http://uk2.php.net/mysql_insert_id) which is a lot easier than using another query to do the same. So in your above line, you would replace $sql = SELECT LAST_INSERT_ID() FROM test; with: $sql = mysql_insert_id($result1); and then remove the $result line, as you don't need to execute a query for it now. Thanks for that... but how do I see what is returned - and what do I do with it - is it a string a value or what? And how do I recuperate it for further use? I have been trying with the little proggie above to see just what is returned and how to deal with it for further inserts and selects etc. But I AM NOT GETTING BEYOND THE FIRST QUERY and that is frustrating... -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What in Hades?
9el wrote: --- Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get a Free CD of Ubuntu mailed to your door without any cost. Visit : www.ubuntu.com http://www.ubuntu.com -- 2009/2/26 PJ af.gour...@videotron.ca mailto:af.gour...@videotron.ca Something is rotten here. Twist it any way you like and it just does not work. I am trying to figure out the working of SELECT LAST_INSERT_ID() and cannot get beyond the first $sql - But it works fine from command-line! ? include (lib/db1.php);// Connect to database $sql1 = INSERT INTO test (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if ( !$result) { At the above line $result1 ? A typo after the fact does not alter the fact. The INSERT does not work as it should! I don't understand why it should work on command line and not from a file. echo(PError performing query: . mysql_error() . /P); exit(); } THIS IS WHERE IT STOPS WITH ERROR.$sql1 just refuses to work. db connection is fine and the INSERT works from xterm on remote puter. Can't figure this out. $sql = SELECT LAST_INSERT_ID() FROM test; $result = mysql_query($sql,$db); if (!$result) { echo(PError performing query: . mysql_error() . /P); exit(); } while ( $row = mysql_fetch_array($result) ) { echo(P . $row[id] . /P); } ? What am I missing here? Or how can I trace the error? -- Phil Jourdan --- p...@ptahhotep.com mailto:p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What in Hades?
On Thu, 2009-02-26 at 11:49 -0500, PJ wrote: Ashley Sheridan wrote: On Thu, 2009-02-26 at 11:14 -0500, PJ wrote: Something is rotten here. Twist it any way you like and it just does not work. I am trying to figure out the working of SELECT LAST_INSERT_ID() and cannot get beyond the first $sql - But it works fine from command-line! ? include (lib/db1.php);// Connect to database $sql1 = INSERT INTO test (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if ( !$result) { echo(PError performing query: . mysql_error() . /P); exit(); } THIS IS WHERE IT STOPS WITH ERROR.$sql1 just refuses to work. db connection is fine and the INSERT works from xterm on remote puter. Can't figure this out. $sql = SELECT LAST_INSERT_ID() FROM test; $result = mysql_query($sql,$db); if (!$result) { echo(PError performing query: . mysql_error() . /P); exit(); } while ( $row = mysql_fetch_array($result) ) { echo(P . $row[id] . /P); } ? What am I missing here? Or how can I trace the error? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com PHP has a built-in function for retrieving the last inserted auto id, called mysql_insert_id (http://uk2.php.net/mysql_insert_id) which is a lot easier than using another query to do the same. So in your above line, you would replace $sql = SELECT LAST_INSERT_ID() FROM test; with: $sql = mysql_insert_id($result1); and then remove the $result line, as you don't need to execute a query for it now. Thanks for that... but how do I see what is returned - and what do I do with it - is it a string a value or what? And how do I recuperate it for further use? I have been trying with the little proggie above to see just what is returned and how to deal with it for further inserts and selects etc. But I AM NOT GETTING BEYOND THE FIRST QUERY and that is frustrating... the value returned from mysql_insert_id() is an integer, so you can use it unquoted in your queries like any other number value. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] catch the error
What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] catch the error
On Thu, 2009-02-26 at 12:28 -0500, PJ wrote: What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com I'd say it was the way you are trying to connect to your database. This is how it's done: $db_host = 'localhost'; $db_user = 'root'; $db_password = ''; $db_name = 'database_name'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); You see, first you have to cerate a connection to the database server, then you have to select your database on that connection. In your example, 'biggie' is the name of a server where your database resides, and 'test', well, what can I say? This 4th parameter should be a boolean indicating whether or not a new connection should be made upon successive calls to mysql_connect. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: catch the error
Hi PJ, Could it be that you have //include (lib/db1.php); commented out? Try uncommenting that line and see what happens. The error message will always print because the query is never executing properly if you have the db connections file commented out. On Thu, Feb 26, 2009 at 12:28 PM, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php); // Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: catch the error
It is commented out because I am using mysql_connect I don't think it would be good to use both, since the db1 references another db. But even when I use the db1.php and change the database and table, I get the same error message. But what I did miss is my typo in What is wrond with this file? :-) Hi PJ, Could it be that you have //include (lib/db1.php); commented out? Try uncommenting that line and see what happens. The error message will always print because the query is never executing properly if you have the db connections file commented out. On Thu, Feb 26, 2009 at 12:28 PM, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: catch the error
what's the error message? On Thu, Feb 26, 2009 at 11:46 AM, PJ af.gour...@videotron.ca wrote: It is commented out because I am using mysql_connect I don't think it would be good to use both, since the db1 references another db. But even when I use the db1.php and change the database and table, I get the same error message. -- Jim Lyons Web developer / Database administrator http://www.weblyons.com
[PHP] Re: catch the error
ok, well if that's the case then do this $db = mysql_connect('biggie', 'user', 'password', 'test'); That should fix the problem. On Thu, Feb 26, 2009 at 12:46 PM, PJ af.gour...@videotron.ca wrote: It is commented out because I am using mysql_connect I don't think it would be good to use both, since the db1 references another db. But even when I use the db1.php and change the database and table, I get the same error message. But what I did miss is my typo in What is wrond with this file? :-) Hi PJ, Could it be that you have //include (lib/db1.php); commented out? Try uncommenting that line and see what happens. The error message will always print because the query is never executing properly if you have the db connections file commented out. On Thu, Feb 26, 2009 at 12:28 PM, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php); // Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: catch the error
Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php); // Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); ... TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Cheers, Ricardo Dias Marques lists AT ricmarques DOT net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] catch the error
Ashley Sheridan wrote: On Thu, 2009-02-26 at 12:28 -0500, PJ wrote: What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php); // Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com I'd say it was the way you are trying to connect to your database. This is how it's done: $db_host = 'localhost'; $db_user = 'root'; $db_password = ''; $db_name = 'database_name'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); You see, first you have to cerate a connection to the database server, then you have to select your database on that connection. In your example, 'biggie' is the name of a server where your database resides, and 'test', well, what can I say? This 4th parameter should be a boolean indicating whether or not a new connection should be made upon successive calls to mysql_connect. Ash www.ashleysheridan.co.uk OK, I see my error...understood and fixed... but it still does not work. But I did have an error - the include was wrong - missing ../ Something is till amiss... the include configuration works, this does not? Why? ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'myuser'; $db_pass = 'my_pwd'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: catch the error
Jim Lyons wrote: what's the error message? it's in the script/// Error performing query: of Error performing 1st query: - whatever I input. But I had an error in the include location... that's fixed and it works, but not the rest as corrected: ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? On Thu, Feb 26, 2009 at 11:46 AM, PJ af.gour...@videotron.ca mailto:af.gour...@videotron.ca wrote: It is commented out because I am using mysql_connect I don't think it would be good to use both, since the db1 references another db. But even when I use the db1.php and change the database and table, I get the same error message. -- Jim Lyons Web developer / Database administrator http://www.weblyons.com -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: catch the error
Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: catch the error
Darryle Steplight wrote: ok, well if that's the case then do this $db = mysql_connect('biggie', 'user', 'password', 'test'); Ashley pointed out that the 4th parameter is not right - belongs in mysql_select_db. Here it is corrected: (but it still does not work) ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'my_user'; $db_pass = 'my_pass'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? That should fix the problem. On Thu, Feb 26, 2009 at 12:46 PM, PJ af.gour...@videotron.ca wrote: It is commented out because I am using mysql_connect I don't think it would be good to use both, since the db1 references another db. But even when I use the db1.php and change the database and table, I get the same error message. But what I did miss is my typo in What is wrond with this file? :-) Hi PJ, Could it be that you have //include (lib/db1.php); commented out? Try uncommenting that line and see what happens. The error message will always print because the query is never executing properly if you have the db connections file commented out. On Thu, Feb 26, 2009 at 12:28 PM, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] catch the error
On Thu, 2009-02-26 at 13:16 -0500, PJ wrote: Ashley Sheridan wrote: On Thu, 2009-02-26 at 12:28 -0500, PJ wrote: What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php); // Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com I'd say it was the way you are trying to connect to your database. This is how it's done: $db_host = 'localhost'; $db_user = 'root'; $db_password = ''; $db_name = 'database_name'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); You see, first you have to cerate a connection to the database server, then you have to select your database on that connection. In your example, 'biggie' is the name of a server where your database resides, and 'test', well, what can I say? This 4th parameter should be a boolean indicating whether or not a new connection should be made upon successive calls to mysql_connect. Ash www.ashleysheridan.co.uk OK, I see my error...understood and fixed... but it still does not work. But I did have an error - the include was wrong - missing ../ Something is till amiss... the include configuration works, this does not? Why? ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'myuser'; $db_pass = 'my_pwd'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com OK, I wouldn't recommend this for a live server, but for development it's fine; add in an or die('message') part to both the connect and select lines and see what is displayed. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: catch the error
What does this output? ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); if (!is_resource($db_connect)) { echo 'p$db_connect is not a valid resource: ' . mysql_error() . '/p'; exit(); } if (!mysql_select_db($db_name, $db_connect)) { echo pUnable to select $db_name: . mysql_error() . '/p'; exit(); } $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!is_resource($result1)) { echo pError performing 1st query: . mysql_error() . /p; exit(); } else { echo 'p' . mysql_affected_rows() . 'row(s) affected by last statement/p'; exit(); } ? Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: catch the error
Hi PJ, $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; Everyone here is trying to help you and that's cool, but EVERYONE on this list may not be so nice. The above credentials is definitely the type of information you want to keep private, unless you don't mind people potentially accessing your database tables and doing whatever they like with them. I suggest doing something like $db_host = 'localhost; $db_user = 'foo'; $db_pass= ''bar; $db_name =''xx; if you are going to post it on the list. On Thu, Feb 26, 2009 at 1:22 PM, PJ af.gour...@videotron.ca wrote: Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php); // Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php); // Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] RE: non-auto increment question
-Original Message- From: PJ [mailto:af.gour...@videotron.ca] Sent: Thursday, February 26, 2009 11:27 AM To: Jerry Schwartz Cc: a...@ashleysheridan.co.uk; 'Gary W. Smith'; 'MySql'; php- gene...@lists.php.net Subject: Re: [PHP] RE: non-auto increment question Jerry Schwartz wrote: Being rather new to all this, I understood from the MySql manual that the auto_increment is to b e used immediately after an insertion not intermittently. My application is for administrators (the site owner designates) to update the database from and administration directory, accessed by user/password login... so there's really very little possibility of 2 people accessing at the same time. By using MAX + 1 I keep the id number in the $idIn and can reuse it in other INSERTS [JS] Are you looking for something like LAST_INSERT_ID()? If you INSERT a record that has an auto-increment field, you can retrieve the value that got inserted with SELECT LAST_INSERT_ID(). It is connection-specific, so you'll always have your own value. You can then save it to reuse, either as a session variable or (more easily) as a hidden field on your form. Thanks, Jerry, You hit the nail on the head.:) [JS] I'm glad to hear it. To refine my problem (and reduce my ignorance),here's what is happening on the form page: There is a series of INSERTs. The first inserts all the columns of book table except for the id, which I do not specify as it if auto- insert. In subsequent tables I have to reference the book.id (for transitional tables like book_author(refers authors to book) etc. [JS] Okay. If I understand it correctly, I must retrieve (SELECT LAST_INSERT_ID()) after the first INSERT and before the following insert; and save the id as a string ($id)...e.g. $sql = SELECT LAST_INSERT_ID() AS $id [JS] You are confusing database column names with PHP variable names. You don't need an alias at all, unless you feel like it for reasons of convenience or style. Assume that $title is your book title, and that the first column is an auto-increment field. The first two queries should look like $query_insert = INSERT INTO book VALUES (NULL, '$title', ...); and $query_select_id = SELECT LAST_INSERT_ID(); Of course, you need to actually execute the two queries. The first one doesn't return anything (check for errors, of course). The second one retrieves the ID of the record you just inserted. Now retrieve the value returned by the SELECT statement and put it into a variable. You'll use something like $row_selected = mysql_query($query_select_id) or die($query_select_id failed); $last_id = mysql_fetch_array($row_selected) or die(Unable to fetch last inserted ID); and you have what you want. You can now use $last_id anywhere you want, until your script ends. This is all very simplified, but I think you can get my drift. Regards, Jerry Schwartz The Infoshop by Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 www.the-infoshop.com www.giiexpress.com www.etudes-marche.com I need clarification on the AS $id - should this be simply id(does this have to be turned into a value into $id or does $id contain the value? And how do I retrieve it to use the returned value for the next $sql = INSERT ... - in other words, is the id or $id available for the next directive or do I have to do something like $id = id? I'm trying to figure this out with some trials but my insert does not work from a php file - but it works from command-line... that's another post. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: catch the error
On Thu, 2009-02-26 at 13:34 -0500, Darryle Steplight wrote: Hi PJ, $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; Everyone here is trying to help you and that's cool, but EVERYONE on this list may not be so nice. The above credentials is definitely the type of information you want to keep private, unless you don't mind people potentially accessing your database tables and doing whatever they like with them. I suggest doing something like $db_host = 'localhost; $db_user = 'foo'; $db_pass= ''bar; $db_name =''xx; if you are going to post it on the list. On Thu, Feb 26, 2009 at 1:22 PM, PJ af.gour...@videotron.ca wrote: Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com I agree. I wouldn't trust me at all! ;) Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: catch the error
-Original Message- From: PJ [mailto:af.gour...@videotron.ca] Sent: Thursday, February 26, 2009 12:28 PM To: php-general@lists.php.net; MySql Subject: catch the error What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. [JS] You need $db = mysql_connect('biggie', 'user', 'password', 'test'); -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=jschwa...@the- infoshop.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] RE: non-auto increment question
Here's how I mostly do it (albeit simplified): $query = INSERT INTO `sometable`(`title`,`content`) VALUES('$title','$content'); $result = mysql_query($query); $autoId = mysql_insert_id($result); $query = INSERT INTO `another_table`(`link_id`,`value`) VALUES($autoId,'$value'); $result = mysql_query($query); No need to call another query to retrieve the last inserted id, as it is tied to the last query executed within this session. Ash www.ashleysheridan.co.uk [JS] Ashley is absolutely right, I'd forgotten about the mysql_insert_id shorthand. (I'm a one-man band, and for the last week or two I've been immersed in VB for Access forms.) Not only is she right, but her way is better. Presumably a language's internal code is maintained as the specific database changes. You can make yourself more independent of the specific database by using the PDO abstraction, although I would save that for a rainy weekend. Regards, Jerry Schwartz The Infoshop by Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 www.the-infoshop.com www.giiexpress.com www.etudes-marche.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: catch the error
Additionally regarding the error handling , add this to the op of your script. ini_set(display_errors,true); error_reporting(E_STRICT|E_ALL); and post the output of your error message. On Thu, Feb 26, 2009 at 1:40 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Thu, 2009-02-26 at 13:34 -0500, Darryle Steplight wrote: Hi PJ, $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; Everyone here is trying to help you and that's cool, but EVERYONE on this list may not be so nice. The above credentials is definitely the type of information you want to keep private, unless you don't mind people potentially accessing your database tables and doing whatever they like with them. I suggest doing something like $db_host = 'localhost; $db_user = 'foo'; $db_pass= ''bar; $db_name =''xx; if you are going to post it on the list. On Thu, Feb 26, 2009 at 1:22 PM, PJ af.gour...@videotron.ca wrote: Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php); // Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php); // Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com I agree. I wouldn't trust me at all! ;) Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] RE: non-auto increment question
On Thu, 2009-02-26 at 13:44 -0500, Jerry Schwartz wrote: Here's how I mostly do it (albeit simplified): $query = INSERT INTO `sometable`(`title`,`content`) VALUES('$title','$content'); $result = mysql_query($query); $autoId = mysql_insert_id($result); $query = INSERT INTO `another_table`(`link_id`,`value`) VALUES($autoId,'$value'); $result = mysql_query($query); No need to call another query to retrieve the last inserted id, as it is tied to the last query executed within this session. Ash www.ashleysheridan.co.uk [JS] Ashley is absolutely right, I'd forgotten about the mysql_insert_id shorthand. (I'm a one-man band, and for the last week or two I've been immersed in VB for Access forms.) Not only is she right, but her way is better. Presumably a language's internal code is maintained as the specific database changes. You can make yourself more independent of the specific database by using the PDO abstraction, although I would save that for a rainy weekend. Regards, Jerry Schwartz The Infoshop by Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 www.the-infoshop.com www.giiexpress.com www.etudes-marche.com I just checked, and yep, I'm definitely still a he ;) Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: catch the error
But the question is PJ, have you got it out of errors yet? :) www.twitter.com/nine_L www.lenin9l.wordpress.com --- Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get a Free CD of Ubuntu mailed to your door without any cost. Visit : www.ubuntu.com -- 2009/2/27 Ashley Sheridan a...@ashleysheridan.co.uk On Thu, 2009-02-26 at 13:34 -0500, Darryle Steplight wrote: Hi PJ, $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; Everyone here is trying to help you and that's cool, but EVERYONE on this list may not be so nice. The above credentials is definitely the type of information you want to keep private, unless you don't mind people potentially accessing your database tables and doing whatever they like with them. I suggest doing something like $db_host = 'localhost; $db_user = 'foo'; $db_pass= ''bar; $db_name =''xx; if you are going to post it on the list. On Thu, Feb 26, 2009 at 1:22 PM, PJ af.gour...@videotron.ca wrote: Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test') or die(Error connecting DB.mysql_error()); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db) or die(PError performing 1st query: .mysql_error() . /P); ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com I agree. I wouldn't trust me at all! ;) Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: catch the error
Jerry Schwartz wrote: -Original Message- From: PJ [mailto:af.gour...@videotron.ca] Sent: Thursday, February 26, 2009 12:28 PM To: php-general@lists.php.net; MySql Subject: catch the error What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. [JS] You need $db = mysql_connect('biggie', 'user', 'password', 'test'); -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=jschwa...@the- infoshop.com I think the problem here has been that this is such a basic operation and most of us just are too busy with more complicated stuff...that we didn't catch it... ? //include (../lib/db1.php);// Connect to database $db_host = ''; $db_user = ''; $db_pass = ''; $db_name = ''; $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 3st query: . mysql_error() . /P); } echo $sql1; echo br /; echo $db_select; exit(); ? anyway, I am learning a lot... thanks, guys... you're all great... I have lots more coming... :-D -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: catch the error
Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:34 -0500, Darryle Steplight wrote: Hi PJ, $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; Everyone here is trying to help you and that's cool, but EVERYONE on this list may not be so nice. The above credentials is definitely the type of information you want to keep private, unless you don't mind people potentially accessing your database tables and doing whatever they like with them. I suggest doing something like $db_host = 'localhost; $db_user = 'foo'; $db_pass= ''bar; $db_name =''xx; if you are going to post it on the list. On Thu, Feb 26, 2009 at 1:22 PM, PJ af.gour...@videotron.ca wrote: Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com I agree. I wouldn't trust me at all! ;) Ash www.ashleysheridan.co.uk Yeah very stupid of me...but I found the error: see if you can catch it: ? //include (../lib/db1.php);// Connect to database $db_host = 'xxx'; $db_user = 'xxx; $db_pass = 'xxx'; $db_name = 'xxx'; $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 3st query: . mysql_error() . /P); } echo $sql1; echo br /; echo $db_select; exit(); ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: catch the error
On Thu, 2009-02-26 at 13:56 -0500, PJ wrote: Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:34 -0500, Darryle Steplight wrote: Hi PJ, $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; Everyone here is trying to help you and that's cool, but EVERYONE on this list may not be so nice. The above credentials is definitely the type of information you want to keep private, unless you don't mind people potentially accessing your database tables and doing whatever they like with them. I suggest doing something like $db_host = 'localhost; $db_user = 'foo'; $db_pass= ''bar; $db_name =''xx; if you are going to post it on the list. On Thu, Feb 26, 2009 at 1:22 PM, PJ af.gour...@videotron.ca wrote: Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com I agree. I wouldn't trust me at all! ;) Ash www.ashleysheridan.co.uk Yeah very stupid of me...but I found the error: see if you can catch it: ? //include (../lib/db1.php);// Connect to database $db_host = 'xxx'; $db_user = 'xxx; $db_pass = 'xxx'; $db_name = 'xxx'; $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 3st query: . mysql_error() . /P); } echo $sql1; echo br /; echo $db_select; exit(); ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com $db_user has not had the string terminated. pray tell was that the answer you were looking for?! Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: catch the error
Here's the working code... ? //include (../lib/db1.php);// Connect to database $db_host = ''; $db_user = ''; $db_pass = ''; $db_name = ''; $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 3st query: . mysql_error() . /P); } echo $sql1; echo br /; echo $db_select; exit(); ? This works fine either as is or using the include... :-) 9el wrote: But the question is PJ, have you got it out of errors yet? :) www.twitter.com/nine_L http://www.twitter.com/nine_L www.lenin9l.wordpress.com http://www.lenin9l.wordpress.com --- Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get a Free CD of Ubuntu mailed to your door without any cost. Visit : www.ubuntu.com http://www.ubuntu.com -- 2009/2/27 Ashley Sheridan a...@ashleysheridan.co.uk mailto:a...@ashleysheridan.co.uk On Thu, 2009-02-26 at 13:34 -0500, Darryle Steplight wrote: Hi PJ, $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; Everyone here is trying to help you and that's cool, but EVERYONE on this list may not be so nice. The above credentials is definitely the type of information you want to keep private, unless you don't mind people potentially accessing your database tables and doing whatever they like with them. I suggest doing something like $db_host = 'localhost; $db_user = 'foo'; $db_pass= ''bar; $db_name =''xx; if you are going to post it on the list. On Thu, Feb 26, 2009 at 1:22 PM, PJ af.gour...@videotron.ca mailto:af.gour...@videotron.ca wrote: Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca mailto:af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test') or die(Error connecting DB.mysql_error()); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db) or die(PError performing 1st query: .mysql_error() . /P); ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com mailto:p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com I agree. I wouldn't trust me at all! ;) Ash www.ashleysheridan.co.uk http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RE: non-auto increment question
Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:44 -0500, Jerry Schwartz wrote: Here's how I mostly do it (albeit simplified): $query = INSERT INTO `sometable`(`title`,`content`) VALUES('$title','$content'); $result = mysql_query($query); $autoId = mysql_insert_id($result); $query = INSERT INTO `another_table`(`link_id`,`value`) VALUES($autoId,'$value'); $result = mysql_query($query); No need to call another query to retrieve the last inserted id, as it is tied to the last query executed within this session. Ash www.ashleysheridan.co.uk [JS] Ashley is absolutely right, I'd forgotten about the mysql_insert_id shorthand. (I'm a one-man band, and for the last week or two I've been immersed in VB for Access forms.) Not only is she right, but her way is better. Presumably a language's internal code is maintained as the specific database changes. You can make yourself more independent of the specific database by using the PDO abstraction, although I would save that for a rainy weekend. Regards, Jerry Schwartz The Infoshop by Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 www.the-infoshop.com www.giiexpress.com www.etudes-marche.com I just checked, and yep, I'm definitely still a he ;) I never thought otherwise... but then I was wondering... there are too many actresses with the same name... ;-) -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: catch the error
Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:56 -0500, PJ wrote: Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:34 -0500, Darryle Steplight wrote: Hi PJ, $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; Everyone here is trying to help you and that's cool, but EVERYONE on this list may not be so nice. The above credentials is definitely the type of information you want to keep private, unless you don't mind people potentially accessing your database tables and doing whatever they like with them. I suggest doing something like $db_host = 'localhost; $db_user = 'foo'; $db_pass= ''bar; $db_name =''xx; if you are going to post it on the list. On Thu, Feb 26, 2009 at 1:22 PM, PJ af.gour...@videotron.ca wrote: Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com I agree. I wouldn't trust me at all! ;) Ash www.ashleysheridan.co.uk Yeah very stupid of me...but I found the error: see if you can catch it: ? //include (../lib/db1.php);// Connect to database $db_host = 'xxx'; $db_user = 'xxx; $db_pass = 'xxx'; $db_name = 'xxx'; $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 3st query: . mysql_error() . /P); } echo $sql1; echo br /; echo $db_select; exit(); ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com $db_user has not had the string terminated. pray tell was that the answer you were looking for?! Ash www.ashleysheridan.co.uk No. Damn those typos! What seems to have made it work is just $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); not using mysql_select in a string but would you use it in a string? how why? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] RE: non-auto increment question
Sorry, I should know better. -Original Message- From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: Thursday, February 26, 2009 1:51 PM To: Jerry Schwartz Cc: 'PJ'; 'Gary W. Smith'; 'MySql'; php-general@lists.php.net Subject: RE: [PHP] RE: non-auto increment question On Thu, 2009-02-26 at 13:44 -0500, Jerry Schwartz wrote: Here's how I mostly do it (albeit simplified): $query = INSERT INTO `sometable`(`title`,`content`) VALUES('$title','$content'); $result = mysql_query($query); $autoId = mysql_insert_id($result); $query = INSERT INTO `another_table`(`link_id`,`value`) VALUES($autoId,'$value'); $result = mysql_query($query); No need to call another query to retrieve the last inserted id, as it is tied to the last query executed within this session. Ash www.ashleysheridan.co.uk [JS] Ashley is absolutely right, I'd forgotten about the mysql_insert_id shorthand. (I'm a one-man band, and for the last week or two I've been immersed in VB for Access forms.) Not only is she right, but her way is better. Presumably a language's internal code is maintained as the specific database changes. You can make yourself more independent of the specific database by using the PDO abstraction, although I would save that for a rainy weekend. Regards, Jerry Schwartz The Infoshop by Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 www.the-infoshop.com www.giiexpress.com www.etudes-marche.com I just checked, and yep, I'm definitely still a he ;) Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] use strict or similar in PHP?
Hello, I am beginner with PHP and prior to PHP I have worked with java for some time and with perl for very short period. I can't help to notice some things that are little annoyance for me with PHP, but I am sure someone more experienced can help me :-) Is there in PHP something like use strict from perl? I find it pretty annoying to need to run script over and over again just to find out that I made typo in variable name. Is there some way for PHP to cache some data on the page? I like very much PHP's speed but it would be even better to be able to cache some frequently used data from database? Also regarding databases, I liked a lot java's way of sending data to database using parameters (select * from user where username = ? and then passing parameter separately with database doing necessary escaping and everything). Is there something like PHPDBC similar to JDBC? TIA, Hans -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Get a list of column field names from a MS Access table
Newbie question: I would like to get a list of column field names from a MS Access table and hopefully get them returned in the ORIGINAL order (as they appear in access) Is there a sql query I could do to get this result? -- Thanks - RevDave Cool @ hosting4days . com [db-lists 09] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] use strict or similar in PHP?
Yes you can use: error_reporting(E_ALL); Which will enable notices. You can even do: error_reporting(E_ALL | E_STRICT); To enable strict messages. Lewis. 2009/2/26 Hans Schultz h.schult...@yahoo.com: Hello, I am beginner with PHP and prior to PHP I have worked with java for some time and with perl for very short period. I can't help to notice some things that are little annoyance for me with PHP, but I am sure someone more experienced can help me :-) Is there in PHP something like use strict from perl? I find it pretty annoying to need to run script over and over again just to find out that I made typo in variable name. Is there some way for PHP to cache some data on the page? I like very much PHP's speed but it would be even better to be able to cache some frequently used data from database? Also regarding databases, I liked a lot java's way of sending data to database using parameters (select * from user where username = ? and then passing parameter separately with database doing necessary escaping and everything). Is there something like PHPDBC similar to JDBC? TIA, Hans -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- 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] Web Development work
Thanks for everyone's input! I will take your words to heart. /Ernie -Original Message- From: Bob McConnell [mailto:r...@cbord.com] Sent: February-26-09 9:15 AM To: php-general@lists.php.net Subject: RE: [PHP] Web Development work Ooops, I forgot one. 0. Invest some time studying the top 25 errors list from either SANS http://www.sans.org/top25errors/ or CWE http://cwe.mitre.org/top25/. Make sure you don't have _any_ of them in your code. (This list includes and extends the OWASP guidelines http://www.owasp.org/index.php/Main_Page.) Bob McConnell -Original Message- From: Bob McConnell Sent: Thursday, February 26, 2009 8:58 AM To: php-general@lists.php.net Subject: RE: [PHP] Web Development work From: Ernie Kemp It seems to me that there must to other places a freelance Web Developer fines work. How do you find work in PHP Web programming? Work a company, through this site and from God. I wish to know more than handing out a business card. 1. Create a personal/business page on a local server. That page serves as an advertisement and a sample of what you can do. Include a data entry form for prospects to request your services and make sure it's not susceptible to HTML or SQL injection. 2. Check with any local ISP or web server providers. See if they have a referral service or help wanted section for customers that want help updating or creating pages. While you're talking to them, find out what services they offer and what tools are available on their servers. Make sure you know how to use them. 3. Talk to the folks at Kinko's, Staples, etc. to see if they get requests for help with web pages. Possibly they can pass out your cards for you. In my case there were two events that directed me into web development. First, about 15 years ago I helped two friends set up a web site with a specific purpose. It was all Perl, CGI and flat files at the time, but it was useful experience. The effort died after three years because we couldn't figure out how to make it pay for itself. Second, after 20 years of designing embedded communications devices and programming credit card terminals, my employer decreed all of those devices to be legacy. But they had started moving some of those same services over to the web. So I became a web developer. I am now doing OJT for XHTML, CSS, Postgres, PHP, PCI DSS, Apache and RedHat Linux; all at the same time. I have done three releases of a product that was already online, but still have a long way to go. I figure another two years to complete my apprenticeship. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php No virus found in this incoming message. Checked by AVG - www.avg.com Version: 8.0.237 / Virus Database: 270.11.3/1971 - Release Date: 02/26/09 07:03:00 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] use strict or similar in PHP?
--- Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get a Free CD of Ubuntu mailed to your door without any cost. Visit : www.ubuntu.com -- 2009/2/27 Hans Schultz h.schult...@yahoo.com Hello, I am beginner with PHP and prior to PHP I have worked with java for some time and with perl for very short period. I can't help to notice some things that are little annoyance for me with PHP, but I am sure someone more experienced can help me :-) Is there in PHP something like use strict from perl? I find it pretty annoying to need to run script over and over again just to find out that I made typo in variable name. see error_reporting(E_ALL|E_STRICT);:) Is there some way for PHP to cache some data on the page? I like very much PHP's speed but it would be even better to be able to cache some frequently used data from database? Also regarding databases, I liked a lot java's way of sending data to database using parameters (select * from user where username = ? and then passing parameter separately with database doing necessary escaping and everything). Is there something like PHPDBC similar to JDBC? You can use sprintf(select * from `user` where `username`=%s,$user); Also you can look into the great frameworks of PHP like ZendFramework, CodeIgniter, CakePHP etc. TIA, Hans -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] use strict or similar in PHP?
Hans Schultz wrote: Hello, I am beginner with PHP and prior to PHP I have worked with java for some time and with perl for very short period. I can't help to notice some things that are little annoyance for me with PHP, but I am sure someone more experienced can help me :-) Is there in PHP something like use strict from perl? I find it pretty annoying to need to run script over and over again just to find out that I made typo in variable name. Is there some way for PHP to cache some data on the page? I like very much PHP's speed but it would be even better to be able to cache some frequently used data from database? Also regarding databases, I liked a lot java's way of sending data to database using parameters (select * from user where username = ? and then passing parameter separately with database doing necessary escaping and everything). Is there something like PHPDBC similar to JDBC? TIA, Hans 1. Error reporting set to show notices, warnings and errors. See http://www.php.net/manual/en/function.error-reporting.php 2. For caching you can use memcache. See http://www.php.net/memcache 3. These are called prepared statements. See http://www.google.ro/search?q=prepared+statements+php Regards, Ovdiiu -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] use strict or similar in PHP?
I was thinking more of something to fail at compile time if possible :-)regarding second, that solution with sprintf is vulnerable to SQL injection, that is why I wanted something with parameters, instead of escaping everything myself Thanks for your help anyway --- On Thu, 2/26/09, 9el le...@phpxperts.net wrote: Is there in PHP something like use strict from perl? I find it pretty annoying to need to run script over and over again just to find out that I made typo in variable name. see error_reporting(E_ALL|E_STRICT); :) Is there some way for PHP to cache some data on the page? I like very much PHP's speed but it would be even better to be able to cache some frequently used data from database? Also regarding databases, I liked a lot java's way of sending data to database using parameters (select * from user where username = ? and then passing parameter separately with database doing necessary escaping and everything).. Is there something like PHPDBC similar to JDBC? You can use sprintf(select * from `user` where `username`=%s,$user); Also you can look into the great frameworks of PHP like ZendFramework, CodeIgniter, CakePHP etc. TIA, Hans -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] use strict or similar in PHP?
--- Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get a Free CD of Ubuntu mailed to your door without any cost. Visit : www.ubuntu.com -- On Fri, Feb 27, 2009 at 3:20 AM, Hans Schultz h.schult...@yahoo.com wrote: I was thinking more of something to fail at compile time if possible :-) regarding second, that solution with sprintf is vulnerable to SQL injection, that is why I wanted something with parameters, instead of escaping everything myself Well, you can use mysql_real_escape.. to avoid SQL injection possibilities. And ofcourse give a try with the mysqli functions, prepared statements and PDO. And with the frameworks you have less chance to do mistake. Thanks for your help anyway --- On *Thu, 2/26/09, 9el le...@phpxperts.net* wrote: Is there in PHP something like use strict from perl? I find it pretty annoying to need to run script over and over again just to find out that I made typo in variable name. see error_reporting(E_ALL|E_STRICT);:) Is there some way for PHP to cache some data on the page? I like very much PHP's speed but it would be even better to be able to cache some frequently used data from database? Also regarding databases, I liked a lot java's way of sending data to database using parameters (select * from user where username = ? and then passing parameter separately with database doing necessary escaping and everything).. Is there something like PHPDBC similar to JDBC? You can use sprintf(select * from `user` where `username`=%s,$user); Also you can look into the great frameworks of PHP like ZendFramework, CodeIgniter, CakePHP etc. TIA, Hans -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] use strict or similar in PHP?
Oh, I didn't mentioned that I tried that, I was thinking something like failing at compile time (like perl with use strict in programs)Thanks for reply, Hans --- On Thu, 2/26/09, Lewis Wright lewiswri...@gmail.com wrote: From: Lewis Wright lewiswri...@gmail.com Subject: Re: [PHP] use strict or similar in PHP? To: Hans Schultz h.schult...@yahoo.com Cc: php-general@lists.php.net Date: Thursday, February 26, 2009, 9:07 PM Yes you can use: error_reporting(E_ALL); Which will enable notices. You can even do: error_reporting(E_ALL | E_STRICT); To enable strict messages. Lewis. 2009/2/26 Hans Schultz h.schult...@yahoo.com: Hello, I am beginner with PHP and prior to PHP I have worked with java for some time and with perl for very short period. I can't help to notice some things that are little annoyance for me with PHP, but I am sure someone more experienced can help me :-) Is there in PHP something like use strict from perl? I find it pretty annoying to need to run script over and over again just to find out that I made typo in variable name. Is there some way for PHP to cache some data on the page? I like very much PHP's speed but it would be even better to be able to cache some frequently used data from database? Also regarding databases, I liked a lot java's way of sending data to database using parameters (select * from user where username = ? and then passing parameter separately with database doing necessary escaping and everything). Is there something like PHPDBC similar to JDBC? TIA, Hans -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] use strict or similar in PHP?
I have no ideea why my response from half an hour ago was not sent, but here it is again: 1. Error reporting set to show notices, warnings and errors. See http://www.php.net/manual/en/function.error-reporting.php 2. For caching you can use memcache. See http://www.php.net/memcache 3. These are called prepared statements. See http://www.google.ro/search?q=prepared+statements+php Regards, Ovidiu On Thu, Feb 26, 2009 at 10:45 PM, Hans Schultz h.schult...@yahoo.comwrote: Hello, I am beginner with PHP and prior to PHP I have worked with java for some time and with perl for very short period. I can't help to notice some things that are little annoyance for me with PHP, but I am sure someone more experienced can help me :-) Is there in PHP something like use strict from perl? I find it pretty annoying to need to run script over and over again just to find out that I made typo in variable name. Is there some way for PHP to cache some data on the page? I like very much PHP's speed but it would be even better to be able to cache some frequently used data from database? Also regarding databases, I liked a lot java's way of sending data to database using parameters (select * from user where username = ? and then passing parameter separately with database doing necessary escaping and everything). Is there something like PHPDBC similar to JDBC? TIA, Hans -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] use strict or similar in PHP?
On Thu, Feb 26, 2009 at 10:45 PM, Hans Schultz h.schult...@yahoo.comwrote: Hello, I am beginner with PHP and prior to PHP I have worked with java for some time and with perl for very short period. I can't help to notice some things that are little annoyance for me with PHP, but I am sure someone more experienced can help me :-) Is there in PHP something like use strict from perl? I find it pretty annoying to need to run script over and over again just to find out that I made typo in variable name. Is there some way for PHP to cache some data on the page? I like very much PHP's speed but it would be even better to be able to cache some frequently used data from database? Also regarding databases, I liked a lot java's way of sending data to database using parameters (select * from user where username = ? and then passing parameter separately with database doing necessary escaping and everything). Is there something like PHPDBC similar to JDBC? TIA, Hans -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I have no ideea why my response from half an hour ago was not sent, but here it is again: 1. Error reporting set to show notices, warnings and errors. See http://www.php.net/manual/en/function.error-reporting.php 2. For caching you can use memcache. See http://www.php.net/memcache 3. These are called prepared statements. See http://www.google.ro/search?q=prepared+statements+php Regards, Ovidiu
Re: [PHP] use strict or similar in PHP?
Hans Schultz wrote: Oh, I didn't mentioned that I tried that, I was thinking something like failing at compile time (like perl with use strict in programs)Thanks for reply, Hans --- On Thu, 2/26/09, Lewis Wright lewiswri...@gmail.com wrote: From: Lewis Wright lewiswri...@gmail.com Subject: Re: [PHP] use strict or similar in PHP? To: Hans Schultz h.schult...@yahoo.com Cc: php-general@lists.php.net Date: Thursday, February 26, 2009, 9:07 PM Yes you can use: error_reporting(E_ALL); Which will enable notices. You can even do: error_reporting(E_ALL | E_STRICT); To enable strict messages. Lewis. 2009/2/26 Hans Schultz h.schult...@yahoo.com: Hello, I am beginner with PHP and prior to PHP I have worked with java for some time and with perl for very short period. I can't help to notice some things that are little annoyance for me with PHP, but I am sure someone more experienced can help me :-) Is there in PHP something like use strict from perl? I find it pretty annoying to need to run script over and over again just to find out that I made typo in variable name. Is there some way for PHP to cache some data on the page? I like very much PHP's speed but it would be even better to be able to cache some frequently used data from database? Also regarding databases, I liked a lot java's way of sending data to database using parameters (select * from user where username = ? and then passing parameter separately with database doing necessary escaping and everything). Is there something like PHPDBC similar to JDBC? TIA, Hans -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php There is no compile time. PHP is interpreted so it is compiled and then executed. If you always want error reporting, then set it in php.ini. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] use strict or similar in PHP?
Thanks a lot for your info, I will check that IDE too. But those warning levels give me warning only when they encounter offending code? Are you telling me that it can be setup to fail entire script prior to any execution if there are errors in it? Can you please point me how to setup my PHP installation that way? --- On Thu, 2/26/09, 9el le...@phpxperts.net wrote: From: 9el le...@phpxperts.net Subject: Re: [PHP] use strict or similar in PHP? To: h.schult...@yahoo.com Date: Thursday, February 26, 2009, 9:34 PM --- Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get a Free CD of Ubuntu mailed to your door without any cost. Visit : www.ubuntu.com -- On Fri, Feb 27, 2009 at 3:13 AM, Hans Schultz h.schult...@yahoo.com wrote: Oh, I didn't mentioned that I tried that, I was thinking something like failing at compile time (like perl with use strict in programs)Thanks for reply, Thats why E_ALL E_STRICT are there. Read the Zend Guide for Zend Certified Programmer to know the gists at a glance. I'm becoming a ZCE soon :) www.twitter.com/nine_L www.lenin9l.wordpress.com
Re: [PHP] use strict or similar in PHP?
Hans Schultz wrote: Thanks a lot for your info, I will check that IDE too. But those warning levels give me warning only when they encounter offending code? Are you telling me that it can be setup to fail entire script prior to any execution if there are errors in it? Can you please point me how to setup my PHP installation that way? Only thing I can think of is to set auto_prepend_file in php.ini and then setup a custom error handler in that file to die() on whatever errors you want. http://php.net/manual/function.set-error-handler.php -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: catch the error
-Original Message- From: PJ [mailto:af.gour...@videotron.ca] Sent: Thursday, February 26, 2009 1:16 PM To: a...@ashleysheridan.co.uk Cc: Darryle Steplight; Ricardo Dias Marques; php-general@lists.php.net; MySql Subject: Re: [PHP] Re: catch the error Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:56 -0500, PJ wrote: Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:34 -0500, Darryle Steplight wrote: Hi PJ, $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; Everyone here is trying to help you and that's cool, but EVERYONE on this list may not be so nice. The above credentials is definitely the type of information you want to keep private, unless you don't mind people potentially accessing your database tables and doing whatever they like with them. I suggest doing something like $db_host = 'localhost; $db_user = 'foo'; $db_pass= ''bar; $db_name =''xx; if you are going to post it on the list. On Thu, Feb 26, 2009 at 1:22 PM, PJ af.gour...@videotron.ca wrote: Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com I agree. I wouldn't trust me at all! ;) Ash www.ashleysheridan.co.uk Yeah very stupid of me...but I found the error: see if you can catch it: ? //include (../lib/db1.php);// Connect to database $db_host = 'xxx'; $db_user = 'xxx; $db_pass = 'xxx'; $db_name = 'xxx'; $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 3st query: . mysql_error() . /P); } echo $sql1; echo br /; echo $db_select; exit(); ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com $db_user has not had the string terminated. pray tell was that the answer you were looking for?! Ash www.ashleysheridan.co.uk No. Damn those typos! What seems to have made it work is just $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); not using mysql_select in a string but would you use it in a string? how why? Jesus Christ... everyone on this list must've had a long week, because you guys are going blind. :D In examples sent to you, people foolishly replaced your $db var with $db_connect ONLY FOR PART OF THE SCRIPT. You've defined your database connection as $db_connect in some versions of the source, but then you reference $db (without _connect) in your mysql_select call in that same source. $db = mysql_connect([option list here]); # -- this code instantiates a connection mysql_select_db([some name], $db); # notice how $db is here? $result = mysql_query([some query], $db); # it's here, too! $db becomes your resource link when you use mysql_connect. That resource link must
Re: [PHP] RE: non-auto increment question
On Thu, 2009-02-26 at 14:04 -0500, PJ wrote: Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:44 -0500, Jerry Schwartz wrote: Here's how I mostly do it (albeit simplified): $query = INSERT INTO `sometable`(`title`,`content`) VALUES('$title','$content'); $result = mysql_query($query); $autoId = mysql_insert_id($result); $query = INSERT INTO `another_table`(`link_id`,`value`) VALUES($autoId,'$value'); $result = mysql_query($query); No need to call another query to retrieve the last inserted id, as it is tied to the last query executed within this session. Ash www.ashleysheridan.co.uk [JS] Ashley is absolutely right, I'd forgotten about the mysql_insert_id shorthand. (I'm a one-man band, and for the last week or two I've been immersed in VB for Access forms.) Not only is she right, but her way is better. Presumably a language's internal code is maintained as the specific database changes. You can make yourself more independent of the specific database by using the PDO abstraction, although I would save that for a rainy weekend. Regards, Jerry Schwartz The Infoshop by Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 www.the-infoshop.com www.giiexpress.com www.etudes-marche.com I just checked, and yep, I'm definitely still a he ;) I never thought otherwise... but then I was wondering... there are too many actresses with the same name... ;-) -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com Only in America! Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: catch the error
On Thu, 2009-02-26 at 14:15 -0500, PJ wrote: Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:56 -0500, PJ wrote: Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:34 -0500, Darryle Steplight wrote: Hi PJ, $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; Everyone here is trying to help you and that's cool, but EVERYONE on this list may not be so nice. The above credentials is definitely the type of information you want to keep private, unless you don't mind people potentially accessing your database tables and doing whatever they like with them. I suggest doing something like $db_host = 'localhost; $db_user = 'foo'; $db_pass= ''bar; $db_name =''xx; if you are going to post it on the list. On Thu, Feb 26, 2009 at 1:22 PM, PJ af.gour...@videotron.ca wrote: Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com I agree. I wouldn't trust me at all! ;) Ash www.ashleysheridan.co.uk Yeah very stupid of me...but I found the error: see if you can catch it: ? //include (../lib/db1.php);// Connect to database $db_host = 'xxx'; $db_user = 'xxx; $db_pass = 'xxx'; $db_name = 'xxx'; $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 3st query: . mysql_error() . /P); } echo $sql1; echo br /; echo $db_select; exit(); ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com $db_user has not had the string terminated. pray tell was that the answer you were looking for?! Ash www.ashleysheridan.co.uk No. Damn those typos! What seems to have made it work is just $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); not using mysql_select in a string but would you use it in a string? how why? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com Yeah, you'd typo'd on the variable name. Also, the $ sign doesn't actually denote a string, but a scaler variable, which can be any type, complex or simple. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: catch the error
Boyd, Todd M. wrote: Jesus Christ... everyone on this list must've had a long week, because you guys are going blind. :D In examples sent to you, people foolishly replaced your $db var with $db_connect ONLY FOR PART OF THE SCRIPT. You've defined your database connection as $db_connect in some versions of the source, but then you reference $db (without _connect) in your mysql_select call in that same source. $db = mysql_connect([option list here]); # -- this code instantiates a connection mysql_select_db([some name], $db); # notice how $db is here? $result = mysql_query([some query], $db); # it's here, too! $db becomes your resource link when you use mysql_connect. That resource link must then be passed to your mysql functions. Otherwise, they have no idea which database connection you are attempting to use. # BAD: $db = mysql_connect([options]); $result = mysql_query([some query], $db_connect); # what's $db_connect? who knows! # GOOD: $db = mysql_connect([options]); $result = mysql_query([some query], $db); # same resource link from mysql_connect See? HTH, // Todd Yes, and I would also strongly urge (scream at) PJ, to turn on E_ALL error reporting in any script he has problems with. #1 you'll figure out the problem because the errors will tell you exactly what the problem is undefined variable db_connect, etc... #2 if you can't figure it out, someone here can easily if you give the errors. Virtually every problem you've posted throws an error(s) that will tell you what the F*** is the problem! -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: catch the error
In examples sent to you, people foolishly replaced your $db var with $db_connect ONLY FOR PART OF THE SCRIPT. You've defined your database connection as $db_connect in some versions of the source, but then you reference $db (without _connect) in your mysql_select call in that same source. $db = mysql_connect([option list here]); # -- this code instantiates a connection mysql_select_db([some name], $db); # notice how $db is here? $result = mysql_query([some query], $db); # it's here, too! $db becomes your resource link when you use mysql_connect. That resource link must then be passed to your mysql functions. Otherwise, they have no idea which database connection you are attempting to use. RTFM? If no connection is specified, the last one is used. It is an optional argument (only *really* needed when you have multiple connections in the same script). -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: catch the error
-Original Message- From: Chris [mailto:dmag...@gmail.com] Sent: Thursday, February 26, 2009 4:16 PM To: Boyd, Todd M. Cc: PJ; PHP General list Subject: Re: [PHP] Re: catch the error In examples sent to you, people foolishly replaced your $db var with $db_connect ONLY FOR PART OF THE SCRIPT. You've defined your database connection as $db_connect in some versions of the source, but then you reference $db (without _connect) in your mysql_select call in that same source. $db = mysql_connect([option list here]); # -- this code instantiates a connection mysql_select_db([some name], $db); # notice how $db is here? $result = mysql_query([some query], $db); # it's here, too! $db becomes your resource link when you use mysql_connect. That resource link must then be passed to your mysql functions. Otherwise, they have no idea which database connection you are attempting to use. RTFM? If no connection is specified, the last one is used. It is an optional argument (only *really* needed when you have multiple connections in the same script). RTF E-mail I sent? He had used $db_connect instead of $db. $db_connect hadn't been set to anything. He was specifying a connection, but it was null. Unless it falls back to the last connection used in the case of an empty variable, then this was most likely (read: proven to be) the problem. :p -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] verify text in field
Is there a shorter way of determining if a field contains text? This works but I wonder if I can K.I.S.S. it? I really only need to know if there is or is not a field containing the text specified. I don't need to see it. ?php // Request the text $text = Joe of Egypt; $sql = SELECT title FROM book WHERE title LIKE '$text'; $result = mysql_query($sql); if (!$result) { echo(PError performing query: . mysql_error() . /P); exit(); } // Display the text while ( $row = mysql_fetch_array($result) ) { echo(P . $row[title] . /P); } if ($row[title] == ) echo (Empty!) ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] verify text in field
Try $text = Joe of Egypt; $sql = SELECT title FROM book WHERE title LIKE '$text'; $result = mysql_query($sql); If(mysql_num_rows($result) = '1') { while ( $row = mysql_fetch_array($sql) ) { echo(P . $row[title] . /P); } } My Ideas my not make some people happy with my design but I use it and it works very well -Original Message- From: PJ [mailto:af.gour...@videotron.ca] Sent: Thursday, February 26, 2009 5:07 PM To: php-general@lists.php.net Subject: [PHP] verify text in field Is there a shorter way of determining if a field contains text? This works but I wonder if I can K.I.S.S. it? I really only need to know if there is or is not a field containing the text specified. I don't need to see it. ?php // Request the text $text = Joe of Egypt; $sql = SELECT title FROM book WHERE title LIKE '$text'; $result = mysql_query($sql); if (!$result) { echo(PError performing query: . mysql_error() . /P); exit(); } // Display the text while ( $row = mysql_fetch_array($result) ) { echo(P . $row[title] . /P); } if ($row[title] == ) echo (Empty!) ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- 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] verify text in field
On Thu, Feb 26, 2009 at 06:07:02PM -0500, PJ wrote: Is there a shorter way of determining if a field contains text? This works but I wonder if I can K.I.S.S. it? I really only need to know if there is or is not a field containing the text specified. I don't need to see it. ?php // Request the text $text = Joe of Egypt; $sql = SELECT title FROM book WHERE title LIKE '$text'; $result = mysql_query($sql); if (!$result) { echo(PError performing query: . mysql_error() . /P); exit(); } // Display the text while ( $row = mysql_fetch_array($result) ) { echo(P . $row[title] . /P); } if ($row[title] == ) echo (Empty!) ? If you just want to see whether the passed text is in the title field, and not display it, then no, there's no simpler way. However, I would suggest you surround the $text with percent signs (%) to allow mysql to check if this text is embedded within any of the titles. (Er, that's the way you do it in PostgreSQL; I assume MySQL uses the same mechanism.) Also, I don't know that mysql_query() returns *false* on no rows. I generally check that with mysql_num_rows(). Again, I don't know MySQL that well. PostgreSQL only returns *false* if there's a problem with the query. If the query yields nothing, then you have to check with pg_num_rows(). Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: verify text in field
PJ wrote: Is there a shorter way of determining if a field contains text? This works but I wonder if I can K.I.S.S. it? I really only need to know if there is or is not a field containing the text specified. I don't need to see it. ?php // Request the text $text = Joe of Egypt; $sql = SELECT title FROM book WHERE title LIKE '$text'; $result = mysql_query($sql); if (!$result) { echo(PError performing query: . mysql_error() . /P); exit(); } // Display the text while ( $row = mysql_fetch_array($result) ) { echo(P . $row[title] . /P); } if ($row[title] == ) echo (Empty!) ? // Request the text $text = Joe of Egypt; $sql = SELECT title FROM book WHERE title LIKE '%$text%'; $result = mysql_query($sql); if (!$result) { die(PError performing query: . mysql_error() . /P); } if (mysql_num_rows($result) 0) { // you found text } -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: verify text in field
Shawn McKenzie wrote: PJ wrote: Is there a shorter way of determining if a field contains text? This works but I wonder if I can K.I.S.S. it? I really only need to know if there is or is not a field containing the text specified. I don't need to see it. ?php // Request the text $text = Joe of Egypt; $sql = SELECT title FROM book WHERE title LIKE '$text'; $result = mysql_query($sql); if (!$result) { echo(PError performing query: . mysql_error() . /P); exit(); } // Display the text while ( $row = mysql_fetch_array($result) ) { echo(P . $row[title] . /P); } if ($row[title] == ) echo (Empty!) ? // Request the text $text = Joe of Egypt; $sql = SELECT title FROM book WHERE title LIKE '%$text%'; $result = mysql_query($sql); if (!$result) { die(PError performing query: . mysql_error() . /P); } if (mysql_num_rows($result) 0) { // you found text } Not relevant to your question, but you should be able to shorten it up more like this: --instead of this: $result = mysql_query($sql); if (!$result) { die(PError performing query: . mysql_error() . /P); } --try this: $result = mysql_query($sql) or die(PError performing query: . mysql_error() . /P); -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: catch the error
Shawn McKenzie wrote: Boyd, Todd M. wrote: Jesus Christ... everyone on this list must've had a long week, because you guys are going blind. :D In examples sent to you, people foolishly replaced your $db var with $db_connect ONLY FOR PART OF THE SCRIPT. You've defined your database connection as $db_connect in some versions of the source, but then you reference $db (without _connect) in your mysql_select call in that same source. $db = mysql_connect([option list here]); # -- this code instantiates a connection mysql_select_db([some name], $db); # notice how $db is here? $result = mysql_query([some query], $db); # it's here, too! $db becomes your resource link when you use mysql_connect. That resource link must then be passed to your mysql functions. Otherwise, they have no idea which database connection you are attempting to use. # BAD: $db = mysql_connect([options]); $result = mysql_query([some query], $db_connect); # what's $db_connect? who knows! # GOOD: $db = mysql_connect([options]); $result = mysql_query([some query], $db); # same resource link from mysql_connect See? HTH, // Todd Yes, and I would also strongly urge (scream at) PJ, to turn on E_ALL error reporting in any script he has problems with. #1 you'll figure out the problem because the errors will tell you exactly what the problem is undefined variable db_connect, etc... #2 if you can't figure it out, someone here can easily if you give the errors. Virtually every problem you've posted throws an error(s) that will tell you what the F*** is the problem! Ok, ok, I understant the frustrations But, yes, I think that some of the suggestions were rather hastily made as most of the guys must be very busy and as we are all somewhat normal, we do make mistakes. I mixed up some suggestions with other errors of mine and so we had spaghetti. So, now let's kiss and make up... or as the Italians would say, Amici, come prima. :-) I'm glad you mention the error reporting and I admit i haven't been doing much of that. I do not understand how it should be set up or where I should look for the errors. I did try ini_set(display_errors,true); error_reporting(E_STRICT|E_ALL); but it meant absolutely nothing. I could not find any logs for mysql or php errors and none appeared magically in the page. Perhaps you could steer me to an explanation somewhere. I was able to save some grief for all as I dif manage to find some guidelines on the mysql manual site that were pretty helpful. Thanks for your tolerance of my ignorance - love you all! PJ -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: catch the error
Ashley Sheridan wrote: On Thu, 2009-02-26 at 14:15 -0500, PJ wrote: Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:56 -0500, PJ wrote: Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:34 -0500, Darryle Steplight wrote: Hi PJ, $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; Everyone here is trying to help you and that's cool, but EVERYONE on this list may not be so nice. The above credentials is definitely the type of information you want to keep private, unless you don't mind people potentially accessing your database tables and doing whatever they like with them. I suggest doing something like $db_host = 'localhost; $db_user = 'foo'; $db_pass= ''bar; $db_name =''xx; if you are going to post it on the list. On Thu, Feb 26, 2009 at 1:22 PM, PJ af.gour...@videotron.ca wrote: Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com I agree. I wouldn't trust me at all! ;) Ash www.ashleysheridan.co.uk Yeah very stupid of me...but I found the error: see if you can catch it: ? //include (../lib/db1.php);// Connect to database $db_host = 'xxx'; $db_user = 'xxx; $db_pass = 'xxx'; $db_name = 'xxx'; $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 3st query: . mysql_error() . /P); } echo $sql1; echo br /; echo $db_select; exit(); ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com $db_user has not had the string terminated. pray tell was that the answer you were looking for?! Ash www.ashleysheridan.co.uk No. Damn those typos! What seems to have made it work is just $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); not using mysql_select in a string but would you use it in a string? how why? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com Yeah, you'd typo'd on the variable name. Also, the $ sign doesn't actually denote a string, but a scaler variable, which can be any type, complex or simple. I type too fast and am too speedy... :-) I'll have to look up about the variables. Thanks good night. 'Til the morrow. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: catch the error
Boyd, Todd M. wrote: -Original Message- From: Chris [mailto:dmag...@gmail.com] Sent: Thursday, February 26, 2009 4:16 PM To: Boyd, Todd M. Cc: PJ; PHP General list Subject: Re: [PHP] Re: catch the error In examples sent to you, people foolishly replaced your $db var with $db_connect ONLY FOR PART OF THE SCRIPT. You've defined your database connection as $db_connect in some versions of the source, but then you reference $db (without _connect) in your mysql_select call in that same source. $db = mysql_connect([option list here]); # -- this code instantiates a connection mysql_select_db([some name], $db); # notice how $db is here? $result = mysql_query([some query], $db); # it's here, too! $db becomes your resource link when you use mysql_connect. That resource link must then be passed to your mysql functions. Otherwise, they have no idea which database connection you are attempting to use. RTFM? If no connection is specified, the last one is used. It is an optional argument (only *really* needed when you have multiple connections in the same script). RTF E-mail I sent? He had used $db_connect instead of $db. $db_connect hadn't been set to anything. He was specifying a connection, but it was null. Unless it falls back to the last connection used in the case of an empty variable, then this was most likely (read: proven to be) the problem. The last two emails I saw (no I haven't read the whole thread) were: $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); snip $result1 = mysql_query($sql1,$db); and $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); which have the right variables. Plus I was picking on the you must do this - using the link identifier is an optional thing as I already said. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] RE: non-auto increment question
Being rather new to all this, I understood from the MySql manual that the auto_increment is to b e used immediately after an insertion not intermittently. My application is for administrators (the site owner designates) to update the database from and administration directory, accessed by user/password login... so there's really very little possibility of 2 people accessing at the same time. By using MAX + 1 I keep the id number in the $idIn and can reuse it in other INSERTS -- The statement is confusing at best. For the casual user auto_increment is the way to do. I say for the casual user. That is typical me and you. Basically if you do an insert a unique value is inserted at the time of the insert. As mentioned, there are ways to get this value back in the return. Now why I say it's for the casual user is because if you are using triggers then you can do things prior to this value being used and then the statement above is correct. But you are not going to be using triggers... So, put an auto_increment on the key field and find one of the 2^16 samples of how this works with PHP. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] How do I remove an array element from within a recursive function?
I have an array like this and I simply need to recurse over it and find a matching menu item to remove: array(3) { [dart]= array(10) { [0]= object(menuItem)#4 (9) { [menu]= string(7) My DART [name]= string(7) My DART [title]= string(39) Data Analasys Reliability Tracker [employee_only]= bool(false) [page]= NULL [children]= NULL [parent]= NULL [current]= bool(false) [array_key]= string(4) dart } [1]= object(menuItem)#5 (9) { [menu]= string(5) Login [name]= string(5) Login [title]= string(5) Login [employee_only]= bool(false) [page]= string(9) login.php [children]= NULL [parent]= NULL [current]= bool(false) [array_key]= string(4) dart } [2]= object(menuItem)#6 (9) { [menu]= string(13) Lost Password [name]= string(13) Lost Password [title]= string(13) Lost Password [employee_only]= bool(false) [page]= string(12) forgotpw.php [children]= NULL [parent]= NULL [current]= bool(false) [array_key]= string(4) dart } ... I'm trying to remove [menu] == 'Login' from the array, but despite finding the element, it never removes. isn't that what the reference stuff is for? menuItem::removeMenuItems($navArray['dart'], array('Login', 'Lost Password')); public static final function removeMenuItems($menuItems, $removeArray) { foreach($menuItems as $value) { if (is_array($value-children)) menuItem::removeMenuItems($value-children, $removeArray); else { //echo *** CHECKING .$value-menu. against .implode(',',$removeArray). ***; if (in_array($value-menu, $removeArray)) { //echo *** REMOVING .$value-menu. ***; unset($value); } } } }
[PHP] Re: How do I remove an array element from within a recursive function?
Daevid Vincent wrote: I'm trying to remove [menu] == 'Login' from the array, but despite finding the element, it never removes. isn't that what the reference stuff is for? Yes, but foreach can't modify an array unless you use a reference in the foreach also. Try this: foreach($menuItems as $value) menuItem::removeMenuItems($navArray['dart'], array('Login', 'Lost Password')); public static final function removeMenuItems($menuItems, $removeArray) { foreach($menuItems as $value) { if (is_array($value-children)) menuItem::removeMenuItems($value-children, $removeArray); else { //echo *** CHECKING .$value-menu. against .implode(',',$removeArray). ***; if (in_array($value-menu, $removeArray)) { //echo *** REMOVING .$value-menu. ***; unset($value); } } } } -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: How do I remove an array element from within a recursive function?
Shawn McKenzie wrote: Daevid Vincent wrote: I'm trying to remove [menu] == 'Login' from the array, but despite finding the element, it never removes. isn't that what the reference stuff is for? Yes, but foreach can't modify an array unless you use a reference in the foreach also. Try this: foreach($menuItems as $value) menuItem::removeMenuItems($navArray['dart'], array('Login', 'Lost Password')); public static final function removeMenuItems($menuItems, $removeArray) { foreach($menuItems as $value) { if (is_array($value-children)) menuItem::removeMenuItems($value-children, $removeArray); else { //echo *** CHECKING .$value-menu. against .implode(',',$removeArray). ***; if (in_array($value-menu, $removeArray)) { //echo *** REMOVING .$value-menu. ***; unset($value); } } } } Also, I'm not sure what happens here: if (is_array($value-children)) menuItem::removeMenuItems($value-children, $removeArray); else { Your function defines that var as a reference so you don't have to use a reference in the call. Don't know if it does anything but throw a deprecated notice though. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: How do I remove an array element from within a recursive function?
I tried that and it still doesn't work. I even tried this hardcore test: public static final function removeMenuItems($menuItems, $removeArray) { foreach($menuItems as $value) { unset($value); } } -Original Message- From: Shawn McKenzie nos...@mckenzies.net To: php-general@lists.php.net Subject: [PHP] Re: How do I remove an array element from within a recursive function? Date: Thu, 26 Feb 2009 20:10:20 -0600 Daevid Vincent wrote: I'm trying to remove [menu] == 'Login' from the array, but despite finding the element, it never removes. isn't that what the reference stuff is for? Yes, but foreach can't modify an array unless you use a reference in the foreach also. Try this: foreach($menuItems as $value) menuItem::removeMenuItems($navArray['dart'], array('Login', 'Lost Password')); public static final function removeMenuItems($menuItems, $removeArray) { foreach($menuItems as $value) { if (is_array($value-children)) menuItem::removeMenuItems($value-children, $removeArray); else { //echo *** CHECKING .$value-menu. against .implode(',',$removeArray). ***; if (in_array($value-menu, $removeArray)) { //echo *** REMOVING .$value-menu. ***; unset($value); } } } } -- Thanks! -Shawn http://www.spidean.com
Re: [PHP] Re: How do I remove an array element from within a recursive function?
Daevid Vincent wrote: I tried that and it still doesn't work. I even tried this hardcore test: public static final function removeMenuItems($menuItems, $removeArray) { foreach($menuItems as $value) { unset($value); } } You don't unset the value, you unset the key. ?php $items = array('menu1', 'menu2', 'menu3'); echo Before:\n; print_r($items); foreach ($items as $_menuKey = $value) { if ($value == 'menu2') { unset($items[$_menuKey]); } } echo After:\n; print_r($items); $ php test.php Before: Array ( [0] = menu1 [1] = menu2 [2] = menu3 ) After: Array ( [0] = menu1 [2] = menu3 ) -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] verify text in field
ad...@buskirkgraphics.com wrote: Try $text = Joe of Egypt; $sql = SELECT title FROM book WHERE title LIKE '$text'; $result = mysql_query($sql); If(mysql_num_rows($result) = '1') { while ( $row = mysql_fetch_array($sql) ) { echo(P . $row[title] . /P); } } My Ideas my not make some people happy with my design but I use it and it works very well -Original Message- From: PJ [mailto:af.gour...@videotron.ca] Sent: Thursday, February 26, 2009 5:07 PM To: php-general@lists.php.net Subject: [PHP] verify text in field Is there a shorter way of determining if a field contains text? This works but I wonder if I can K.I.S.S. it? I really only need to know if there is or is not a field containing the text specified. I don't need to see it. ?php // Request the text $text = Joe of Egypt; $sql = SELECT title FROM book WHERE title LIKE '$text'; $result = mysql_query($sql); if (!$result) { echo(PError performing query: . mysql_error() . /P); exit(); } // Display the text while ( $row = mysql_fetch_array($result) ) { echo(P . $row[title] . /P); } if ($row[title] == ) echo (Empty!) ? I think I was not precise in my question. I meant that I do need to be able to use an if condition to determine which instruction will be executed next: e.g. if the $return is (empty or 0) then I INSERT data somewhere; if the $return is a string or text or 1, then I either do a different insert or I abort the operation and ask to restart it with different criteria. I was just wondering if there was conditional operation I could use that would replace this: = if (!$result) { echo(PError performing query: . mysql_error() . /P); exit(); } // Display the text while ( $row = mysql_fetch_array($result) ) { echo(P . $row[title] . /P); } if ($row[title] == ) echo (Empty!) -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: catch the error
PJ you should be getting Warning errors the way you had the code. You definitely is a fun lover and enjoy moments. But while coding dont only think of fastness of coding but also code with logic. I was going to answer you about the $db but later I found lots response already came so didn't really dig to get the errors. Look back, see, I asked if you got rid of the errors :) Now, if you dont use the variable in the parameter it will look for the immediate opened database resource but if you use a variable. THEN it must contain that required resource thats just OBVIOUS reason. And, your error reporting should be reporting that. I haven't checked the code. A funny thing is you are making others think for the things you should be thinking. I dont say its bad. Its actually good for all of us having some drill on the basics :D Regards Lenin www.twitter.com/nine_L www.lenin9l.wordpress.com On Fri, Feb 27, 2009 at 6:37 AM, Chris dmag...@gmail.com wrote: Boyd, Todd M. wrote: -Original Message- From: Chris [mailto:dmag...@gmail.com] Sent: Thursday, February 26, 2009 4:16 PM To: Boyd, Todd M. Cc: PJ; PHP General list Subject: Re: [PHP] Re: catch the error In examples sent to you, people foolishly replaced your $db var with $db_connect ONLY FOR PART OF THE SCRIPT. You've defined your database connection as $db_connect in some versions of the source, but then you reference $db (without _connect) in your mysql_select call in that same source. $db = mysql_connect([option list here]); # -- this code instantiates a connection mysql_select_db([some name], $db); # notice how $db is here? $result = mysql_query([some query], $db); # it's here, too! $db becomes your resource link when you use mysql_connect. That resource link must then be passed to your mysql functions. Otherwise, they have no idea which database connection you are attempting to use. RTFM? If no connection is specified, the last one is used. It is an optional argument (only *really* needed when you have multiple connections in the same script). RTF E-mail I sent? He had used $db_connect instead of $db. $db_connect hadn't been set to anything. He was specifying a connection, but it was null. Unless it falls back to the last connection used in the case of an empty variable, then this was most likely (read: proven to be) the problem. The last two emails I saw (no I haven't read the whole thread) were: $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); snip $result1 = mysql_query($sql1,$db); and $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); which have the right variables. Plus I was picking on the you must do this - using the link identifier is an optional thing as I already said. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: verify text in field
PJ wrote: Is there a shorter way of determining if a field contains text? This works but I wonder if I can K.I.S.S. it? I really only need to know if there is or is not a field containing the text specified. I don't need to see it. ?php // Request the text $text = Joe of Egypt; $sql = SELECT title FROM book WHERE title LIKE '$text'; $result = mysql_query($sql); if (!$result) { echo(PError performing query: . mysql_error() . /P); exit(); } // Display the text while ( $row = mysql_fetch_array($result) ) { echo(P . $row[title] . /P); } if ($row[title] == ) echo (Empty!) ? In addition to other answers, don't forget to escape the string you are passing to the query with mysql_real_escape_string(), otherwise your query will have problems with some characters e.g. apostrophe. Cheers -- David Robley I refuse to make an agenda, Tom said listlessly. Today is Pungenday, the 58th day of Chaos in the YOLD 3175. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Stupid is as Stupid does
As my web app is coming to completion, I added a means to search records (different from site search). This involves reading post input and is many cases converting it to an integer. Damn I feel dumb. The search app wasn't working, so I did what I often do when troubleshooting crap - I put a die($variable) at various points to see if the variable is what it is suppose to be. I kept getting blank returns from die after the conversion from a post string to an integer. I looked in the apache logs, system logs, I even tried rebooting - I couldn't figure why the smurf the variable wasn't converting to integer. I even turned off eaccelerator in case that was causing it, though it never has given me issue before (except once when I was doing something in a really shoddy way - cleaned up my method and it behaved) After several hours contemplating if I had bad RAM, an issue with the CPU, verifying my RPMs were good, wondering why I wasn't getting anything in the logs, it dawned on me. If variable is an integer, die($var) returns nothing and is suppose to return nothing, it takes a string as an argument to echo on death - die($var) is what I wanted. I need sleep. I did finally find the error and fix the record search problem. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] use strict or similar in PHP?
Hans Schultz wrote: Is there some way for PHP to cache some data on the page? I like very much PHP's speed but it would be even better to be able to cache some frequently used data from database? Databases such as MySQL are very good at caching. -- Per Jessen, Zürich (3.6°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Stupid is as Stupid does
Use var_dump() to see contents of a variable. It will print something even if variable is empty or undefined. Michael A. Peters mpet...@mac.com píse v diskusním príspevku news:49a79416.6060...@mac.com... As my web app is coming to completion, I added a means to search records (different from site search). This involves reading post input and is many cases converting it to an integer. Damn I feel dumb. The search app wasn't working, so I did what I often do when troubleshooting crap - I put a die($variable) at various points to see if the variable is what it is suppose to be. I kept getting blank returns from die after the conversion from a post string to an integer. I looked in the apache logs, system logs, I even tried rebooting - I couldn't figure why the smurf the variable wasn't converting to integer. I even turned off eaccelerator in case that was causing it, though it never has given me issue before (except once when I was doing something in a really shoddy way - cleaned up my method and it behaved) After several hours contemplating if I had bad RAM, an issue with the CPU, verifying my RPMs were good, wondering why I wasn't getting anything in the logs, it dawned on me. If variable is an integer, die($var) returns nothing and is suppose to return nothing, it takes a string as an argument to echo on death - die($var) is what I wanted. I need sleep. I did finally find the error and fix the record search problem. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stupid is as Stupid does
Michael A. Peters wrote: If variable is an integer, die($var) returns nothing and is suppose to return nothing, it takes a string as an argument to echo on death - die($var) is what I wanted. I often use ?php var_dump($myVar); exit(1); ? to debug and print the value of the variable. xDebug adds nice formatting to var_dump(). -- With warm regards, Sudheer. S Business: http://binaryvibes.co.in, Tech stuff: http://techchorus.net, Personal: http://sudheer.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php