Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP not sending variables

Status
Not open for further replies.

rninja

Technical User
Apr 11, 2001
381
0
0
US
The script I've got is not sending variables to embeded proceedures. I don't know why it is no longer working. I have a feeling it is due to changes in PHP syntax.

When I click on one of the options from the database, it stays on the same page and doesn't move on to the link page. The link string however goes show up in the browser, but that's it.

Thanks in advance if you can let me know what needs to be fixed or changed!

HERE IS THE CODE:

<?php
include (&quot;conf.php&quot;);
include (&quot;func_set.php&quot;);

if ( isset($qid) ) {
// Display question and answer
connex();
if ($topmenu == 1 and isset($catid))
whereareu($catid);
elseif (isset($frommosrec) )
print &quot;<p align=\&quot;center\&quot;><a href=\&quot;$faqindex\&quot;>Home</a> > Most Recent Questions</p>&quot;;
elseif (isset($frommospop))
print &quot;<p align=\&quot;center\&quot;><a href=\&quot;$faqindex\&quot;>Home</a> > Most Popular Questions</p>&quot;;
else
print &quot;<p align=\&quot;center\&quot;><a href=\&quot;$faqindex\&quot;>Home</a> > <a href=\&quot;$faqindex?runsearch=start\&quot;>Search FAQ</a></p>&quot;;

$query = &quot;Select question, answer, viewed FROM faq_qandas WHERE qid = $qid&quot;;
$qinfo = mysql_query( $query, $link ) or die(&quot;Error pulling subcat list from database: &quot;.mysql_error());
$question = mysql_fetch_array( $qinfo );

// Strip slashes, then change hard returns to <BR> and spaces to &nbsp; if there are no <BR> or paragraph tags already in place
$thisquestion = $question[question];
if (substr_count($thisquestion, &quot;<p&quot;) == 0 && substr_count($thisquestion, &quot;<BR>&quot;) == 0)
$thisquestion = nl2br($thisquestion);
$thisquestion = str_replace(&quot; &quot;, &quot;&nbsp;&nbsp;&quot;, $thisquestion);
$thisquestion = stripslashes($thisquestion);

$thisanswer = $question[answer];
if (substr_count($thisanswer, &quot;<p&quot;) == 0 && substr_count($thisanswer, &quot;<BR>&quot;) == 0 && substr_count($thisanswer, &quot;<ul&quot;) == 0)
$thisanswer = nl2br($thisanswer);
$thisanswer = str_replace(&quot; &quot;, &quot;&nbsp;&nbsp;&quot;, $thisanswer);
$thisanswer = stripslashes($thisanswer);

print &quot;<P><strong>$thisquestion</strong></P>&quot;;
print &quot;<blockquote>$thisanswer</blockquote>&quot;;

$newview = $question[viewed] + 1;
$query = &quot;UPDATE faq_qandas SET viewed = $newview WHERE qid = $qid&quot;;
$qinfo = mysql_query( $query, $link ) or die(&quot;Error updating view count: &quot;.mysql_error());

footerlinks();
}

