php-windows Digest 10 Nov 2002 11:17:23 -0000 Issue 1432
Topics (messages 16833 through 16838):
Re: Subject: mysql_fetch_array problem
16833 by: neil smith
Print or Echo?
16834 by: Stephen Edmonds
16835 by: Maxim Maletsky
16837 by: Cam Dunstan
Re: mysql_fetch_array problem
16836 by: Dash McElroy
MsWord html
16838 by: Steel
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
At 14:10 09/11/2002 +0000, you wrote:
Message-ID: <000201c28788$00d50e20$0200a8c0@ncus>
From: "Zeus" <[EMAIL PROTECTED]>
Subject: mysql_fetch_array problem
I try to display mysql database using fetch_array but there seem to problem,
i m new with PHP and mysql.I didn't quite sure, what's worng with my
codes.i havent include the formyet. the error messages:
Warning: mysql_fetch_field(): supplied argument is not a valid MySQL result
resource in c:\apache\htdocs\zeus\shoutbox.php on line 17
I think the problem lies in the line below :
$result = mysql_query("SELECT * FROM shoutbox BY ID desc LIMIT 5");
shoud read ORDER BY :
$result = mysql_query("SELECT * FROM shoutbox ORDER BY ID desc LIMIT 5");
=========
If the SQL is not correctly formed, you will not get a result set - hence
your error (not a valid MySQL result means no results were returned)
To check for returned results, use the function like this :
if (mysql_num_rows($result)==0) {
print ("No results returned - please check query");
} else {
.. rest of your code - while loop etc.
}
You can always chec a query by printing it, then cut & paste into mysql
console or (better imho) insert it into the query box in phpmyadmin - you
will get more useful / less cryptic information there.
Hope that helps,
Regards,
Neil Smith.
--- End Message ---
--- Begin Message ---
This is not strictly a help question, but more of a do you question.
Simply, do you use print, or do you use echo?
Personally, I use print. I like the way its set out, and find it easier to
understand code. But then again, that was just the way i learnt php.
What do you think?
Stephen
--- End Message ---
--- Begin Message ---
This was discussed a lot over thetime on php.general. try searching
archives
--
Maxim Maletsky
[EMAIL PROTECTED]
On Sat, 9 Nov 2002 17:10:26 -0000 "Stephen Edmonds" <[EMAIL PROTECTED]>
wrote:
> This is not strictly a help question, but more of a do you question.
>
> Simply, do you use print, or do you use echo?
>
> Personally, I use print. I like the way its set out, and find it easier to
> understand code. But then again, that was just the way i learnt php.
>
> What do you think?
>
> Stephen
>
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
Stephen
I use echo, but that is not to say there is anything wrong with using print.
I`ve never really appreciated the difference, guess it gets back to the very
first script one ever wrote when trying to learn the language - I still use
$result and $myrow and $sqlstatement to this day purely out of habit
straight out of the first tutorial I ever read!. I would bet that a lot of
VB refugees would tend to use PRINT for example.
I wouldn`t worry too much, in a team environment the more readable code is
the better, so whatever makes for more readable code - yeah?
----- Original Message -----
From: "Stephen Edmonds" <[EMAIL PROTECTED]>
To: "PHP Helplist Windows" <[EMAIL PROTECTED]>
Sent: Sunday, November 10, 2002 4:10 AM
Subject: [PHP-WIN] Print or Echo?
> This is not strictly a help question, but more of a do you question.
>
> Simply, do you use print, or do you use echo?
>
> Personally, I use print. I like the way its set out, and find it easier to
> understand code. But then again, that was just the way i learnt php.
>
> What do you think?
>
> Stephen
>
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Rich,
Anything coming from a user should be escaped. I'd rather not run the risk
of having control characters or other similar SQL injection tricks.
Either way - it's good to think ahead just in case anything you put into
the database (i.e. strings with ' or " or other characters) won't show up
with the extra slash there.
-Dash
You worry too much about your job. Stop it. You're not paid enough to
worry.
On Sat, 9 Nov 2002, Rich Gray wrote:
> Erm.. isn't the addslashes() just needed to protect the SQL query?
>
> IMO the data in the db will not have any slashes embedded in normal
> circumstances, so there is no reason to stripslashes() any data coming from
> a database column...
>
> Rich
> -----Original Message-----
> From: Dash McElroy [mailto:dash.php@;westonefcu.org]
> Sent: 08 November 2002 16:53
> To: 'Zeus'; [EMAIL PROTECTED]
> Subject: RE: [PHP-WIN] mysql_fetch_array problem
>
>
> Zeus,
>
> 2 notes:
>
> 1. Data you insert into a database should be addslashes($varname) first (or
> another encoding) to protect against MySQL injection vulnerabilities. A nice
> stripslashes($varname) on the way out gets rid of the slashes. You could
> also use urlencode($varname) and urldecode($varname). Helpful for storing
> URL's.
>
> 2. mysql_fetch_array
> (http://www.php.net/manual/en/function.mysql-fetch-array.php) is nowhere to
> be found in your code. You're using mysql_fetch_field...
>
> Either way, this is what I do:
>
> $result = mysql_query("SELECT * FROM shoutbox BY ID desc LIMIT 5");
> $count = mysql_num_rows($result);
>
> if ($count > 0) {
> for ($i=0;$i<$count;$i++) {
> $row = mysql_fetch_array($result);
> echo $row['time'] ."<br />".$row['name']."<br
> />".$row['message']."<br />\n";
> }
> }
> elseif ($count == 0) {
> echo "No results returned";
> }
> else {
> echo "Invalid Query. MySQL error: ".mysql_error();
> }
>
> Please note - this code is off the top of my head, I have not actually tried
> it :)
>
> -Dash
>
> -----Original Message-----
> From: Zeus [mailto:zeus_dreamer@;myrealbox.com]
> Sent: Saturday, November 09, 2002 4:29 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP-WIN] mysql_fetch_array problem
>
>
> I try to display mysql database using fetch_array but there seem to problem,
> i m new with PHP and mysql.
> I didn't quite sure, what's worng with my codes.i havent include the form
> yet.
>
> the error messages:
> Warning: mysql_fetch_field(): supplied argument is not a valid MySQL result
> resource in c:\apache\htdocs\zeus\shoutbox.php on line 17
>
>
> code in shoutbox.php:
>
> <?PHP
>
> mysql_connect('localhost', 'zeus', 'pass') or die ("deadconnect");
> mysql_select_db('zeussama_db') or die ("no db");
>
> if($submit)
> {
> $time=date("h:ia d/j/y");
> $result=mysql_query("INSERT INTO shoutbox (id,name,message,time)","values
> ('NULL','$name','$message','$time')");
> }
> ?>
>
>
> <?php
> $result = mysql_query("SELECT * FROM shoutbox BY ID desc LIMIT 5");
> while($r=mysql_fetch_field($result))
> {
> $time=$r["time"];
> $id=$r["id"];
> $message=$r["message"];
> $name=$r["name"];
>
> echo "$time <br>";
> echo "$name <br>";
> echo "$message <br>";
> }
> ?>
>
> ================================
> :.zeus:.
> http://www.redrival.com/zeussama
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.404 / Virus Database: 228 - Release Date: 15/10/2002
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Hi php-windows,
Does anybody knows, what regexp can help me remove almost all
M$ Word2000 HTML tags and styles?
Let the Force Be with Yo! ;)
--
The Same,
Steel mailto:asergey@;inbox.ru
http://www.none.ru
--- End Message ---