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
https://forums.phpfreaks.com/topic/93769-another-problem/
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
https://forums.phpfreaks.com/topic/93769-another-problem/#findComment-480513
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
https://forums.phpfreaks.com/topic/93769-another-problem/#findComment-480997
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
https://forums.phpfreaks.com/topic/93769-another-problem/#findComment-481094
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.