SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look below for the better looking code.

    Ok, the script give no syntax errors, or anything, but It just loops forever, telling me that the same new submissions are there. I know the problem is somewhere within the while loop at the top.

    The script when I first show up, spits out the tips that need to be verfied (allowed to go live) and it loops, making a table, with a bunch of forms, and options for each individual tip. I want to update one tip at a tip, by checking the radio to yes, it should change the variable "verify" in the database from 0 to 1. But it does nothing. I also, want to beable to update the text of the tip itself, because, often times people misspell stuff. (like me )

    I don't get why it won't work, but I am fairly sure it has something to do with the while loop at the top.
    Last edited by WALoeIII; May 18, 2001 at 10:08.

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, I haven't tried to read through all your code because it is too dificult to
    keep track of all the nested control structures in it. Please learn how to indent
    your code followings accepted conventions such as the pear
    http://php.net/manual/en/pear.standards.php standards.
    An easier introduction to good coding standards can be found here http://www.gnu.org/prep/standards.html#SEC21
    The section "Making the Best Use of C" is the most relevent section.
    The C programming conventions apply because PHP is a C-"like" language.
    Good coding practice is the differnce between others being able to read
    and understand your code easily

    Anyway, if you say your program gets stuck in an infinite loop then it would
    be becasue the while condition

    while (isset($HTTP_POST_VARS["update"]))

    never evaluates to false. Unless you call unset($HTTP_POST_VARS["update"])
    to destroy that variable the while condition will always return true.

  3. #3
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, I'll work on cleaning up my code, sorry.

  4. #4
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <?php
    include ("$DOCUMENT_ROOT/includes/global.php");
    dbconnect("content");
    if (isset($HTTP_POST_VARS["update"])) {
    	//update everything
    	
    	while (isset($HTTP_POST_VARS["update"])) {
    			mysql_select_db("content");
    			//update tip
    			if ($HTTP_POST_VARS["tip"] != $tip) {
    				safe_query("UPDATE tips set tip='".addslashes(htmlspecialchars($HTTP_POST_VARS["updated_tip"]))."' WHERE tip_id='".$HTTP_POST_VARS["update_id"]."'");
    				unset($HTTP_POST_VARS["tip"]
    			}
    			//update verified
    			if ($HTTP_POST_VARS["verify"] != $verify) {
    			safe_query("UPDATE tips set verify='".$HTTP_POST_VARS["verify"]."' WHERE tip_id='".$HTTP_POST_VARS["update_id"]."'");
    			unset($HTTP_POST_VARS["verify"]
    			}
    	unset($HTTP_POST_VARS["verify"]);
    	}
    
    	//check to see if there is anything to update, and then do it
    	mysql_select_db("content");
    	$result = safe_query("SELECT * from tips where verify=0");
    
    	if (mysql_num_rows($result) == 0) {
    
    		//there is nothing to verify
    		$title="JuniorSailing.com  Admin  Tips";
    		include("$DOCUMENT_ROOT/includes/admin_header.php");
    
    		?>
    		<font class="main_header">There are no submissions to be verified at this time.</font>
    		<?
    		include("$DOCUMENT_ROOT/includes/admin_footer.php");
    
    	} else {
    
    		//work with unverified info
    		$title="JuniorSailing.com  Admin  Tips";
    		include("$DOCUMENT_ROOT/includes/admin_header.php");
    		?>
    		<font class="main_header">New Submissions:</font><br>
    		<table border="0" bgcolor="#000000" cellpadding="4" cellspacing="1" align="left">
    	
    		<?
    		//new submissions data
    
    			while ($row = mysql_fetch_array($result)) {
    				mysql_select_db("main");
    				$username_result = safe_query("SELECT username FROM user WHERE userid='".$row["userid"]."'");
    				extract(mysql_fetch_array($username_result));
    
    				print "<form method=\"post\" action=\"".$PHP_SELF."\">";
    				print "<input type=\"hidden\" name=\"update\" value=\"1\">\n";
    				print "<input type=\"hidden\" name=\"update_id\" value=\"".$row["tip_id"]."\">\n";
    				print " <tr>\n";
    				print "  <td  bgcolor=\"#ABABAB\" align=\"left\"><font class=\"standard\">Author:</font></td>\n";
    				print "  <td bgcolor=\"#ABABAB\" align=\"left\"><font class=\"standard\">".$username."</font></td>\n";
    				print " </tr>\n";
    				print " <tr>\n";
    				print "  <td bgcolor=\"#BCBCBC\" align=\"left\"><font class=\"standard\">Zone:</font></td>\n";
    				print "  <td bgcolor=\"#BCBCBC\" align=\"left\"><font class=\"standard\">".$row["zone"]."</font></td>\n";
    				print " </tr>\n";
    				print " <tr>\n";
    				print "  <td valign=\"top\" bgcolor=\"#ABABAB\" align=\"left\"><font class=\"standard\">Tip:</font></td>\n";
    				print "  <td valign=\"top\" bgcolor=\"#ABABAB\" align=\"left\"><textarea name=\"updated_tip\" cols=\"30\" rows=\"7\" wrap>".$row["tip"]."</textarea></td>\n";
    				print " </tr>\n";
    				print " <tr>\n";
    				print "  <td bgcolor=\"#BCBCBC\" align=\"left\"><font class=\"standard\">Authorize/Update:</font></td>\n";
    				print "  <td bgcolor=\"#BCBCBC\" align=\"left\"><font class=\"standard\">Yes</font><input type=\"radio\" name=\"verify\" value=\"1\"><font class=\"standard\">No</font><input type=\"radio\" name=\"verify\" value=\"0\" checked> <input type=\"submit\" value=\"Authorize/Update\"></td>\n";
    				print " </tr>\n";
    				print "</form>\n\n";
    			}
    		?>
    
    		</table>
    		<?
    		include("$DOCUMENT_ROOT/includes/admin_footer.php");
    
    	}
    
    } else {
    	//check to see if there is anything to update, and then do it
    	
    	mysql_select_db("content");
    	$result = safe_query("SELECT * from tips where verify=0");
    	
    	if (mysql_num_rows($result) == 0) {
    
    			//there is nothing to verify
    			$title="JuniorSailing.com  Admin  Tips";
    			include("$DOCUMENT_ROOT/includes/admin_header.php");
    
    			?>
    			<font class="main_header">There are no submissions to be verified at this time.</font>
    		<?
    		include("$DOCUMENT_ROOT/includes/admin_footer.php");
    
    	} else {
    
    		//work with unverified info
    		$title="JuniorSailing.com  Admin  Tips";
    		include("$DOCUMENT_ROOT/includes/admin_header.php");
    		?>
    		<font class="main_header">New Submissions:</font><br>
    		<table border="0" bgcolor="#000000" cellpadding="4" cellspacing="1" align="left">
    			
    		<?
    		//new submissions data
    
    		while ($row = mysql_fetch_array($result))
    			{
    		mysql_select_db("main");
    		$username_result = safe_query("SELECT username FROM user WHERE userid='".$row["userid"]."'");
    		extract(mysql_fetch_array($username_result));
    
    		print "<form method=\"post\" action=\"".$PHP_SELF."\">";
    		print "<input type=\"hidden\" name=\"update\" value=\"1\">\n";
    		print "<input type=\"hidden\" name=\"update_id\" value=\"".$row["tip_id"]."\">\n";
    		print " <tr>\n";
    		print "  <td  bgcolor=\"#ABABAB\" align=\"left\"><font class=\"standard\">Author:</font></td>\n";
    		print "  <td bgcolor=\"#ABABAB\" align=\"left\"><font class=\"standard\">".$username."</font></td>\n";
    		print " </tr>\n";
    		print " <tr>\n";
    		print "  <td bgcolor=\"#BCBCBC\" align=\"left\"><font class=\"standard\">Zone:</font></td>\n";
    		print "  <td bgcolor=\"#BCBCBC\" align=\"left\"><font class=\"standard\">".$row["zone"]."</font></td>\n";
    		print " </tr>\n";
    		print " <tr>\n";
    		print "  <td valign=\"top\" bgcolor=\"#ABABAB\" align=\"left\"><font class=\"standard\">Tip:</font></td>\n";
    		print "  <td valign=\"top\" bgcolor=\"#ABABAB\" align=\"left\"><textarea name=\"updated_tip\" cols=\"30\" rows=\"7\" wrap>".$row["tip"]."</textarea></td>\n";
    		print " </tr>\n";
    		print " <tr>\n";
    		print "  <td bgcolor=\"#BCBCBC\" align=\"left\"><font class=\"standard\">Authorize/Update:</font></td>\n";
    		print "  <td bgcolor=\"#BCBCBC\" align=\"left\"><font class=\"standard\">Yes</font><input type=\"radio\" name=\"verify\" value=\"1\"><font class=\"standard\">No</font><input type=\"radio\" name=\"verify\" value=\"0\" checked> <input type=\"submit\" value=\"Authorize/Update\"></td>\n";
    		print " </tr>\n";
    		print "</form>\n\n";
    			}
    		?>
    
    		</table>
    			<?
    		include("$DOCUMENT_ROOT/includes/admin_footer.php");
    
    	}
    
    }
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •