SacredProductions Posted May 21, 2006 Share Posted May 21, 2006 This is a bit of code im using to get the posts for a guestbook out of a database.[code]$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");} [/code]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 Quote Link to comment https://forums.phpfreaks.com/topic/10099-solvedwhy-the-is-this-not-working/ Share on other sites More sharing options...
.josh Posted May 21, 2006 Share Posted May 21, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/10099-solvedwhy-the-is-this-not-working/#findComment-37628 Share on other sites More sharing options...
SacredProductions Posted May 21, 2006 Author Share Posted May 21, 2006 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 postedThe 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 Quote Link to comment https://forums.phpfreaks.com/topic/10099-solvedwhy-the-is-this-not-working/#findComment-37730 Share on other sites More sharing options...
AndyB Posted May 21, 2006 Share Posted May 21, 2006 [!--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.[code]$sql="SELECT * FROM guestbook ORDER BY id DESC";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10099-solvedwhy-the-is-this-not-working/#findComment-37734 Share on other sites More sharing options...
.josh Posted May 21, 2006 Share Posted May 21, 2006 okay hows about removing this red part:while ($gbarray = mysql_fetch_array($result[!--coloro:red--][span style=\"color:red\"][!--/coloro--][b],$conn[/b][!--colorc--][/span][!--/colorc--])){ Quote Link to comment https://forums.phpfreaks.com/topic/10099-solvedwhy-the-is-this-not-working/#findComment-37738 Share on other sites More sharing options...
SacredProductions Posted May 21, 2006 Author Share Posted May 21, 2006 [!--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 :( Quote Link to comment https://forums.phpfreaks.com/topic/10099-solvedwhy-the-is-this-not-working/#findComment-37739 Share on other sites More sharing options...
.josh Posted May 21, 2006 Share Posted May 21, 2006 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?[code]$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");}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10099-solvedwhy-the-is-this-not-working/#findComment-37743 Share on other sites More sharing options...
AndyB Posted May 21, 2006 Share Posted May 21, 2006 OK, to be sure we're all working on the same (code) problem please post the [u]current full version[/u] of what is not working on your live server. Quote Link to comment https://forums.phpfreaks.com/topic/10099-solvedwhy-the-is-this-not-working/#findComment-37744 Share on other sites More sharing options...
Barand Posted May 21, 2006 Share Posted May 21, 2006 Trying to eliminate possibilities -Is the code you posted inside a function and are you trying to echo those varibles outside the function? Quote Link to comment https://forums.phpfreaks.com/topic/10099-solvedwhy-the-is-this-not-working/#findComment-37745 Share on other sites More sharing options...
SacredProductions Posted May 21, 2006 Author Share Posted May 21, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/10099-solvedwhy-the-is-this-not-working/#findComment-37746 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.