Jump to content

Code not working!


DJTim666

Recommended Posts

The following code won't display the results from the DB

 

<?php
require_once("core.php");
loggedin();

echo "<h3>Mail</h3>";
echo "MENU WILL GO HERE...<br /><br />";

if (!$act){
$sql = "SELECT * FROM messages WHERE to_name='$Yourname'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
//determine backround colour
if ($row[state] == 'read'){
	$color = "white";
}
else {
	$color = "orange";
}
echo "<table border='1'>
	<tr><td><b>From</b></td>
	<td><b>Subject</b></td>
	<td><b>Time Sent</b></td>
	<td><b>Delete?</b></td></tr>";
if (mysql_num_rows($result) == 0){
	showerror("<tr><td colspan='4'>No new messages.</td></tr></table>");
}
else {
echo "<form action='mail.php' method='post'>";
while ($row2 = mysql_fetch_array($result)){
	echo "<tr><td bgcolor='$color'><a href='profiles.php?user=" . $row2[from_name] . "'>$row2[from_name]</a></td>
		<td bgcolor='$color'><a href='$PHP_SELF?act=read'>$row2[subject]</a></td>
		<td bgcolor='$color'>$row2[time_sent]</td>
		<td bgcolor='$color'><input type='checkbox' name='delete' value='yes' /></td>";
}
echo "</form></table>";
}
}

require_once("footer.php");
?>

 

It doesn't print out an error, and there is a result in the DB.

 

--

DJ

Link to comment
https://forums.phpfreaks.com/topic/63993-code-not-working/
Share on other sites

 

@GuiltyGear

You can use either one of the formats. I could use $row["w.e"] if I really wanted :)!

 

Guilty gear is correct; are you asking for help or not?

 

Reading the manual here:

http://uk.php.net/manual/en/language.types.array.php

(Scroll down to Array do's and dont's) explains you can't use $foo[bar] but rather $foo ["bar"].

You really can't do anything you really want to.

Link to comment
https://forums.phpfreaks.com/topic/63993-code-not-working/#findComment-318994
Share on other sites

I have fixed the problem. Thanks for all the the help.

 

I do have another question though;;

 

I want the users of my site to be able to enter comments with a ' in the word (e.g. don't) but at the same time I want to use mysql_real_escape_string(); to prevent hacking. How would I go about letting my users use words like don't without having it look like this --> don\'t.

 

Please help me :)!

 

--

DJ

Link to comment
https://forums.phpfreaks.com/topic/63993-code-not-working/#findComment-319019
Share on other sites

If magic quotes is on, then all your quotes will be escaped, hance them looking like \' - use stripslashes() to undo it - i.e. undo them just before outputting to browser, make sure they are escpaed in SQL queries....

 

Check out the manual:

http://uk.php.net/manual/en/security.magicquotes.php

Link to comment
https://forums.phpfreaks.com/topic/63993-code-not-working/#findComment-319208
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.