homepage Welcome to WebmasterWorld Guest from 54.227.215.140
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP / MySQL Troubles
Newbie Question
Racecar78

10+ Year Member



 
Msg#: 620 posted 2:14 pm on Aug 14, 2002 (gmt 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

 

Knowles

10+ Year Member



 
Msg#: 620 posted 2:20 pm on Aug 14, 2002 (gmt 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.

Racecar78

10+ Year Member



 
Msg#: 620 posted 2:33 pm on Aug 14, 2002 (gmt 0)

%$form_type% is passed through a form to this phtml script...

Knowles

10+ Year Member



 
Msg#: 620 posted 2:39 pm on Aug 14, 2002 (gmt 0)

Have you tried printing the varible only? Just to make sure it is passing correctly from the form?

Racecar78

10+ Year Member



 
Msg#: 620 posted 2:42 pm on Aug 14, 2002 (gmt 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?

sugarkane

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 620 posted 2:46 pm on Aug 14, 2002 (gmt 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...

Knowles

10+ Year Member



 
Msg#: 620 posted 2:46 pm on Aug 14, 2002 (gmt 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?

Racecar78

10+ Year Member



 
Msg#: 620 posted 2:48 pm on Aug 14, 2002 (gmt 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

mavherick

10+ Year Member



 
Msg#: 620 posted 2:49 pm on Aug 14, 2002 (gmt 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?

Racecar78

10+ Year Member



 
Msg#: 620 posted 2:49 pm on Aug 14, 2002 (gmt 0)

Knowles, no, I am returning a series of results, not just one.

Knowles

10+ Year Member



 
Msg#: 620 posted 2:52 pm on Aug 14, 2002 (gmt 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]

Racecar78

10+ Year Member



 
Msg#: 620 posted 2:55 pm on Aug 14, 2002 (gmt 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

ergophobe

WebmasterWorld Administrator ergophobe us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 620 posted 5:35 pm on Aug 14, 2002 (gmt 0)


$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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved