Hi:
I have tried to make this work, but it just refuses to. I tried using files and then database to store/retrieve the 'both' data, but got identical results, indicating it must be the logic, since nothing appears as a syntax error. Both file and database functions worked perfectly. I kept the database method.
There seems to be something wrong with the two 'if's, since the 'echo's immediately after the 'if's don't execute:
if ($page == "Visitor Home PLUS Client My Home") // if home
if ($page == "Visitor Gifts PLUS Client Offers & Hot Buys") // if gifts, etc.
These 'if's works:
if ($bothread == "yes") // if double-page article
if ($bothread == "no")
PHP: 4.3.10
MySQL: 3.23.58
apache server: 1.3.33
Here's the script ..
<?php
function db_connect()
{
$db = mysql_pconnect(".......");
mysql_select_db(".....",$db);
$query = "select checkno from db_connect where name='a'";
$result = mysql_query($query,$db);
if (!$result)
return false;
// else ..
$myrow_checkno = mysql_fetch_array($result);
$checkno = $myrow_checkno['checkno'];
if ($checkno == '1') return $db; // true
if ($checkno != '1') return false;
}
function both_write($both_pages)
// set the value of both pages to either 'yes' if two pages, or 'no' if only one page
{
if (!($conn = db_connect()))
{
return false;
}
else
{
$result = mysql_query("update NB_Both set both_pages ='$both_pages'");
if (!$result)
{
return false;
}
return $both_pages;
}
}
function both_read()
// reads the value of both pages: either 'yes' if two pages, or 'no' if only one page
{
if (!($conn = db_connect()))
{
return false;
}
else
{
$result = mysql_query("select both_pages from NB_Both");
if (!$result)
{
return false;
}
$both_pages = mysql_result($result, 0, 'both_pages');
return $both_pages;
}
}
$conn = db_connect();
if (!$conn)
echo 'Could not connect to database server - please try later.';
// check if articleID is unique
$result = mysql_query("select * from NB_Articles where articleID='$articleID'");
if (!$result)
{
echo 'Could not execute query';
exit;
}
if (mysql_num_rows($result)>0)
{
echo 'That articleID already exists, and this is an edited article to be saved.';
// edited article, therefore update data into table ##### STILL TO DO THIS ######
}
else
{
// find value of $both_pages from table in database
$bothread = both_read();
echo "bothread = ",$bothread,"<BR />";
echo "page = ",$page,"<BR />"; // $page ESTABLISHED IN PREVIOUS SCRIPTING
// BOTH $page AND $bothread SHOW AS ACCURATE
// insert new article data into NB_Article table
$result = mysql_query("insert into NB_Articles (articleID, heading, picture, article, start_date, stop_date) values ('$articleID', '$heading', '$picture', '$article', '$start_article', '$stop_article')"); // THIS INSERTS THE DATA CORRECTLY
if (!$result)
{
echo 'We could not insert data into the NB_Article table.';
exit;
}
// insert new article data into NB_Page_Articles table
if ($bothread == "yes") // if double-page article
{
// GET IN HERE OK
if ($page == "Visitor Home PLUS Client My Home") // if home
{
// CAN'T GET IN HERE! #############################
echo "Both + Home";
// insert new article data into NB_Page_Articles table
$result = mysql_query("insert into NB_Page_Articles values
('Visitor Home', '$articleID'),
('Client My Home', '$articleID')
");
if (!$result)
{
echo 'We could not insert data into the NB_Page_Articles table.';
exit;
}
}
if ($page == "Visitor Gifts PLUS Client Offers & Hot Buys") // if gifts, etc.
{
// CAN'T GET IN HERE EITHER ######################
echo "Both + Gifts-HotBuys";
// insert new article data into NB_Page_Articles table
$result = mysql_query("insert into NB_Page_Articles values
('Visitor Gifts', '$articleID'),
('Client Offers & Hot Buys', '$articleID')
");
if (!$result)
{
echo 'We could not insert data into the NB_Page_Articles table.';
exit;
}
}
}
if ($bothread == "no")
{
// GET IN HERE OK
echo "Not both";
// insert new article data into NB_Page_Articles table
$result = mysql_query("insert into NB_Page_Articles values
('$page', '$articleID')
");
if (!$result)
{
echo 'We could not insert data into the NB_Page_Articles table.';
exit;
}
}
}
?>