elseif ( isset($submitq) ) { // Question submission page
// check for form submission. If none, show form
if (!isset($question)) {
// include (&quot;header.php&quot;);
connex();
if ($topmenu == 1 and isset($catid))
whereareu($catid);
else
print &quot;<p align=\&quot;center\&quot;><a href=\&quot;$faqindex\&quot;>Home</a> > <a href=\&quot;$faqindex?submitq=yes\&quot;>Submit New Question</a></p>&quot;;

$submitterip = $REMOTE_ADDR;

print &quot;
<p align=\&quot;center\&quot;><strong>Submit New Question</strong></p>
<form name=\&quot;form1\&quot; method=\&quot;post\&quot; action=\&quot;$_SERVER[PHP_SELF]?page=questions\&quot;>
<input type=\&quot;hidden\&quot; name=\&quot;submitq\&quot; value=\&quot;yes\&quot;>
<table width=\&quot;500\&quot; border=\&quot;0\&quot; cellspacing=\&quot;0\&quot; cellpadding=\&quot;5\&quot; align=\&quot;center\&quot;>
<tr valign=\&quot;top\&quot;>
<td><b>New Question<BR>(maximum length 255)</b></td>
<td>
<textarea name=\&quot;question\&quot; rows=\&quot;3\&quot; cols=\&quot;30\&quot; onkeyup=\&quot;this.value = this.value.slice(0, 255)\&quot;></textarea>
</td>
</tr>
<tr valign=\&quot;top\&quot;>
<td><b>Your Name</b></td>
<td>
<input type=\&quot;text\&quot; name=\&quot;submittername\&quot; size=\&quot;30\&quot; maxlength=\&quot;100\&quot;>
</td>
</tr>
<tr valign=\&quot;top\&quot;>
<td><b>Your Email (not required)</b></td>
<td>
<input type=\&quot;text\&quot; name=\&quot;submitteremail\&quot; size=\&quot;30\&quot; maxlength=\&quot;255\&quot;>
</td>
</tr>
<tr valign=\&quot;top\&quot;>
<td><b>Your IP (recorded for security)</b></td>
<td>$submitterip<input type=\&quot;hidden\&quot; name=\&quot;submitterip\&quot; size=\&quot;30\&quot; maxlength=\&quot;255\&quot; value=\&quot;$submitterip\&quot;></td>
</tr>
<tr valign=\&quot;top\&quot;>
<td><b>Suggested Category</b></td>
<td>
<select name=\&quot;catid\&quot; size=\&quot;5\&quot;>&quot;;
// For questions being edited, pull the list of currently assigned cats
if (isset($catid)) {
$assignedlist[] = $catid;
}
// otherwise set the assigned cat equal to the category being worked in
else
$assignedlist[] = &quot;&quot;;

$maincats = &quot;Select catid, cat FROM faq_cats WHERE maincat = 0 ORDER BY cat&quot;;
$cats = mysql_query( $maincats, $link ) or die(&quot;Error pulling main category list from database: &quot;.mysql_error());

while ($maincatlist = mysql_fetch_array( $cats )) {
if ( in_array( &quot;$maincatlist[catid]&quot;, $assignedlist) )
print &quot;<option value=\&quot;$maincatlist[catid]\&quot; selected>$maincatlist[cat]</option>&quot;;
else
print &quot;<option value=\&quot;$maincatlist[catid]\&quot;>$maincatlist[cat]</option>&quot;;

subcats_qoption($maincatlist[catid], &quot;$maincat&quot;, 2, $assignedlist);
}

print &quot;
</select>
</td>
</tr>
<tr valign=\&quot;top\&quot;>
<td colspan=\&quot;2\&quot; align=\&quot;center\&quot;><input type=\&quot;submit\&quot; name=\&quot;Submit\&quot; value=\&quot;Submit\&quot;></td>
</tr>
</table>
</form>
&quot;;
footerlinks();
}
else {
if ($question == &quot;&quot;)
die(&quot;You must enter a question to add to the database!&quot;);
if ($submittername == &quot;&quot;)
die(&quot;You must enter your name in order to submit a question to the database!&quot;);

// if question and name have been entered, call add function
usersubmittedquestion($question, $submittername, $submitteremail, $submitterip, $catid);

// include (&quot;header.php&quot;);
print &quot;<p align=\&quot;center\&quot;><strong>$result</strong></p>&quot;;
footerlinks();
}
}

