Welcome to WebmasterWorld Guest from 54.224.5.186

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP / MySQL Troubles

Newbie Question

     
2:14 pm on Aug 14, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:Aug 14, 2002
posts:41
votes: 0


Hello - Im a total newbie, so please - be kind.

I am developing a very simple site, that, is no longer simple to me.

The following code does not work for me:

<?
$db = mysql_connect(host, user, pass)or die(mysql_error());
mysql_select_db(NAME,$db) or die(mysql_error());

$query = "SELECT * FROM list WHERE \"%$form_type%\"='1'";
$result = mysql_query("$query") or die(mysql_error());

while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
print $row[name];
}

?>

...Any idea why? Looks like the SQL statement works, but nothing prints out.

Thanks,
- RC78

2:20 pm on Aug 14, 2002 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 17, 2002
posts:601
votes: 0


Where does this VAR %$form_type% come from? Maybe I am just missing what this does. Also I dont think you want to have the \'s infront of the " for that. I am guessing though.
2:33 pm on Aug 14, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:Aug 14, 2002
posts:41
votes: 0


%$form_type% is passed through a form to this phtml script...
2:39 pm on Aug 14, 2002 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 17, 2002
posts:601
votes: 0


Have you tried printing the varible only? Just to make sure it is passing correctly from the form?
2:42 pm on Aug 14, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:Aug 14, 2002
posts:41
votes: 0


Yes, I have.

At the top of the results script, I am using the following:

print "$form_type\n";

That prints the form element of that name, which is also a table column name.

So, when it passes through to the SELECT statement, it should just pull results based on the values of that column, right?

2:46 pm on Aug 14, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 6, 2000
posts:904
votes: 0


You could also try

print(mysql_num_rows($result));

before entering the while loop - this would tell you how many results your query returned, which might give an indication whether your query is correctly constructed...

2:46 pm on Aug 14, 2002 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 17, 2002
posts:601
votes: 0


Try changing your select to "SELECT * FROM list WHERE '$form_type'='1'";
See if that changes anything. You are only trying to select one result right?
2:48 pm on Aug 14, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:Aug 14, 2002
posts:41
votes: 0


sugarkane...
Thank you!

I just implemented that, and the SELECT statement is not returning any records at all, leading me to believe that I have something going wrong.

I will take a look into why, and post back if I have future problems.

Thank you agin.
RC78

2:49 pm on Aug 14, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:June 3, 2002
posts:169
votes: 0


this line here:

$query = "SELECT * FROM list WHERE \"%$form_type%\"='1'";

should be:

$query = "SELECT * FROM list WHERE ".$form_type."='1'";

but that's only going to pull values that ColX as a value of 1... Is that what you're expecting?

2:49 pm on Aug 14, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:Aug 14, 2002
posts:41
votes: 0


Knowles, no, I am returning a series of results, not just one.
2:52 pm on Aug 14, 2002 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 17, 2002
posts:601
votes: 0


Thats where your problem is coming in then. Your select statment is only pulling the result that is equal to 1 in table form_type. So if this is actually a list of names thats why its not working. it should be ".$form_type." = ".$name.""; and you will need to find a way to define $name in the form. Or have it static but that would cause alot of select statements.

<added>Thank you Mavherick I knew I was typing that select wrong but was trying to go off memory which I dont have!</added>

[edited by: Knowles at 2:57 pm (utc) on Aug. 14, 2002]

2:55 pm on Aug 14, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:Aug 14, 2002
posts:41
votes: 0


Everyone...

Thank you for helping!

The script works fine now, based on all of your input.

Thank you again for your help - glad I came out of "lurk mode" here!

RC78

5:35 pm on Aug 14, 2002 (gmt 0)

Moderator

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8471
votes: 222



$result = mysql_query("$query")

Nobody mentioned this - if query is a variable, the "" are not necessary. They don't hurt anything, but they serve no purpose.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members