Jump to content

Form Script Help


ririe44

Recommended Posts

For some reason, everything with my code here works fine, except when my page loads, my sidebar and footer are not on the page!  Until I fill out the form, and submit, then they show up... I think my problem is somewhere in my if else statement, but I can't see where it's making it disapear... will you take a look for me?  Thanks!

 

<?
$host="host"; // Host name
$db_username="username"; // Mysql username
$db_password="password"; // Mysql password
$db_name="name"; // Database name
$tbl_name="tbl_name"; // Table name1
$tbl_name2="tbl_name2"; // Table name2

// Connect to server and select databse.
mysql_connect("$host", "$db_username", "$db_password")or die(mysql_error());
mysql_select_db("$db_name")or die(mysql_error());
?>


<?php get_header(); ?>

<div id="content" class="narrowcolumn">

<h2>Assignments</h2>
Self Given Growth Assignments
	<div class="entry">
	The photographer has developed a list of self-given assignments to help push, stretch, and make him grow.  By selecting from the options below, you may view some of his progress as a photographer!
	</div>
	<div>
	<form method="post">
	<table>
	<tr>
	<th>Category</th><th> </th><th> </th><th> </th>
	</tr>
		<?
		$ass_cat = mysql_query("SELECT * FROM `$tbl_name2`") or die(mysql_error());
		?>
	<tr>
	<td><select name="category" style="width:300px;">
		<option>Select a Category!</option>
		<? while($row=mysql_fetch_array($ass_cat)){?>
            	<option value=<?=$row['cat']?>><?=$row['cat']?></option>
            <? } ?>
	</select></td>
	<td><input type=submit name="submit" value="Go!" /></td>
        <td>OR</td>
        <td><input type=submit name="submit" value="See All Completed Assignments" /></td>
	</tr>
	</table>		
	</form>
	</div>

	<div>
		<?
		if ($_POST['submit']=="Go!")
		{
			$category = $_POST['category'];
			$ass_data = mysql_query("SELECT * FROM `$tbl_name` WHERE `cat` = '$category'") or die(mysql_error());

			Print "<table border=0 cellpadding=3 width=650>";
			Print "<tr>";
			Print "<th width=50>Title</th> <th width=200>Description</th> <th width=175>Photographer Comments</th> <th width=100>Thumbnail</th> <th width=125>Data</th></tr>";
			while($info = mysql_fetch_array( $ass_data ))
			{
			Print "<tr>";
			Print "<td valign='top'>".$info['title'] . "</td> ";
			Print "<td valign='top'>".$info['desc'] . "</td> ";
			Print "<td valign='top'>".$info['comm'] . "</td>";
			Print "<td valign='top'>".$info['img_thmb'] . "</td>";
			Print "<td valign='top'>Date: ".$info['date']."<br>Exposure: ".$info['exp']."<br>Aperture: ".$info['app']."<br>Focal Length: ".$info['focl']."<br>ISO: ".$info['iso']."</td>";
			}
			Print "</table>"; 
		}
		elseif ($_POST['submit']=="See All Completed Assignments")
		{
			$ass_cmplt = mysql_query("SELECT * FROM `$tbl_name` WHERE `cmplt` = 'TRUE'") or die(mysql_error());

			Print "<table border=0 cellpadding=3 width=650>";
			Print "<tr>";
			Print "<th width=50>Title</th> <th width=200>Description</th> <th width=175>Photographer Comments</th> <th width=100>Thumbnail</th> <th width=125>Data</th></tr>";
			while($info = mysql_fetch_array( $ass_cmplt ))
			{
			Print "<tr>";
			Print "<td valign='top'>".$info['title'] . "</td> ";
			Print "<td valign='top'>".$info['desc'] . "</td> ";
			Print "<td valign='top'>".$info['comm'] . "</td>";
			Print "<td valign='top'>".$info['img_thmb'] . "</td>";
			Print "<td valign='top'>Date: ".$info['date']."<br>Exposure: ".$info['exp']."<br>Aperture: ".$info['app']."<br>Focal Length: ".$info['focl']."<br>ISO: ".$info['iso']."</td>";
			}
			Print "</table>"; 

		}
		else {
    			die(mysql_error());
		}
		?>
	</div>

</div>
    
<?php get_sidebar(); ?>

<?php get_footer(); ?>

Link to comment
https://forums.phpfreaks.com/topic/147125-form-script-help/
Share on other sites

your problem is this :

 

else {

            die(mysql_error());

        }

 

When you first load a page, there's no $_POST['submit'] being set.  so that line will kill your script from continuing and your sidebar and footer won't get a chance to load.

 

You can change that like to :

 

elseif (isset($_POST['submit'])) {

            die(mysql_error());

        }

Link to comment
https://forums.phpfreaks.com/topic/147125-form-script-help/#findComment-772406
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.