elseif ( isset($catid) ) {
connex();

if ($topmenu == 1)
whereareu($catid);

$query = &quot;SELECT catid, cat, description
FROM faq_cats
WHERE maincat = $catid
ORDER BY cat&quot;;
$subcatlist = mysql_query( $query, $link ) or die(&quot;Error pulling subcat list from database: &quot;.mysql_error());
$num_rows = mysql_num_rows( $subcatlist );

if ($num_rows > 0) {
print &quot;<dl>&quot;;
while ($subcats = mysql_fetch_array( $subcatlist )) {
$cat = stripslashes($subcats[cat]);
print &quot;<dt><a href=\&quot;$faqindex?catid=$subcats[catid]\&quot;><strong>$cat</strong>&quot;;
if ($showcounts == 1) {
$query = &quot;SELECT DISTINCT qid
FROM faq_whichcats INNER JOIN faq_cats ON faq_whichcats.catid = faq_cats.catid
WHERE maincat = $subcats[catid]
OR faq_whichcats.catid = $subcats[catid]&quot;;
$qlist = mysql_query( $query, $link ) or die(&quot;Error pulling question counts from database: &quot;.mysql_error());
$qcount = mysql_num_rows( $qlist );
print &quot; ($qcount)&quot;;
}
print &quot;</a></dt>&quot;;
if ($usedescripts == 1) {
$catdescription = stripslashes($subcats[description]);
print &quot;<dd>$catdescription</dd>&quot;;
}
}
print &quot;</dl>&quot;;
}

// Show question list, if any are available
$query = &quot;SELECT faq_qandas.qid, question
FROM faq_qandas INNER JOIN faq_whichcats ON faq_qandas.qid = faq_whichcats.qid
WHERE catid = $catid
ORDER BY question&quot;;
$qlist = mysql_query( $query, $link ) or die(&quot;Error pulling question list from database: &quot;.mysql_error());
$num_rows = mysql_num_rows( $qlist );

if ($num_rows == 0)
print &quot;<p align=\&quot;center\&quot;>There are no questions listed in this category</p>&quot;;
else {
print &quot;<p>&nbsp;</p>&quot;;
if ($num_rows == 1)
print &quot;<p>There is $num_rows question available in this category.</p>&quot;;
else
print &quot;<p>There are $num_rows questions available in this category.</p>&quot;;
print &quot;<ul>&quot;;
while ($questions = mysql_fetch_array( $qlist )) {
$question = stripslashes($questions[question]);
print &quot;<li> &nbsp; <a href=\&quot;$faqindex?qid=$questions[qid]&catid=$catid\&quot;>$question</a></li>&quot;;
}
print &quot;</ul>&quot;;
}

footerlinks();
}

elseif ( isset($runsearch) ) {
if ($runsearch == &quot;yes&quot;) { $searchterms = escapeshellcmd($searchterms);
processsearch($searchterms,$limitcat);
}
else {
connex();
print &quot;
<h4 align=\&quot;center\&quot;>Search $faqname</h4>

<form name=\&quot;form1\&quot; method=\&quot;post\&quot; action=\&quot;$_SERVER[PHP_SELF]\&quot;>
<input type=\&quot;hidden\&quot; name=\&quot;runsearch\&quot; value=\&quot;yes\&quot;>
<table width=\&quot;500\&quot; border=\&quot;0\&quot; align=\&quot;center\&quot; cellpadding=\&quot;4\&quot; cellspacing=\&quot;0\&quot;>
<tr align=\&quot;left\&quot; valign=\&quot;top\&quot;>
<td nowrap><p><strong>Enter Search Terms</strong></p></td>
<td><input name=\&quot;searchterms\&quot; type=\&quot;text\&quot; id=\&quot;searchterms\&quot; size=\&quot;30\&quot; maxlength=\&quot;100\&quot;></td>
</tr>
<tr align=\&quot;left\&quot; valign=\&quot;top\&quot;>
<td nowrap><strong>Limit to a specific category?</strong></td>
<td>
<select name=\&quot;limitcat\&quot;>
<option value=\&quot;\&quot;>-- Search All Categories --</option>
&quot;;

$maincats = &quot;Select catid, cat FROM faq_cats WHERE maincat = 0 ORDER BY cat&quot;;
$cats = mysql_query( $maincats, $link ) or die(&quot;Error pulling category list from database: &quot;.mysql_error());

while ($maincatlist = mysql_fetch_array( $cats )) {
$cat = stripslashes($maincatlist[cat]);
if ($maincatlist[catid] == $maincat)
print &quot;<option value=\&quot;$maincatlist[catid]\&quot; selected>$cat</option>&quot;;
else
print &quot;<option value=\&quot;$maincatlist[catid]\&quot;>$cat</option>&quot;;

subcats_option(&quot;$maincatlist[catid]&quot;, &quot;$maincat&quot;, 2);
}

print &quot;
</select>
</td>
</tr>
<tr>
<td colspan=\&quot;2\&quot; align=\&quot;center\&quot; valign=\&quot;top\&quot;>
<input name=\&quot;Submit\&quot; type=\&quot;submit\&quot; id=\&quot;Submit\&quot; value=\&quot;Run My Search\&quot;>
</td>
</tr>
</table>
</form>
&quot;;
}
footerlinks();
}

