i need a very small basic help:)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bedrosamo
Forum Newbie
Posts: 16
Joined: Wed Sep 20, 2006 2:21 pm

i need a very small basic help:)

Post by bedrosamo »

hawleyjr | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

i just want to print on a page something that is found in my database, i used

Code: Select all

define("LOG_USERNAME","root");

define("LOG_PASSWORD","*****");

define("DBname","sql_tables");


mysql_connect("localhost","root","*****");
mysql_select_db(DBname);

$query  = "SELECT UserName, CustID, Email FROM customer WHERE UserName=a";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo "Name :{$row['UserName']} <br>" .
         "Subject : {$row['CustID']} <br>" . 
         "Message : {$row['Email']} <br><br>";
}

and its not working , who can help me fixing it ? (seems its not understanding the "mysql_fetch_array" and i dont know php to fix it .. i just want to pring this:s anyone can help?

HawleyJR: Please Review our forum rules!


hawleyjr | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]2.[/b] Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.[/quote]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]1.[/b] Select the correct board for your query. Take some time to read the guidelines in the sticky topic.[/quote]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Hi. You got a top secret error message?

This is the forum
General Discussion
Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.
you probably wanted "PHP - Code"
bedrosamo
Forum Newbie
Posts: 16
Joined: Wed Sep 20, 2006 2:21 pm

Post by bedrosamo »

the error is :
warning: mysql_fetch_array(): supplied argumant is not a valid MYSQL resuly resource in C:\programfiles\vertrigoServ\www\test.php on line 16
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

<?php
/* LOG_USERNAME and LOG_PASSWORD arn't used */
define("LOG_USERNAME","root");
define("LOG_PASSWORD","vertrigo");
define("DBname","sql_tables");

mysql_connect("localhost","root","vertrigo") or die(mysql_error());
mysql_select_db(DBname) or die(mysql_error());

$query = "SELECT UserName, CustID, Email FROM customer WHERE UserName=a";
$result = mysql_query($query) or die(mysql_error()) ;

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
	echo "Name :{$row['UserName']} <br />
		Subject : {$row['CustID']} <br />
		Message : {$row['Email']} <br />";
}
?>
it will certainly complain about the WHERE UserName=a part. What exactly is it supposed to do?
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

PHP tags around your code please...

Your code is missing a number of error catches. Check the PHP Manual for using die() in combination with mysql commands to capture and report errors. Until these are added, it's hard to say what has gone wrong.

Also, why are you using the user/password explicitly after you went and defined constants for their usage?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Moved to PHP-Code Forum
bedrosamo
Forum Newbie
Posts: 16
Joined: Wed Sep 20, 2006 2:21 pm

Post by bedrosamo »

volka , 1st of all a BIG thank you:) i really appreciate ur work and how fast u r :)
2nd , the "where username= a " part , i mean that i need like the custID and Email for the person who's username is "a" got me ?
anyway 1 more question , can i get ur msn so that if i have some small pbs with php i can ask u?(i can help u in java,c,c++... but dont know any php thats the pb..
anyway if u prefer talking on website its ok:)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

because everyone has lots of small problems I don't have a msn/yahoo/whateverIM anymore ;)
--
string literals (including 1-char literals like a) have to be marked for mysql as well as for php.
try

Code: Select all

$query = "SELECT UserName, CustID, Email FROM customer WHERE UserName='a' ";
That exactly matches a and maybe A (depending on the field definition including the keyword binary or not).
If you want all UserNames starting with a you need WHERE UserName LIKE 'a%'
bedrosamo
Forum Newbie
Posts: 16
Joined: Wed Sep 20, 2006 2:21 pm

Post by bedrosamo »

big thanks :) anyway if u need any questions reguarding java/c/c++ u can pm me im ready to turn it back to u the favor u did for me :)
this is all the questions for today :)
Post Reply