Jump to content

Another problem!


sam06

Recommended Posts

Hi Guys-

I've been using MySQL for a while now, only getting used to it, but there is still a couple of problems, even when I seem to copy and paste from my working code...

Anyway:

My Code;

$result = mysql_query("SELECT * FROM email
WHERE 'to'='$name'") or die(mysql_error());  
echo "<table border='1'>";

echo "<tr> <th>Id</th> <th>Time Added</th> <th>To</th> <th>From</th> <th>Comment</th> </tr>";

// keeps getting the next row until there are no more to get

while($row = mysql_fetch_array( $result )) {

// Print out the contents of each row into a table

echo "<tr><td>"; 

echo $row['id'];

echo "</td><td>"; 

echo $row['time'];

echo "</td><td>"; 

echo $row['to'];

echo "</td><td>"; 

echo $row['from'];

echo "</td><td>"; 

echo $row['comment'];

echo "</td></tr>";  
} 



echo "</table>";

Unfortunetly this keeps outputing with

Id 	Time Added 	To 	From 	Comment
}

But no data- can anyone help me?

 

Many Thanks,

Sam

Link to comment
Share on other sites

$result = mysql_query("SELECT * FROM email

WHERE 'to'='$name'") or die(mysql_error());

 

try taking out the Quotes around the to.

 

$result = mysql_query("SELECT * FROM email
WHERE to='$name'") or die(mysql_error()); 

 

Also test to see if the $result is working.

if($result) {
echo " Yay It works";
}
else
{
echo "Sad, it doesn't work ";
}

Link to comment
Share on other sites

Where are you setting the $name variable.  It is not in the code.

 

echo "Name is " . $name;

 

and see if it has a value.

 

 

Sorry for not posting it, it obtains $name from a post at the top.

echo "Name is " . $name; does work, it returns Name is [name from post from]

 

 

$result = mysql_query("SELECT * FROM email

WHERE 'to'='$name'") or die(mysql_error());

 

try taking out the Quotes around the to.

 

$result = mysql_query("SELECT * FROM email
WHERE to='$name'") or die(mysql_error()); 

 

Also test to see if the $result is working.

if($result) {
echo " Yay It works";
}
else
{
echo "Sad, it doesn't work ";
}

 

Yep, its returning 'Yay it works'

However, removing the quotes from to returns:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'to='????'' at line 2

????? = the value of $name

Link to comment
Share on other sites

Very Strange,

I've changed the field to 'newto', and found out why it's not returning anything

 

When I run the query from the code into the SQL on phpmyadmin, it returns nothing.

My table looks like:

id time                         newto  from comment

1  2008-02-29 17:16:23  Helen  Sam  Test

2 2008-03-01 14:26:15 Sam Helen Yep

 

But when I run the query:SELECT * FROM email WHERE 'newto'='Helen'

It returns nothing.

And thats the query in my php code, so thats why it's not returning anything.

What am I doing wrong?

 

EDIT::::::

I changed the code, and now it works!

The new code is:

$result = mysql_query("SELECT * FROM email
WHERE newto='$name'") or die(mysql_error());   

Thanks to those who helped.

 

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.