calvinschools Posted May 4, 2011 Share Posted May 4, 2011 I populated the database made sure I was connecting and get no display. Can someone please check this. Thanks <?php $max_items = 5; $db = mysql_connect('xxxx','xxxx','xxxx!'); mysql_select_db ('xxxx',$db); function displayPartners($all = 0){ global $db, $max_items; if ($all == 0){ $query = "SELECT id,title" . "DATE_FORMAT(postdate, '%Y-%m-%d) as date" . "FROM partners ORDER BY postdate DESC LIMIT $max_items"; }else{ $query = "SELECT id,title" . "DATE_FORMAT(postdate, '%Y-%m-%d') as date " . "FROM partners ORDER BY postdate DESC"; } $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)){ echo "<TABLE border = \"1\" width=\"300\>\n"; $date = $row['date']; $title = htmlentities ($row['title']); echo "<TR><TD><b>$title</b>posted on $date</TD></TR>\n"; echo "<TR><TD>$partners</TD></TR>\n"; $comment_query = "SELECT count(*) FROM comment WHERE partners_id ={$row['id']}"; $comment_result = mysql_query ($comment_query); $comment_row = mysql_fetch_row($comment_result); echo "<TR><TD><ahref=\"{$_SERVER['PHP_SELF']}" . "?action = show&id={$row['id']}\<Comments</a>($comment_row[0]}</TD></TR>\n)"; echo "</TABLE>\n"; echo "<BR>\n"; } if ($all == 0){ echo "<ahref =\{SERVER_['PHP_SELF']}" . "?action=all\">View all Partners</a>\n; } } function displayOneItem($id){ global $db; $query = 'SELECT * FROM partners WHERE id = $id'; $result = mysql_query ($query); if (mysql_num_rows ($result) == 0){ echo 'No partners found '; return; } $row = mysql_fetch_assoc($result); echo '<TABLE border =\"1\" width=\"300\>\n"; $title = htmlentities ($row['title']); echo "<TR><TD><b>$title</b></TD></TR>\n"; echo "<TR><TD>$partners<b>/TD></TR>\n"; echo "</TABLE>\n"; echo "<BR>\n"; displayComments($id); } function displayComments($id){ global $db; $query = "SELECT * FROM comment WHERE partners_id=$id"; $result = mysql_query ($query); echo "Comments:<BR><HRwidth=\"300\">\n"; while ($row = mysql_fetch_assoc ($result)){ echo "<TABLE border=\"1\"width=\"300\">\n"; $name = htmlentities ($row['name']); echo "<TR><TD><b>by:$name</b></TD></TR>\n"; $comment = strip_tags ($row['comment'],'<a><b><i><u>'); $comment = nl2br ($comment); echo "<TR><TD>$comment</TD></TR>\n"; echo "</TABLE>\n"; echo "<BR>\n"; } echo "<HR width=\"300\">"; echo "<FORM action=\"{$_SERVER['PHP_SELF']}" . "?action=addcomment&id=$id\"method=POST>\n"; echo "Name: <input type=\"text\" " . "width=\"30\"name=\"name\"><BR>\n"; echo "<TEXTAREA cols=\"40\" rows=\"5\" " . "name=\"comment\"></TEXTAREA><BR>\n"; echo "<input type=\"submit\"name=\"submit\" " ."value=\"Add Comment\"\n"; echo "</FORM>\n"; } function addComment($id) { global $db; $query = "INSERT INTO comment " . "VALUES('',$id,'{$_POST['name']}'," . "'{$_POST['comment']}')"; mysql_query ($query); echo "Comment submitted<BR>\n"; echo "<a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id=$id\">Back</a>\n"; } echo "<CENTER>\n"; switch($_GET['action']) { case 'show': displayOneItem($_GET['id']); break; case 'all': displayPartners(1); break; case 'addcomment': addComment($GET['id']); break; default: displayPartners(); } } ?> MOD EDIT: . . . BBCode tags added. Quote Link to comment https://forums.phpfreaks.com/topic/235477-i-get-nothing/ Share on other sites More sharing options...
Pikachu2000 Posted May 4, 2011 Share Posted May 4, 2011 When posting code, please enclose it within the forum's . . . BBCode tags. How did you make sure you're connected to the database? There's no logic in that code that would report any errors that are encountered by mysql. Do you have php's error_reporting set to an appropriate level, and display_errors = On? Seeing the errors is an important part of debugging code wile developing. Quote Link to comment https://forums.phpfreaks.com/topic/235477-i-get-nothing/#findComment-1210202 Share on other sites More sharing options...
fugix Posted May 4, 2011 Share Posted May 4, 2011 i believe this $query = "SELECT id,title" . "DATE_FORMAT(postdate, '%Y-%m-%d) as date" . "FROM partners ORDER BY postdate DESC LIMIT $max_items"; }else{ $query = "SELECT id,title" . "DATE_FORMAT(postdate, '%Y-%m-%d') as date " . "FROM partners ORDER BY postdate DESC"; } should be $query = "SELECT id,title, DATE_FORMAT(postdate, '%Y-%m-%d) as date FROM partners ORDER BY postdate DESC LIMIT $max_items"; }else{ $query = "SELECT id,title, DATE_FORMAT(postdate, '%Y-%m-%d') as date FROM partners ORDER BY postdate DESC"; } Quote Link to comment https://forums.phpfreaks.com/topic/235477-i-get-nothing/#findComment-1210203 Share on other sites More sharing options...
calvinschools Posted May 4, 2011 Author Share Posted May 4, 2011 When posting code, please enclose it within the forum's . . . BBCode tags. How did you make sure you're connected to the database? There's no logic in that code that would report any errors that are encountered by mysql. Do you have php's error_reporting set to an appropriate level, and display_errors = On? Seeing the errors is an important part of debugging code wile developing. I have a connect.php file that gives me an error message if it doesn't connect. I ran that and everything seemed to be ok. No error message that is. Quote Link to comment https://forums.phpfreaks.com/topic/235477-i-get-nothing/#findComment-1210206 Share on other sites More sharing options...
Pikachu2000 Posted May 4, 2011 Share Posted May 4, 2011 But it appears you aren't using it in this script, and there's no error handling in there either, so you really don't know if there's a db connection or not. There are typos in the first query string, and where is the main function ever actually called? Quote Link to comment https://forums.phpfreaks.com/topic/235477-i-get-nothing/#findComment-1210209 Share on other sites More sharing options...
calvinschools Posted May 4, 2011 Author Share Posted May 4, 2011 I wrote in a Mysql error and fixed first query. <?php $max_items = 5; $db = mysql_connect('cccccc','-----','-------'); if (!$db) { die('Could not connect: ' . mysql_error()); } mysql_select_db ('-----',$db); function displayPartners($all = 0){ global $db, $max_items; if ($all == 0){ $query = "SELECT id,title, DATE_FORMAT(postdate, '%Y-%m-%d) as date FROM partners ORDER BY postdate DESC LIMIT $max_items"; }else{ $query = "SELECT id,title, DATE_FORMAT(postdate, '%Y-%m-%d') as date FROM partners ORDER BY postdate DESC"; } $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)){ echo "<TABLE border = \"1\" width=\"300\>\n"; $date = $row['date']; $title = htmlentities ($row['title']); echo "<TR><TD><b>$title</b>posted on $date</TD></TR>\n"; echo "<TR><TD>$partners</TD></TR>\n"; $comment_query = "SELECT count(*) FROM comment WHERE partners_id ={$row['id']}"; $comment_result = mysql_query ($comment_query); $comment_row = mysql_fetch_row($comment_result); echo "<TR><TD><ahref=\"{$_SERVER['PHP_SELF']}" . "?action = show&id={$row['id']}\<Comments</a>($comment_row[0]}</TD></TR>\n)"; echo "</TABLE>\n"; echo "<BR>\n"; } if ($all == 0){ echo "<ahref =\{SERVER_['PHP_SELF']}" . "?action=all\">View all Partners</a>\n; } } function displayOneItem($id){ global $db; $query = 'SELECT * FROM partners WHERE id = $id'; $result = mysql_query ($query); if (mysql_num_rows ($result) == 0){ echo 'No partners found '; return; } $row = mysql_fetch_assoc($result); echo '<TABLE border =\"1\" width=\"300\>\n"; $title = htmlentities ($row['title']); echo "<TR><TD><b>$title</b></TD></TR>\n"; echo "<TR><TD>$partners<b>/TD></TR>\n"; echo "</TABLE>\n"; echo "<BR>\n"; displayComments($id); } function displayComments($id){ global $db; $query = "SELECT * FROM comment WHERE partners_id=$id"; $result = mysql_query ($query); echo "Comments:<BR><HRwidth=\"300\">\n"; while ($row = mysql_fetch_assoc ($result)){ echo "<TABLE border=\"1\"width=\"300\">\n"; $name = htmlentities ($row['name']); echo "<TR><TD><b>by:$name</b></TD></TR>\n"; $comment = strip_tags ($row['comment'],'<a><b><i><u>'); $comment = nl2br ($comment); echo "<TR><TD>$comment</TD></TR>\n"; echo "</TABLE>\n"; echo "<BR>\n"; } echo "<HR width=\"300\">"; echo "<FORM action=\"{$_SERVER['PHP_SELF']}" . "?action=addcomment&id=$id\"method=POST>\n"; echo "Name: <input type=\"text\" " . "width=\"30\"name=\"name\"><BR>\n"; echo "<TEXTAREA cols=\"40\" rows=\"5\" " . "name=\"comment\"></TEXTAREA><BR>\n"; echo "<input type=\"submit\"name=\"submit\" " ."value=\"Add Comment\"\n"; echo "</FORM>\n"; } function addComment($id) { global $db; $query = "INSERT INTO comment " . "VALUES('',$id,'{$_POST['name']}'," . "'{$_POST['comment']}')"; mysql_query ($query); echo "Comment submitted<BR>\n"; echo "<a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id=$id\">Back</a>\n"; } echo "<CENTER>\n"; switch($_GET['action']) { case 'show': displayOneItem($_GET['id']); break; case 'all': displayPartners(1); break; case 'addcomment': addComment($GET['id']); break; default: displayPartners(); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/235477-i-get-nothing/#findComment-1210211 Share on other sites More sharing options...
Pikachu2000 Posted May 4, 2011 Share Posted May 4, 2011 There's a closing single quote missing around the format string for DATE_FORMAT() in the first query. You also seem to have some string quoting issues as well. if ($all == 0){ echo "<ahref =\{SERVER_['PHP_SELF']}" . "?action=all\">View all Partners</a>\n; // <--- MISSING CLOSING QUOTE } } function displayOneItem($id){ // [sNIP] // $row = mysql_fetch_assoc($result); echo '<TABLE border =\"1\" width=\"300\>\n"; // <--- opening/closing quote mismatch (should be double quote at beginning) $title = htmlentities($row['title']); Then once those are corrected, you'll find that you have an extra closing curly brace at the end. After that, there are no more syntax errors, so make those changes and see if it has any affect. Quote Link to comment https://forums.phpfreaks.com/topic/235477-i-get-nothing/#findComment-1210216 Share on other sites More sharing options...
calvinschools Posted May 4, 2011 Author Share Posted May 4, 2011 I can't win. Changed all typos then: <CENTER> Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/20/7812420/html/test.php on line 25 <ahref =\{SERVER_['PHP_SELF']}?action=all">View all Partners</a> <?php $max_items = 5; $db = mysql_connect('cccccc','-----','-------'); if (!$db) { die('Could not connect: ' . mysql_error()); } mysql_select_db ('-----',$db); function displayPartners($all = 0){ global $db, $max_items; if ($all == 0){ $query = "SELECT id,title, DATE_FORMAT(postdate, '%Y-%m-%d) as date FROM partners ORDER BY postdate DESC LIMIT $max_items"; }else{ $query = "SELECT id,title, DATE_FORMAT(postdate, '%Y-%m-%d') as date FROM partners ORDER BY postdate DESC"; } $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)){ echo "<TABLE border = \"1\" width=\"300\>\n"; $date = $row['date']; $title = htmlentities ($row['title']); echo "<TR><TD><b>$title</b>posted on $date</TD></TR>\n"; echo "<TR><TD>$partners</TD></TR>\n"; $comment_query = "SELECT count(*) FROM comment WHERE partners_id ={$row['id']}"; $comment_result = mysql_query ($comment_query); $comment_row = mysql_fetch_row($comment_result); echo "<TR><TD><ahref=\"{$_SERVER['PHP_SELF']}" . "?action = show&id={$row['id']}\<Comments</a>($comment_row[0]}</TD></TR>\n)"; echo "</TABLE>\n"; echo "<BR>\n"; } if ($all == 0){ echo "<ahref =\{SERVER_['PHP_SELF']}" . "?action=all\">View all Partners</a>\n; } } function displayOneItem($id){ global $db; $query = 'SELECT * FROM partners WHERE id = $id'; $result = mysql_query ($query); if (mysql_num_rows ($result) == 0){ echo 'No partners found '; return; } $row = mysql_fetch_assoc($result); echo '<TABLE border =\"1\" width=\"300\>\n"; $title = htmlentities ($row['title']); echo "<TR><TD><b>$title</b></TD></TR>\n"; echo "<TR><TD>$partners<b>/TD></TR>\n"; echo "</TABLE>\n"; echo "<BR>\n"; displayComments($id); } function displayComments($id){ global $db; $query = "SELECT * FROM comment WHERE partners_id=$id"; $result = mysql_query ($query); echo "Comments:<BR><HRwidth=\"300\">\n"; while ($row = mysql_fetch_assoc ($result)){ echo "<TABLE border=\"1\"width=\"300\">\n"; $name = htmlentities ($row['name']); echo "<TR><TD><b>by:$name</b></TD></TR>\n"; $comment = strip_tags ($row['comment'],'<a><b><i><u>'); $comment = nl2br ($comment); echo "<TR><TD>$comment</TD></TR>\n"; echo "</TABLE>\n"; echo "<BR>\n"; } echo "<HR width=\"300\">"; echo "<FORM action=\"{$_SERVER['PHP_SELF']}" . "?action=addcomment&id=$id\"method=POST>\n"; echo "Name: <input type=\"text\" " . "width=\"30\"name=\"name\"><BR>\n"; echo "<TEXTAREA cols=\"40\" rows=\"5\" " . "name=\"comment\"></TEXTAREA><BR>\n"; echo "<input type=\"submit\"name=\"submit\" " ."value=\"Add Comment\"\n"; echo "</FORM>\n"; } function addComment($id) { global $db; $query = "INSERT INTO comment " . "VALUES('',$id,'{$_POST['name']}'," . "'{$_POST['comment']}')"; mysql_query ($query); echo "Comment submitted<BR>\n"; echo "<a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id=$id\">Back</a>\n"; } echo "<CENTER>\n"; switch($_GET['action']) { case 'show': displayOneItem($_GET['id']); break; case 'all': displayPartners(1); break; case 'addcomment': addComment($GET['id']); break; default: displayPartners(); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/235477-i-get-nothing/#findComment-1210223 Share on other sites More sharing options...
Pikachu2000 Posted May 4, 2011 Share Posted May 4, 2011 At least there aren't any parse errors. A query is failing, though For debugging purposes while developing, you should output any errors generated by the database, along with the query string that generated them. You can do that in this manner, where $query would be changed to whatever variable holds the query string being executed. You would not want to echo all that information on a live, production site, however . . . $result = mysql_query( $query ) or die ( "<br>Query string: $query<br>Produced error: " . mysql_error() . '<br>On line ' . __LINE__ ); Quote Link to comment https://forums.phpfreaks.com/topic/235477-i-get-nothing/#findComment-1210231 Share on other sites More sharing options...
calvinschools Posted May 4, 2011 Author Share Posted May 4, 2011 Here's the newest. <CENTER> Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/20/7812420/html/test.php on line 25 <ahref =\{SERVER_['PHP_SELF']}?action=all">View all Partners</a> if ($all == 0){ echo "<ahref =\{SERVER_['PHP_SELF']}" . "?action=all\">View all Partners</a>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/235477-i-get-nothing/#findComment-1210238 Share on other sites More sharing options...
fugix Posted May 4, 2011 Share Posted May 4, 2011 in your above code it looks like you still forgot the ending single quote in the DATE FORMAT in your query Quote Link to comment https://forums.phpfreaks.com/topic/235477-i-get-nothing/#findComment-1210240 Share on other sites More sharing options...
Pikachu2000 Posted May 4, 2011 Share Posted May 4, 2011 Oh, and why are you using all of the $gt; < html chartacter codes? Those will cause the < and > character to be displayed, rather than be used as markup. Quote Link to comment https://forums.phpfreaks.com/topic/235477-i-get-nothing/#findComment-1210242 Share on other sites More sharing options...
calvinschools Posted May 4, 2011 Author Share Posted May 4, 2011 ok doing some error checking now. Quote Link to comment https://forums.phpfreaks.com/topic/235477-i-get-nothing/#findComment-1210245 Share on other sites More sharing options...
calvinschools Posted May 4, 2011 Author Share Posted May 4, 2011 ok last post I'm going to sleep. Ran this and verified I am connected for sure. <html> <head> <title>Listing every database, table, and field</title> </head> <body> <?php $user = "xxx"; $pass = "xxx"; $db = "x"; $link = mysql_connect( "x", $user, $pass ); if ( ! $link ) die( "Couldn't connect to MySQL" ); $db_res = mysql_list_dbs( $link ); while ( $db_rows = mysql_fetch_row( $db_res ) ) { print "<b>$db_rows[0]</b>\n"; if ( !@mysql_select_db( $db_rows[0], $link ) ) { print "<dl><dd>couldn't connect -- " . mysql_error() ." </dl>"; continue; } $tab_res = mysql_list_tables( $db_rows[0], $link ); print "\t<dl><dd>\n"; while ( $tab_rows = mysql_fetch_row( $tab_res ) ){ print "\t<b>$tab_rows[0]</b>\n"; $query_res = mysql_query( "SELECT * from $tab_rows[0]" ); $num_fields = mysql_num_fields( $query_res ); print "\t\t<dl><dd>\n"; for ( $x=0; $x<$num_fields; $x++ ){ print "\t\t<i>"; print mysql_field_type( $query_res, $x ); print "</i> <i>"; print mysql_field_len( $query_res, $x ); print "</i> <b>"; print mysql_field_name( $query_res, $x ); print "</b> <i>"; print mysql_field_flags( $query_res, $x ); print "</i><br>\n"; } print "\t\t</d1>\n"; } print "\t</d1>\n"; } mysql_close( $link ); ?> </body> </html> then ran this again and got: <CENTER> <ahref =\{SERVER_['PHP_SELF']} ?action=all">View all Partners</a> could it be the character codes or am i just butchering the code? <?php $db = mysql_connect('x,x,x'); if (!$db) { die('Could not connect: ' . mysql_error()); } mysql_select_db ('x',$db); $max_items = 5; function displayPartners($all = 0){ global $db, $max_items; if ($all == 0){ $query = "SELECT id,title, DATE_FORMAT(postdate, '%Y-%m-%d') as date FROM partners ORDER BY postdate DESC LIMIT $max_items"; }else{ $query = "SELECT id,title, DATE_FORMAT(postdate, '%Y-%m-%d') as date FROM partners ORDER BY postdate DESC"; } if (!$db) while ($row = mysql_fetch_assoc($result)){ echo "<TABLE border = \"1\" width=\"300\>\n"; $date = $row['date']; $title = htmlentities ($row['title']); echo "<TR><TD><b>$title</b>posted on $date</TD></TR>\n"; echo "<TR><TD>$partners</TD></TR>\n"; $comment_query = "SELECT count(*) FROM comment WHERE partners_id ={$row['id']}"; $comment_result = mysql_query ($comment_query); $comment_row = mysql_fetch_row($comment_result); echo "<TR><TD><ahref=\"{$_SERVER['PHP_SELF']}" . "?action = show&id={$row['id']}\<Comments</a>($comment_row[0]}</TD></TR>\n)"; echo "</TABLE>\n"; echo "<BR>\n"; } if ($all == 0){ echo "<ahref =\{SERVER_['PHP_SELF']} ?action=all\">View all Partners</a>\n"; } } function displayOneItem($id){ global $db; $query = 'SELECT * FROM partners WHERE id = $id'; $result = mysql_query ($query); if (mysql_num_rows ($result) == 0){ echo 'No partners found '; return; } $row = mysql_fetch_assoc($result); echo "<TABLE border =\"1\" width=\"300\>\n"; $title = htmlentities ($row['title']); echo "<TR><TD><b>$title</b></TD></TR>\n"; echo "<TR><TD>$partners<b>/TD></TR>\n"; echo "</TABLE>\n"; echo "<BR>\n"; displayComments($id); } function displayComments($id){ global $db; $query = "SELECT * FROM comment WHERE partners_id=$id"; $result = mysql_query ($query); echo "Comments:<BR><HRwidth=\"300\">\n"; while ($row = mysql_fetch_assoc ($result)){ echo "<TABLE border=\"1\"width=\"300\">\n"; $name = htmlentities ($row['name']); echo "<TR><TD><b>by:$name</b></TD></TR>\n"; $comment = strip_tags ($row['comment'],'<a><b><i><u>'); $comment = nl2br ($comment); echo "<TR><TD>$comment</TD></TR>\n"; echo "</TABLE>\n"; echo "<BR>\n"; } echo "<HR width=\"300\">"; echo "<FORM action=\"{$_SERVER['PHP_SELF']}" . "?action=addcomment&id=$id\"method=POST>\n"; echo "Name: <input type=\"text\" " . "width=\"30\"name=\"name\"><BR>\n"; echo "<TEXTAREA cols=\"40\" rows=\"5\" " . "name=\"comment\"></TEXTAREA><BR>\n"; echo "<input type=\"submit\"name=\"submit\" " ."value=\"Add Comment\"\n"; echo "</FORM>\n"; } function addComment($id) { global $db; $query = "INSERT INTO comment " . "VALUES('',$id,'{$_POST['name']}'," . "'{$_POST['comment']}')"; mysql_query ($query); echo "Comment submitted<BR>\n"; echo "<a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id=$id\">Back</a>\n"; } echo "<CENTER>\n"; switch($_GET['action']) { case 'show': displayOneItem($_GET['id']); break; case 'all': displayPartners(1); break; case 'addcomment': addComment($GET['id']); break; default: displayPartners(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/235477-i-get-nothing/#findComment-1210266 Share on other sites More sharing options...
gizmola Posted May 4, 2011 Share Posted May 4, 2011 It's not the character codes, but I'm not understanding why you are using them all over the place. Why not just this (errors fixed either way): echo "View all Partners\n"; One other thing --- it's best not to use $_SERVER['PHP_SELF']. Instead use basename($_SERVER['SCRIPT_FILENAME']). There are numerous blogposts you can find about why PHP_SELF should not be trusted. Quote Link to comment https://forums.phpfreaks.com/topic/235477-i-get-nothing/#findComment-1210268 Share on other sites More sharing options...
calvinschools Posted May 4, 2011 Author Share Posted May 4, 2011 Thanks again gizmola. Getting there. Changed the html and got: <CENTER> View all Partners is now linked but no display of anything from the db. Quote Link to comment https://forums.phpfreaks.com/topic/235477-i-get-nothing/#findComment-1210273 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.