else { // Display entry page
$isindex = &quot;Yes&quot;;

if (($mospop == 1 && $anypop == &quot;yes&quot;) || $mosrec == 1)
print &quot;<p style=\&quot;font-family:arial;font-size:9pt;border:#A0A0A0 1px
solid;background-color:#D0D0D0;font-weight:bold;\&quot;>&nbsp;&nbsp; Frequently Asked
Questions</p>&quot;;

print &quot;<dl>&quot;;

connectToDB();
$query = &quot;SELECT catid, cat, description
FROM faq_cats
WHERE maincat = 0
ORDER BY cat&quot;;
$catlist = mysql_query( $query, $link ) or die(&quot;Error pulling cat list from database: &quot;.mysql_error());
while ($cat = mysql_fetch_array( $catlist )) {
$thiscat = stripslashes($cat[cat]);
print &quot;<dt><a href=\&quot;$faqindex?catid=$cat[catid]\&quot;>$thiscat&quot;;
if ($showcounts == 1) {
$query = &quot;SELECT DISTINCT qid
FROM faq_whichcats INNER JOIN faq_cats ON faq_whichcats.catid = faq_cats.catid
WHERE maincat = $cat[catid]
OR faq_whichcats.catid = $cat[catid]&quot;;
$qlist = mysql_query( $query, $link ) or die(&quot;Error pulling question counts from database: &quot;.mysql_error());
$qcount = mysql_num_rows( $qlist );
print &quot; ($qcount)&quot;;
}
print &quot;</a></dt>&quot;;
if ($usedescripts == 1) {
$catdescription = stripslashes($cat[description]);
print &quot;<dd>$catdescription</dd>&quot;;
}
}

print &quot;</dl>&quot;;

footerlinks();
}

?>


Rninja

smlogo.gif

 
I've not read all the lines :), but...

If the page was working before and not now, have you changed the register_globals option in your php.ini file ?
A common error (for me) was to have php program wrote with register_globals = yes, not working anymore when php 4 (in release 4.2 i think) put as standard register_globals = off.

Hope this can help

Riccardo

Try an open source Tsm report Tool:

 
Rninja, let me add a little aid to Riccardo's: to be sure your source will work fine on most servers (and expecially if you cant change php settings!) than, when you post variables from a form, you should recall them (in the form action file) with the array $_POST[] because, if register_globals is set to &quot;off&quot;, then the variables are not passed &quot;as they are&quot;: for example if you have a form that posts (form method='post'...) a variable from an input field named &quot;familyname&quot;, you will not find it as $familyname in the action file, but you can always retrieve its value issuing $_POST['familyname'].

Hope it helps
Gaetano
 
Actually, if you really care about portability, you would want to use [tt]$HTTP_POST_VARS[/tt] and it's relatives, because this makes the script work even on servers with an old version of PHP.

//Daniel
 
Daniel, as (nearly) always, you are right!
Gaetano
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top