For some reason when I insert a record, it adds a blank row into the database as well. Here's the code, and thanks!
@ $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())");
?>
<form method="post" action="<?php echo $PHP_SELF ?>">
<?php
if (!$LeadGoLive)
{
?>
<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
}
if ($LeadGoLive)
{
if ($LeadLive=='yes')
{
?>
<input type="hidden" name="LeadGoLive" value="Submit">
<input type="hidden" name="LeadLive" value="yes">
<?php
@ $db = mysql_pconnect('localhost', 'esbsolu_esbsolu', 'armagita');
if (!$db)
{
echo 'Could not connect to the database. Try again later.';
exit;
}
$select=mysql_select_db("esbsolu_boston");
if (!$select)
{
print "ERROR: " . mysql_error() . "\n";
}
$query = "SELECT * FROM live WHERE Position='lead'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
if ($num_results=1)
{
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
$OldHomeHead=$row['HomeHead'];
}
@ $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='no' WHERE HomeHead=$OldHomeHead LIMIT 1");
mysql_query ("DELETE FROM live WHERE HomeHead=$OldHomeHead 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_SESSION_VARS[NewHomeHead]' 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");
$query = mysql_query("SELECT * FROM news WHERE HomeHead='$HTTP_SESSION_VARS[NewHomeHead]'") or die(mysql_error());
$num_results = mysql_num_rows($query) or die(mysql_error());
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($query);
$HomeHead=$row['HomeHead'];
$HomeBody=$row['HomeBody'];
$Headline=$row['Headline'];
$Body=$row['Body'];
@ $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 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>';
exit;
}
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>';
exit;
}
}
?>
</form>
<?php
}