Page 1 of 1

i need a very small basic help:)

Posted: Wed Sep 20, 2006 2:31 pm
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]

Posted: Wed Sep 20, 2006 2:35 pm
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"

Posted: Wed Sep 20, 2006 2:44 pm
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

Posted: Wed Sep 20, 2006 2:48 pm
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?

Posted: Wed Sep 20, 2006 2:55 pm
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?

Posted: Wed Sep 20, 2006 2:58 pm
by hawleyjr
Moved to PHP-Code Forum

Posted: Wed Sep 20, 2006 3:01 pm
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:)

Posted: Wed Sep 20, 2006 3:06 pm
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%'

Posted: Wed Sep 20, 2006 3:09 pm
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 :)