Ok, sorry for the mixup. I think I need to further clarify what I'm wanting to do.
Below is the main page in index.php
The Header.php and Footer.php files contain the html wrapping around the PHP code. (you'll see i still need improvement in some ways but I'm learning. 😉 )
<?PHP
include ("functions.php");
// the Default function.
//note for functions: if you want to include a value of some variables inside the funtions,
//then you have to GLOBAL it first.
function index($user) {
global $db, $prefix;
//check if the user is logged in or not.
if (is_logged_in($user)) {
include("header.php");
$cookie_read = explode("|", base64_decode($user));
//define variables to hold cookie values.
global $userid;
$userid = $cookie_read[0];
$username = $cookie_read[1];
$password = $cookie_read[2];
$ipaddress = $cookie_read[3];
$lastlogin_date = $cookie_read[4];
$lastlogin_time = $cookie_read[5];
if($ipaddress == "") $ipaddress = ""._NOT_YET."";
//print wilcome message
echo "<h3>"._WELCOME." <b>$username</b>!</h3>";
echo "<p>Here are the most recent additions to the public listings:</p>";
$searchstring = "WHERE `account` != '0'";
$table = "listings";
$order = "1";
$pagination = pagination($table, $order, $searchstring, $pre, $pos, $nav, $page, $pages);
$navigation = $pagination[0];
$result = $pagination[1];
$num = $pagination[2];
// echo"$navigation";
echo "<table class=\"hover\">";
echo "<tr>";
echo "<th>Contact</th><th>Last Years Percent</th><th>Location</th><th>Amount</th></tr>";
for($i; $i < mysql_num_rows($result); $i++)
{
$row = mysql_fetch_array($result);
echo ($i % 2 == 0) ? '<tr>' : '<tr class="altrow">' . "\n";
echo "<td>"; echo $row['ContactFirst']; echo " "; echo $row['ContactLast']; echo "</td>";
echo "<td>"; echo $row['LastYearsPercent']; echo "</td>";
echo "<td>"; echo $row['City']; echo ", "; echo $row['State']; echo "</td>";
echo "<td>"; echo $row['Amount']; echo "</td>";
}
echo "</table>";
navigation_menu();
include("footer.php");
}else{
//if the user is not logged in then show the login form.
// header("Location: users.php?a=Login"); die();
include("header.php");
$login_needed = 1;
include("footer.php");
}
}
index($user);
?>
Now I want to take the value from $userid; and put it into this function that will insert it into the database:
function do_AddListing(){
include("header.php");
$ContactFirst = $_POST['ContactFirst'];
$ContactLast = $_POST['ContactLast'];
$Email = $_POST['Email'];
$Phone = $_POST['Phone'];
$Comments = $_POST['Comments'];
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("oillisting") or die(mysql_error());
mysql_query("INSERT INTO `listings` VALUES ('', '$userid', '$ContactFirst', '$ContactLast', '$Email', '$Phone', '$Comments')") or die("No Worky");
echo "Success!";
include("footer.php");
}
So using the code of
index($user);
echo $userid;
Isn't good because it calls another entire page. What else can I do or would anyone suggest some modifications to my code? Thanks! Yall have been a great help already!