Jump to content


Photo

**SOLVED**Why the $%*! is this not working?


  • Please log in to reply
9 replies to this topic

#1 SacredProductions

SacredProductions
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 21 May 2006 - 04:25 AM

This is a bit of code im using to get the posts for a guestbook out of a database.
$sql="SELECT * FROM guestbook ORDER BY id desc;";
$result=mysql_query($sql,$conn) or die(mysql_error());
while ($gbarray = mysql_fetch_array($result,$conn)){
    $name=$gbarray['name'];
    $email=$gbarray['email'];
    $message=$gbarray['message'];
    textbox("$name - $email","$message");
}

Im not getting any "official" errors.. however, the variables are not storing anything and are showing up as blank spaces on the webpage. I've used this method many times, and yet for some reason this time its not working. I triple checked the naming.. everything. It seems perhaps there may be something throwing it off somewhere else in the document? I dont think so.. *sigh*. Is there a better way to do this? Any help is appreciated,

-Ben

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 21 May 2006 - 09:01 AM

firstly,

$sql="SELECT * FROM guestbook ORDER BY id desc;";

you should probably take out that ; after desc i know that doesn't work for me. but maybe that's some kind of setting or version thing and it works for you. may as well try it.

secondly,

echo your variables $name, $email $message directly after you set them (before textbox()). see if they are printing on the screen what they are supposed to be printing.

thirdly,

textbox("$name - $email","$message");

i assume that you have a function somewhere called textbox. Your variables that you are passing do not need to be in quotes. I am assuming that you want to pass 2 string variables, one which just shows "bob - bob@bobc.om" and the other "what about bob" (examples). it should lookie like this:

textbox($name . " - " . $email", $message);

fourthly,

if the vars are echoing properly and none of the above works, then please post the contents of your textbox function
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 SacredProductions

SacredProductions
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 21 May 2006 - 05:36 PM

Thank you for your reply Crayon,

I did run some tests,

- I echo'd the number of rows being returned which came out as 2, which is correct.
- I also echo'd the variables, $name, $email, and $message, yet nothing was returned.
- Then I set up the code on a different page, seperate from anything else and the variables still returned blank, which shows that the problem lies in the bit of code I posted

The textbox() function is just setting up the tables with a header (the first argument) and the content (the second argument). This part is working as the textboxes are showing up, along with the " - " in the header. What remains unkown is why the variables are not storing anything.

Again, any help is appreciated-

Ben

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 21 May 2006 - 05:46 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]- I echo'd the number of rows being returned which came out as 2, which is correct.
- I also echo'd the variables, $name, $email, and $message, yet nothing was returned.[/quote]
Then clearly there's a problem with the querystring in the live version.

$sql="SELECT * FROM guestbook ORDER BY id DESC";

Legend has it that reading the manual never killed anyone.
My site

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 21 May 2006 - 05:53 PM

okay hows about removing this red part:

while ($gbarray = mysql_fetch_array($result[!--coloro:red--][span style=\"color:red\"][!--/coloro--],$conn[!--colorc--][/span][!--/colorc--])){
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 SacredProductions

SacredProductions
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 21 May 2006 - 05:58 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]okay hows about removing this red part:

while ($gbarray = mysql_fetch_array($result,$conn)){ [/quote]

Yes, I did realize that was an issue shortly before you posted, but that still did not remedy the problem.

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Then clearly there's a problem with the querystring in the live version.

$sql="SELECT * FROM guestbook ORDER BY id DESC";
[/quote]

Still nothing :(

#7 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 21 May 2006 - 06:07 PM

so you're telling me that if you throw in a num rows right after that $result, it will display 2? (see below) and you have the while argument looking like this (see below) and yet when you echo $name, $email, and $message (see below) you get nothing?

$sql="SELECT * FROM guestbook ORDER BY id desc";
$result=mysql_query($sql,$conn) or die(mysql_error());

$blah = mysql_num_rows($result);
echo $blah;

while ($gbarray = mysql_fetch_array($result)){
    $name=$gbarray['name']; echo $name;
    $email=$gbarray['email']; echo $email;
    $message=$gbarray['message']; echo $message;
    textbox("$name - $email","$message");
}

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#8 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 21 May 2006 - 06:08 PM

OK, to be sure we're all working on the same (code) problem please post the current full version of what is not working on your live server.
Legend has it that reading the manual never killed anyone.
My site

#9 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 21 May 2006 - 06:11 PM

Trying to eliminate possibilities -

Is the code you posted inside a function and are you trying to echo those varibles outside the function?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#10 SacredProductions

SacredProductions
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 21 May 2006 - 06:13 PM

Umm.. not quite sure why.. but for some reason it has now decided to work. I didnt change anything.. perhaps there was a problem with.. umm... [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /]

Anyways, thank you all for your effort.

-Ben




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users