Jump to content

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


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

[!--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]
Link to comment
Share on other sites

[!--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 :(
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.