For some reason I get bumped back to the first validation condtion (Please provide an Abbridged Lead Body that is at least 140 characters) even though this condition has originally been met when I should be able to make it to the last section:
I have a feeling it has something to do with passing a hidden form field or something, but I've been slaving away over this one stupid page for 4 days so I'm despairing here.....Much thanks to any suggestions!
Abbreviated Code:
<?php
if (strlen($HTTP_POST_VARS['LeadHomeBody']) < 140)
{
echo '<p class="backend">Please provide an Abbridged Lead Body that is at least 140 characters.<br /><center><a href="insertnews.php">Go Back</a></center></p>';
exit;
}
elseif (strlen($HTTP_POST_VARS['LeadHomeBody']) > 200)
{
echo '<p class="backend">Please provide an Abbridged Lead Body that is no more than 200 characters.
<br /><center><a href="insertnews.php">Go Back</a></center></p>';
exit;
}
elseif (strlen($HTTP_POST_VARS['LeadHomeHead']) > 60)
{
echo '<p class="backend">Please provide an Abbridged Lead Headline that is no more than 60 characters.<br /><center><a href="insertnews.php">Go Back</a></center></p>';
exit;
}
elseif (strlen($HTTP_POST_VARS['LeadHomeBody']) >= 140 && strlen($HTTP_POST_VARS['LeadHomeBody']) <= 200 && strlen($HTTP_POST_VARS['LeadHomeHead']) <= 60)
{
@ $db = mysql_pconnect('localhost', 'user', 'pass');
if (!$db)
{
echo 'Could not connect to the database. Try again later.';
exit;
}
$select=mysql_select_db("db");
if (!$select)
{
print "ERROR: " . mysql_error() . "\n";
}
mysql_query ("INSERT INTO news (HomeHead, HomeBody, Headline, Body, Live, DatePosted)VALUES ('$HTTP_POST_VARS[LeadHomeHead]', '$HTTP_POST_VARS[LeadHomeBody]', '$HTTP_POST_VARS[LeadHeadline]','$HTTP_POST_VARS[LeadBody]', 'no', now())");
$LeadHomeHead=$HTTP_POST_VARS['LeadHomeHead'];
?>
<form method="post" action="<?php echo $PHP_SELF ?>">
<?php
if (!$LeadGoLive)
{
$LeadHomeHead=$HTTP_POST_VARS['LeadHomeHead'];
@ $db = mysql_pconnect('localhost', 'user', 'pass');
if (!$db)
{
echo 'Could not connect to the database. Try again later.';
exit;
}
$select=mysql_select_db("db");
if (!$select)
{
print "ERROR: " . mysql_error() . "\n";
}
$query = mysql_query("SELECT * FROM news WHERE HomeHead='$HTTP_POST_VARS[LeadHomeHead]'");
$num_results = mysql_num_rows($query) or die(mysql_error());
?>
<p class="backend"><center><a href="preview.php" target="_blank">Preview news item.</a><br /><br />Make live? <input type="checkbox" name="LeadLive" value="yes">Yes <input type="checkbox" name="LeadLive" value="no">No<br /><br />
<input type="submit" name="LeadGoLive" value="Submit">
</center></p>
<?php
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($query);
echo '<input type="hidden" name="HomeHead" value="'.stripslashes($row['HomeHead']).'"><br />
<input type="hidden" name="HomeBody" value="'.stripslashes($row['HomeBody']).'"><br />
<input type="hidden" name="Headline" value="'.stripslashes($row['Headline']).'"><br />
<input type="hidden" name="Body" value="'.stripslashes($row['Body']).'"><br />';
}
}
if ($LeadGoLive)
{
$HomeHead=$HTTP_POST_VARS['HomeHead'];
$HomeBody=$HTTP_POST_VARS['HomeBody'];
$Headline=$HTTP_POST_VARS['Headline'];
$Body=$HTTP_POST_VARS['Body'];
if ($LeadLive=='yes')
{
$HomeHead=$HTTP_POST_VARS['HomeHead'];
$HomeBody=$HTTP_POST_VARS['HomeBody'];
$Headline=$HTTP_POST_VARS['Headline'];
$Body=$HTTP_POST_VARS['Body'];
?>
<input type="hidden" name="LeadGoLive" value="Submit">
<input type="hidden" name="LeadLive" value="yes">
<?php
@ $db = mysql_pconnect('localhost', 'user', 'pass');
if (!$db)
{
echo 'Could not connect to the database. Try again later.';
exit;
}
$select=mysql_select_db("db");
if (!$select)
{
print "ERROR: " . mysql_error() . "\n";
}
$query = "SELECT * FROM live WHERE Position='lead'";
if ($query)
{
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
$OldHomeHead=$row['HomeHead'];
mysql_query ("UPDATE news SET Live='no' WHERE HomeHead=$OldHomeHead LIMIT 1");
mysql_query ("DELETE FROM live WHERE HomeHead=$HomeHead LIMIT 1");
}
}
@ $db = mysql_pconnect('localhost', 'user', 'pass');
if (!$db)
{
echo 'Could not connect to the database. Try again later.';
exit;
}
$select=mysql_select_db("db");
if (!$select)
{
print "ERROR: " . mysql_error() . "\n";
}
mysql_query ("UPDATE news SET Live='yes' WHERE HomeHead='$HTTP_POST_VARS[HomeHead]' LIMIT 1");
mysql_query ("INSERT INTO live (Position, HomeHead, HomeBody, Headline, Body, Live, DatePosted)VALUES ('Lead', $HomeHead, $HomeBody, $Headline, $Body, 'yes', now())");
echo '<p class="backend"><center>Your news item has been posted and is live.<br /><br />
<a href="insertnews.php">Enter another news item.</a><br />
<a href="inserttestimonial.php">Enter a testimonial item.</a><br />
<a href="managenews.php">Manage news items.</a><br />
<a href="managetestimonials.php">Manage testimonial items.</a><br />
</center></p>';
}
if ($LeadLive=='no')
{
echo '<p class="backend"><center>Your news item has been posted and is not live.<br /><br />
<a href="insertnews.php">Enter another news item.</a><br />
<a href="inserttestimonial.php">Enter a testimonial item.</a><br />
<a href="managenews.php">Manage news items.</a><br />
<a href="managetestimonials.php">Manage testimonial items.</a><br />
</center></p>';
?>
<input type="hidden" name="LeadLive" value="no">
<input type="hidden" name="LeadGoLive" value="Submit">
<?php
}
}
?>
</form>
<?php
}
}