mitwess Posted August 20, 2013 Share Posted August 20, 2013 i recently upgraded servers (centos 5/php5.1.6 to centos 6/php5.3.3) and now one of my web page embedded scripts is not working. while it works fine on my old server, on the new server half the code gets displayed on the webpage where the script is called from. so i'm wondering if i'm missing a php module (that i need to install) or my syntax doesn't work for the newer version of php. i did run the code in a syntax checker and it checked out (but who knows how accurate that is). the code is below. any help/ideas would be appreciated. <? setcookie("ScriptVisited","",time() - 3600,'/'); ?> <html><head><LINK REL="STYLESHEET" HREF="/style.css" TYPE="text/css"><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><title>TEST</title> <? include 'poll/test/includes.php'; $link = mysql_connect($host,$login,$password); $error=mysql_error(); if($error) die($error); mysql_select_db($base,$link); $error=mysql_error(); if($error) die($error); clearstatcache(); $synchronize=false; if($mtime=filemtime($pollfile)) { $result=mysql_query("select UNIX_TIMESTAMP(stamp) from mtimes where file='".mysql_escape_string($pollfile)."'",$link); $error=mysql_error(); if($error) echo $error; if(mysql_num_rows($result)==0) { mysql_query("insert into mtimes (file,stamp) values ('".mysql_escape_string($pollfile)."',FROM_UNIXTIME($mtime))",$link); $error=mysql_error(); if($error) echo $error; $synchronize=true; } else { $stamp=array_pop(mysql_fetch_row($result)); if($stamp!=$mtime) { mysql_query("update mtimes set stamp=FROM_UNIXTIME($mtime) where file='".mysql_escape_string($pollfile)."'",$link); $error=mysql_error(); if($error) echo $error; $synchronize=true; } } } if($synchronize) { if(file_exists($pollfile)) { if($pollptr=fopen($pollfile,"r")) { while($line=trim(fgets($pollptr,4096))) { $type='rotational'; if($line[0]=='#' or strlen($line)==0) continue; if(strncmp($line,"d-",2)==0) { $line=substr($line,2); $type='normal'; } $pollanswers=explode('|',$line); $pollquest=array_shift($pollanswers); $anstype='normal'; if(count($pollanswers)==0) { array_unshift($pollanswers,"0","1","2","3","4"); $anstype='scale'; } for($query="and (",$i=0;$i<count($pollanswers);$i++) { if($i==0) $query.="answer='".mysql_escape_string($pollanswers[$i])."' "; else $query.="or answer='".mysql_escape_string($pollanswers[$i])."' "; } $query.=")"; $result=mysql_query("select quest_id from questions,answers where question='".mysql_escape_string($pollquest)."' and quest_id=questions.id $query group by quest_id having count(answer)=".count($pollanswers),$link); $error=mysql_error(); if($error) echo $error; $found=false; if(mysql_num_rows($result)>0) { while($row=mysql_fetch_row($result)) { $quest_id=array_pop($row); $result2=mysql_query("select count(*) from answers where quest_id=$quest_id",$link); $error=mysql_error(); if($error) echo $error; if(array_pop(mysql_fetch_row($result2))==count($pollanswers)) { $found=true; break; } } } else $found=false; if($found==false) { $result=mysql_query("insert into questions (question,type,active,answertype) values ('".mysql_escape_string($pollquest)."','$type','yes','$anstype')",$link); $error=mysql_error(); if($error) echo $error; $quest_id=mysql_insert_id($link); for($i=0;$i<count($pollanswers);$i++) { $result=mysql_query("insert into answers (answer,quest_id) values ('".mysql_escape_string($pollanswers[$i])."',$quest_id)",$link); $error=mysql_error(); if($error) echo $error; } } } fclose($pollptr); } } } $resultnormal=mysql_query("select id,question,answertype from questions where active='yes' and type='normal'"); $error=mysql_error(); if($error) echo $error; $resultrotational=mysql_query("select id,question,answertype from questions where active='yes' and type='rotational' order by round asc,answered desc,id asc limit $rotquestsnum"); $error=mysql_error(); if($error) echo $error; ?> <script> function verify() { <? echo "var choice;\n"; while ($line = mysql_fetch_array($resultnormal, MYSQL_ASSOC)) { if($line['answertype']=='normal') { echo "if(document.form1.quest".$line['id']."[0].selected==true) {alert('Please answer question \'".addslashes($line['question'])."\''); return false;}\n"; } else if($pollintest!='yes') { echo "choice=false;\n"; echo "for(cnt=0;cnt<document.form1.quest".$line['id'].".length;cnt++){\n"; echo "if(document.form1.quest".$line['id']."[cnt].checked) choice=true;\n"; echo "}\n"; echo "if(!choice){alert('Please answer question \'".addslashes($line['question'])."\''); return false;}\n"; } } while ($line = mysql_fetch_array($resultrotational, MYSQL_ASSOC)) { if($line['answertype']=='normal') { echo "if(document.form1.quest".$line['id']."[0].selected==true) {alert('Please answer question \'".addslashes($line['question'])."\''); return false;}\n"; } else if($pollintest!='yes') { echo "choice=false;\n"; echo "for(cnt=0;cnt<document.form1.quest".$line['id'].".length;cnt++){\n"; echo "if(document.form1.quest".addslashes($line['id'])."[cnt].checked) choice=true;\n"; echo "}\n"; echo "if(!choice){alert('Please answer question \'".addslashes($line['question'])."\''); return false;}\n"; } } mysql_data_seek($resultnormal,0); mysql_data_seek($resultrotational,0); ?> } </script> </head> <body bgcolor="#eeeeee" marginwidth="0" marginheight="0" topmargin="0" leftmargin="0"> <div align="center"> <br> <? echo "<FORM name='form1' ACTION='/cgi-bin/newmb.pl' METHOD='POST'>\n"; echo "<table>\n"; while ($line = mysql_fetch_array($resultnormal, MYSQL_ASSOC)) { echo "<TR align='center'><TD>".$line['question']."</TD></TR>"; $result2=mysql_query("select answer,id from answers where quest_id=".$line['id']); $error=mysql_error(); if($error) echo $error; echo "<TR align='center'><TD>"; if($line['answertype']=='scale' and $pollintest=='no') { echo "<table border='0' cellpadding='0' cellspacing='0' width='310'><tr>\n"; echo "<td>Very Inaccurate</td>\n"; $startcol=0xc6; $endcol=0xee; $addcol=($endcol-$startcol)/((mysql_num_rows($result2)/2-1)/2); $addcol2=-$addcol; for($col=$startcol;$line2 = mysql_fetch_array($result2, MYSQL_ASSOC);$col+=$addcol) { echo "<td bgcolor='#".sprintf("%2x%2x%2x",$col,$col,$col)."'><input type='radio' value='".$line2['id']."' name='quest".$line['id']."'></td>\n"; if($col>=0xee) $addcol=$addcol2; } echo "<td> Very Accurate</td>\n"; echo "</tr></table><hr width='60%'>"; } else if($line['answertype']=='normal') { echo "<SELECT name=\"quest".$line['id']."\">\n"; echo "<OPTION>---</OPTION>\n"; while ($line2 = mysql_fetch_array($result2, MYSQL_ASSOC)) { echo "<OPTION VALUE='".$line2['id']."'>".$line2['answer']."</OPTION>\n"; } echo "</SELECT><BR/><hr width='60%'>\n"; } echo "</TD>"; echo "</TR>"; echo "<TR><TD> <TD></TR>"; echo "<TR><TD> <TD></TR>"; } while ($line = mysql_fetch_array($resultrotational, MYSQL_ASSOC)) { if($line['answertype']=='scale' and $pollintest=='yes') continue; echo "<TR align='center'><TD>".$line['question']."</TD></TR>"; $result2=mysql_query("select answer,id from answers where quest_id=".$line['id']." order by answers.id"); $error=mysql_error(); if($error) echo $error; echo "<TR align='center'><TD>"; if($line['answertype']=='scale') { echo "<table border='0' cellpadding='0' cellspacing='0' width='310'><tr>\n"; echo "<td>Very Inaccurate</td>\n"; $startcol=0xc6; $endcol=0xee; $addcol=($endcol-$startcol)/((mysql_num_rows($result2)-1)/2); $addcol2=-$addcol; for($col=$startcol;$line2 = mysql_fetch_array($result2, MYSQL_ASSOC);$col+=$addcol) { echo "<td bgcolor='#".sprintf("%2x%2x%2x",$col,$col,$col)."'><input type='radio' value='".$line2['id']."' name='quest".$line['id']."'></td>\n"; if($col>=0xee) $addcol=$addcol2; } echo "<td> Very Accurate</td>\n"; echo "</tr></table><hr width='60%'>"; } else if($line['answertype']=='normal'){ echo "<SELECT name=\"quest".$line['id']."\">\n"; echo "<OPTION>---</OPTION>\n"; while ($line2 = mysql_fetch_array($result2, MYSQL_ASSOC)) { echo "<OPTION VALUE='".$line2['id']."'>".$line2['answer']."</OPTION>\n"; } echo "</SELECT><BR/><hr width='60%'>\n"; } echo "</TD></TR>\n"; echo "<TR><TD> <TD></TR>"; echo "<TR><TD> <TD></TR>"; } echo "</table><BR>"; echo "<INPUT TYPE='SUBMIT' onclick='return verify()' VALUE='Next'/>\n"; echo "<INPUT TYPE='HIDDEN' NAME='action' VALUE='add'>"; echo "<INPUT TYPE='HIDDEN' NAME='pollintest' VALUE='$pollintest'>"; echo "</FORM>\n"; ?><br><br> </div> </body> </html> when i call the webpage where the code is, it displays most of it (instead of running it), this is what gets displayed... 0) { while($row=mysql_fetch_row($result)) { $quest_id=array_pop($row); $result2=mysql_query("select count(*) from answers where quest_id=$quest_id",$link); $error=mysql_error(); if($error) echo $error; if(array_pop(mysql_fetch_row($result2))==count($pollanswers)) { $found=true; break; } } } else $found=false; if($found==false) { $result=mysql_query("insert into questions (question,type,active,answertype) values ('".mysql_escape_string($pollquest)."','$type','yes','$anstype')",$link); $error=mysql_error(); if($error) echo $error; $quest_id=mysql_insert_id($link); for($i=0;$i\n"; echo "\n"; while ($line = mysql_fetch_array($resultnormal, MYSQL_ASSOC)) { echo ""; $result2=mysql_query("select answer,id from answers where quest_id=".$line['id']); $error=mysql_error(); if($error) echo $error; echo ""; echo ""; echo ""; echo ""; } while ($line = mysql_fetch_array($resultrotational, MYSQL_ASSOC)) { if($line['answertype']=='scale' and $pollintest=='yes') continue; echo ""; $result2=mysql_query("select answer,id from answers where quest_id=".$line['id']." order by answers.id"); $error=mysql_error(); if($error) echo $error; echo "\n"; echo ""; echo ""; } echo " ".$line['question']." "; if($line['answertype']=='scale' and $pollintest=='no') { echo "\n"; echo "\n"; $startcol=0xc6; $endcol=0xee; $addcol=($endcol-$startcol)/((mysql_num_rows($result2)/2-1)/2); $addcol2=-$addcol; for($col=$startcol;$line2 = mysql_fetch_array($result2, MYSQL_ASSOC);$col+=$addcol) { echo "\n"; if($col>=0xee) $addcol=$addcol2; } echo "\n"; echo " Very Inaccurate Very Accurate "; } else if($line['answertype']=='normal') { echo "\n"; echo "\n"; while ($line2 = mysql_fetch_array($result2, MYSQL_ASSOC)) { echo "\n"; } echo " \n"; } echo " ".$line['question']." "; if($line['answertype']=='scale') { echo "\n"; echo "\n"; $startcol=0xc6; $endcol=0xee; $addcol=($endcol-$startcol)/((mysql_num_rows($result2)-1)/2); $addcol2=-$addcol; for($col=$startcol;$line2 = mysql_fetch_array($result2, MYSQL_ASSOC);$col+=$addcol) { echo "\n"; if($col>=0xee) $addcol=$addcol2; } echo "\n"; echo " Very Inaccurate Very Accurate "; } else if($line['answertype']=='normal'){ echo "\n"; echo "\n"; while ($line2 = mysql_fetch_array($result2, MYSQL_ASSOC)) { echo "\n"; } echo " \n"; } echo " Quote Link to comment Share on other sites More sharing options...
mitwess Posted August 20, 2013 Author Share Posted August 20, 2013 another one of my php scripts is working on the new server so php is active/parsing. Quote Link to comment Share on other sites More sharing options...
mitwess Posted August 20, 2013 Author Share Posted August 20, 2013 i figured it out. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 20, 2013 Share Posted August 20, 2013 i figured it out. Was it <? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.