Re: PHP4, MySQL, errors....

From: Date: Thu, 09 Aug 2001 17:05:33 +0000
Subject: Re: PHP4, MySQL, errors....
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-11194@lists.php.net to get a copy of this message
"Cato Larsen" <ravenno1@world-online.no> wrote in message news:20010809112324.38133.qmail@pb1.pair.com... > Just to have said it... Im green in both PHP4 and MySQL. > Can anyone say what I've been doing wrong here, and how to fix it, or even > better. Debug the whole shit! =) First, make sure PHP is actually running. Try this: <?php $str = "PHP is not running!"; echo substr($str, 0, 7) . substr($str, 11); ?> For one thing, trying to echo unescaped double-quotes won't work, ie echo "<table leftmargin = "0">"; // no good! Use ' or \" instead. Second, all this variable-renaming seems like a waste of effort; just use the array directly. > $cid = mysql_connect($host,$usr,$pwd); > if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } If the connection fails, your script prints an error message, then continues trying to query... if (!$cid) { echo "Error: ".mysql_error(); exit; } ... or redirect them back to a different page. > # setup SQL statement > $SQL = " SELECT * FROM memberinfo "; > $SQL = $SQL . " WHERE prof = '$prof' "; $sql = "SELECT * FROM memberingo " ."WHERE prof='$prof' "; > echo ("<P><DT><B>Members who are $prof s</B><BR>\n"); <dt> should only occur in <dl>...</dl> > $apperiance = $row["apperiance"]; 'appearance' > $prof = $row["prof"]; ? you already know prof; why query for it? First thing to do is write a couple of functions to take care of the formatting for you: // Generic tag-formatting routine // Ensures all tags are closed properly; // Also forces you to think about tag-clause formatting // so the final result is readable. function clause($preopen, $tag, $opts, $pretext, $text, $preclose) { return "$preopen<$tag $opts>$pretext$text$preclose</$tag>"; } function table($contents) { return clause("\n", "table", "style='margin-left: 80px;'>", "", $contents, "\n"); } function row($contents) { return clause("\n\t", "tr", "style='margin-top: 30px;'", "", $contents, "\n\t"); } function cell($text, $width=0) { if ($text == "") // check for empty str $text = "&nbsp;"; $opts = ($width > 0 ? "style='width: $widthpx;'" : ""); return clause("\n\t\t", "td", $opts, "", $text, ""); } function bold($text) { return clause("", "b", "", "", $text, ""); } I would simplify your table, too, at least until you get it working; play with it after that. $contents = row(cell("", 150) . cell("", 200) . cell("", 200)); while ($row = mysql_fetch_array($retid)) $contents .= row( cell("<img src='{$row["picurl"]}'>") .cell( bold( "{$row["tit"]} {$row["charname"]} " ."&quot;{$row["charnick"]}&quot;" ."{$row["charsname"]}" )."<br>" .bold("Contact: ").$row["email"]."<br>" .bold("Level: ").$row["lvl"]."<br>" .bold("Breed: ").$row["breed"]."<br>" .bold("Profession: ").$prof."<br>" .bold("Location: ").$row["loc"]."<br>" .bold("AIM: ").$row["aim"]."<br>" .bold("ICQ: ").$row["icq"]."<br>" .bold("MSN: ").$row["msn"]."<br>" .bold("Yahoo!: ").$row["yahoo"]."<br>" ) .cell( "<br>" .bold("Born: ").$row["born"]."<br>" .bold("Appearance: ").$row["appearance"]."<br>" .bold("Position: ").$row["posn"]."<br>" .bold("Characteristics: ").$row["charac"]."<br>" .bold("Strengths/weaknesses: ").$row["streng"]."<br>" .bold("Bio: ").$row["bio"]."<br>" ) ); echo table($contents); (Note: this approach builds the whole table in memory, in order to print it out using the clause() function; it might be worth breaking that out and printing the table a row at a time if there are many rows in the table.)

« previous php.db (#11194) next »