i have used this script w/ success many times already in my app. it basically goes like this. i'm sure you've seen it-- either from me, or in your own travelings:
please let's assume all other supporting code is present and w/out error. okay. here's goes:
my if statement to start it off
if ($_POST['op'] != "Do_it!") {
then all of my html is built and entered into a concatenated $variable, including <select><option> pull-downs populated by way of WHILE arrays calling data from a table w/ mysql_query()'s, then when the form is complete w/ the final, hidden value being "Do_it!", the code jumps down, skipping this, cause it's NOT 'true' yet:
} else { if ($_POST['op'] == "Do_it!") {
and printing the form to the screen by way of a little HTML block after ending the PHP script which has built the Form from the While Arrays and the table data. so now the Form is then submitted by the user, thereby sending the $_POST data, including the hidden field "Do_it!" back to itself by way of
<form method=\"post\" action=\"$_SERVER[PHP_SELF]\">
so that THIS TIME, the IF / ELSE logic will see the $_POST['op'] == "Do_it!" as true, and proceed to the final, previously skipped block of PHP where the data is then entered into the table via INSERT SQL.
i have used this script many times w/ success. now, i'm trying it again, and for whatever reason, i keep getting NO VALUE in my $variable, such that there is NO FORM output to the screen. i can't see what's wrong!
here's my specifc code. i posted elsewhere this same code, so please forgive me, but this time, i wanted to provide a more thorough explanation of why i am so flabbergasted here. thanks for your patience. note, i've modifed the original { if ($_POST['op'] != "Do_it!") } to use an { isset } so that i don't get a Notice: undefined variable 'op' error. you may also notice that i've added a test which proves that indeed my IF ELSE is failing. i DO get output since adding that piece which shows:
OMG false!
<?php
$conn = mysql_connect("localhost", "private", "private") or die(mysql_error());
mysql_select_db("cb_shows1", $conn) or die(mysql_error());
// MAKE DB CONNECTION
if (isset ($_post['op']) and ($_POST['op'] != "doit")) {
// BEGIN IF 'OP NOT EQUAL TO DO_IT' LOGIC
// BEGIN MAKING HTML BLOCK
$outputhtml = "<h1>Associate Contact with Artist info</h1>
<p>Use the pull-downs to match Contact person
to the appropriate Artist</p>
<form method=\"post\" action=\"$_SERVER[PHP_SELF]\">
<p><select name=\"contact_id\">
<option value=\"\">-- Contact Name --</option>";
// QUERY FOR CONCTACT ID AND NAME
$contQuery = "select contact_id, contact_name from contact_info";
$contShow = mysql_query($contQuery) or die(mysql_error());
while ($contArray = mysql_fetch_array($contShow) or die(mysql_error()) ) {
// START WHILE LOOP ONE
$contId = $contArray[0];
$contName = $contArray[1];
$outputhtml .= "<option value=\"$contId\">$contName</option>";
}
// END WHILE LOOP ONE
$outputhtml .= "</select></p>";
// QUERY FOR ARTIST ID AND NAME
$artQuery = "select artist_id, artist_name from artist_info";
$artShow = mysql_query($artQuery);
$outputhtml .= "<p>Use this pull-down to match an Artist
with the Contact selected above</p>
<p><select name=\"artist_id\">
<option value=\"\">-- Artist Name --</option>";
while ($artArray = mysql_fetch_array($artShow) or die(mysql_error()) ) {
// START WHILE LOOP TWO
$artId = $artArray['artist_id'];
$artName = $artArray['artist_name'];
$outputhtml .= "<option value=\"$artId\">$artName</option>";
}
// END WHILE LOOP TWO
// MORE HTML VARIABLE CONCAT
$outputhtml .= "</select></p>";
$outputhtml .= "<p>When you are finished making your selections
simply hit the button below, and your selections will
be associated properly for future reference</p>
<p>
<input type=\"submit\" name=\"submit\"
value\"Assciate Contact & Artist Now\" /></p>
<p><input type=\"hidden\" name=\"op\" value=\"doit\" /></p>
</form>";
}
// IF LOGIC PART TWO SHOULD ACTIVATE UPDATE QUERY AND ASSOCIATE ARTIST AND CONTACT
else if (isset($_POST['op']) and ($_POST['op'] != "doit")) {
// SQL -UPDATE ROW- FOR CHANGING ARTIST AND CONTACT ASSOCIATION
$assQuery = "UPDATE artist_info SET contact_id='$_POST[contact_id]'WHERE artist_id='$_POST[artist_id]'";
$contInfo = "select contact_name from contact_info where contact_id='$_POST[contact_id]'";
$artInfo = "select artist_name from artist_info where artist_id='$_POST[artist_id]'";
// PUT MYSQL QUERY RESULTS INTO ARRAYS
$assup = mysql_query($assQuery) or die(mysql_error());
$contRes = mysql_query($contInfo) or die(mysql_error());
$artRes = mysql_query($artInfo) or die(mysql_error());
// PULL NAMES FROM MYSQL RESULTS
$contEntered = $contRes['contact_name'];
$artEntered = $artRes['artist_name'];
// PUT CHANGED INFO INTO NEW HTML BLOCK - SECOND TIME AROUND
$outputhtml = "<h1>Success!</h1>
<h2>Results:</h2>
<p> ".$artEntered."is now associated with
".$contEntered." as their Contact</p>
<p>Click here to
<a href=\"associate.php\">change more
</a> Artist / Contact associations</p>
<p>or go <a href=\"control.htm\">back to the main</a> control</p>";
}// END IF LOGIC PART TWO
else { echo "OMG false!"; }
?>
<html>
<head>
<title>Change Associated Contacts and Artists</title>
<link rel="STYLESHEET" type="text/css" href="css/php.css">
</head>
<body>
<p>Results</p>
<?php
echo "<p>".$outputhtml."</p>"; ?>
</body>
</html>
thanks for reading. i wouldn't bother w/ this again, but i've been struggling over this script all day and since last night. what the heck is going on here?