PHP - Migrating Forms : Php4 To 5
A while back my webhost upgraded to PHP5 and broke a few of my simple scripts - primarily forms using a text box for entry. I renamed and relinked the forms to .php4 and it "solved" the problem.
I've decided to fix them correctly and use proper PHP 5 code. What's the easiest way to actually retrieve the value of a text input in PHP5? My old reference tricks return null. When I started reading up I saw only PHP4 examples and then in over my head with global variables, httaccess and php.ini. I don't want to mess about with the default settings. I'm sure I zoomed right past a simple answer on my way to that mess. A simple example script: Code: [Select] <FORM NAME="form1" ID="form1" METHOD="POST" ACTION="simple.php"> <INPUT Type='Text' Name="i1Text" ID="i1Text" Value="Default"> <INPUT Type="Submit" Name="Submit1" Value="Read the Text"> </FORM> <?PHP if (isset($_POST['Submit1'])) { $RefText=$i1Text; print "Text: $RefText"; <!-- Returns blanks unless .php4 --> } ?>So, how do I actually get to that text value? Thanks in advance! Similar TutorialsHi all, please be nice my php is poor! I operate a website which uses the JS menue from Milonic, As part of the package from Milonic there is a function to output the menu as a site map this uses some clever php jiggery pokery.... I have recently changed hosts to a new host offering only php v5.3, i have noticed that the sitemap now will not run, to my unknowledgeable eyes it seems to get part way through the code then output the rest as text.... see... www.tugtracker.co.uk/menu/extras/php_sitemap/index.php Code: [Select] html> <body> This file needs to be executed under PHP from a webserver and will take the <br> contents of any Milonic menu data file and output the results as either a <br> NoScript menu or as a Sitemap <? //$menuDataFile[]="http://www.milonic.com/menu_data.php"; // Can execute a WWW File $menuDataFile[]="http://www.tugtracker.co.uk/menu/embedded_main_menu.js"; // Or can execute a local file //$menuDataFile[]="/main_menu_data.php"; // You can also add more than one file //$menuDataFile[]="/menu_data.php"; // For main and sub menus if you need to $useMenuStyles=false; include("http://www.tugtracker.co.uk/menu/extras/php_sitemap/mm_dataminer.php"); echo "<Pre>".outputAsSiteMap($menuDataFile)."</Pre>"; // Can output as a Sitemap //echo "<PRE>".outputAsNoScript($menuDataFile)."</PRE>"; // Or output as a NoScript Sitemap ?> </body> </html> The dataminer code file is Code: [Select] <? /* Milonic DHTML/PHP Menu Sitemap builder version 2.0 - September 1 2006 mm_dataminer.php */ //$globalValues=Array(); //$menus=Array(); //$styles=Array(); //$filedata=""; $dataRetrieved=0; $_S=Array(); $_M=Array(); $_I=Array(); function extractStyleName($data) { global $filedata; $pos=miner_getInnerStrpos($data, "(", "="); $text=substr($data,$pos[0]+1, $pos[1]-2); $pos=miner_getInnerStrpos($data, "with(", "mm_style("); $filedata=substr($filedata,0,$pos[0]).substr($filedata,$pos[1]+9,strlen($filedata)); return $text; } function extractMenuName($data){ if(substr($data,0,1)=="(")$data=substr($data,1,strlen($data)); $pos=miner_getInnerStrpos($data, "(\"", "\")"); $text=substr($data,$pos[0]+1, $pos[1]-2); $text=ereg_replace("\"", "", $text); return $text; } function getThisFile(){ $getThisFile=$_SERVER['SCRIPT_NAME']; $pos=strrpos($getThisFile,"/"); if($pos)$getThisFile=substr($getThisFile,$pos+1); return $getThisFile; } function getThisFolder(){ $thisfile=getThisFile(); $thisFolder=$_SERVER['SCRIPT_NAME']; if(strlen($thisfile)>0)$thisFolder=ereg_replace($thisfile,"",$thisFolder); return $thisFolder; } function createMenuStyleCSS() { global $styles; $cssoutput="<style>"; $styleproperties=""; foreach ($styles as $key => $value) { foreach ($value as $cssproperty => $cssvalue) { if($cssproperty=="stylename")$stylename=$cssvalue; if($cssproperty=="offcolor")$styleproperties.="color:$cssvalue;"; if($cssproperty=="offbgcolor")$styleproperties.="background-color:$cssvalue;"; if($cssproperty=="fontfamily")$styleproperties.="font-family:$cssvalue;"; if($cssproperty=="fontsize")$styleproperties.="font-size:$cssvalue;"; } $cssoutput.= ".".$stylename."{".$styleproperties."}"; } $cssoutput.="</style>"; echo $cssoutput; } $RitemsArray=Array(); function getRecursiveItemsByMenuname($menuname, $datafile, $level=0, $counter=1){ global $menus,$RitemsArray; $menus=getMenusFromData($datafile); //echo "<HR>".count($menus)."<HR>"; for($a=0;$a<count($menus);$a++){ if($menus[$a]['menuname']==$menuname){ for($b=0;$b<count($menus[$a]['items']);$b++){ $RitemsArray[]['level']=$level; $RitemsArray[count($RitemsArray)-1]['data']=$menus[$a]['items'][$b]; $RitemsArray[count($RitemsArray)-1]['data']['menu']=$a; if(isset($menus[$a]['items'][$b]['showmenu'])&& $menus[$a]['items'][$b]['showmenu']) { getRecursiveItemsByMenuname($menus[$a]['items'][$b]['showmenu'],$datafile,$level+1, $counter,$datafile); } } } } return $RitemsArray; } function getFormatedMenuDataFromFile($menufile){ global $globalValues, $styles, $menus, $filedata; $menus=Array(); if(!$menufile)$menufile="menu_data.js"; if (ereg("://", $menufile)){ $handle = fopen($menufile, "rb"); $contents = ''; if($handle){ while (!feof($handle)){ $contents .= fread($handle, 8192); } } fclose($handle); $filedata=$contents; } else{ $menufile=$_SERVER['DOCUMENT_ROOT'].$menufile; $contents = ''; if ($handle=fopen($menufile, "rb")){ while(!feof($file)){ $contents .= fread($handle, 8192); } } fclose($handle); $filedata=$contents; } if(strlen($filedata)>1) { $filedata=stripslashes($filedata); $filedata=ereg_replace("://",":",$filedata); $filedata=miner_replaceInnerText($filedata, "\"", "\"", ";", "", 1); $filedata=miner_chopInnerText($filedata, "/*", "*/", 1, 0); $filedata=miner_chopInnerText($filedata, "//", "\r", 1, 0); $filedata=ereg_replace("\t","",$filedata); $filedata=miner_replaceInnerText($filedata, "\"", "\"", "with", "_H_T_I_W_", 1); $filedata=miner_replaceInnerText($filedata, "\"", "\"", "{", "_OPEN_CUR_BRA_CKET_", 1); $filedata=miner_replaceInnerText($filedata, "\"", "\"", "}", "_CLOSE_CUR_BRA_CKET_", 1); $filedata=ereg_replace("\n",";",$filedata); $filedata=ereg_replace("\r",";",$filedata); $filedata=ereg_replace(" {2,}", " ", $filedata); $filedata=ereg_replace(" ;",";",$filedata); $filedata=ereg_replace("; ",";",$filedata); $filedata=ereg_replace("= ","=",$filedata); $filedata=ereg_replace(" =","=",$filedata); $filedata=ereg_replace(":","://",$filedata); $globalValues["_menuCloseDelay"]=extractPair("_menuCloseDelay",$filedata); $globalValues["_menuOpenDelay"]=extractPair("_menuOpenDelay",$filedata); $globalValues["_subOffsetTop"]=extractPair("_subOffsetTop",$filedata); $globalValues["_subOffsetLeft"]=extractPair("_subOffsetLeft",$filedata); $globalValues["disableMouseMove"]=extractPair("disableMouseMove",$filedata); $globalValues["ignoreCollisions"]=extractPair("ignoreCollisions",$filedata); $globalValues["horizontalMenuDelay"]=extractPair("horizontalMenuDelay",$filedata); $globalValues["retainClickValue"]=extractPair("retainClickValue",$filedata); $globalValues["closeAllOnClick"]=extractPair("closeAllOnClick",$filedata); $globalValues["noSubImageSpacing"]=extractPair("noSubImageSpacing",$filedata); $globalValues["includeTabIndex"]=extractPair("includeTabIndex",$filedata); $globalValues["buildAllMenus"]=extractPair("buildAllMenus",$filedata); $globalValues["_CFix"]=extractPair("_CFix",$filedata); $globalValues["blankPath"]=extractPair("blankPath",$filedata); $globalValues["_scrollUpImage"]=extractPair("_scrollUpImage",$filedata); $globalValues["_scrollDownImage"]=extractPair("_scrollDownImage",$filedata); $globalValues["_scrollAmount"]=extractPair("_scrollAmount",$filedata); $globalValues["_scrollDelay"]=extractPair("_scrollDelay",$filedata); $data=split("with",$filedata); $stylecount=0; $menucount=0; //echo count($data); for($a=0;$a<count($data);$a++) { if(eregi("new mm_style\(\)", $data[$a])) { $stylename=extractStyleName($data[$a]); $styles[$stylecount]["stylename"]=$stylename; $props=miner_getInnerText($data[$a], "{", "}"); $propsar=split(";",$props); for($b=0;$b<count($propsar);$b++){ $pos=strpos($propsar[$b],"="); if($pos){ $key=substr($propsar[$b],0,$pos); $styles[$stylecount][$key]=extractPair($key,$data[$a]); } } $stylecount++; } if(eregi("new menuname\(", $data[$a])) { $menuname=extractMenuName($data[$a]); $menus[$menucount]["menuname"]=$menuname; $props=miner_getInnerText($data[$a], "{", "}"); $propsar=split(";",$props); $itemnumber=0; for($b=0;$b<count($propsar);$b++){ if(substr($propsar[$b],0,3)=="aI("){ $aitext=substr(miner_getInnerText($propsar[$b], "\"", "\""),1,strlen($propsar[$b])-6); $aiparts=split("",$aitext); for($c=0;$c<count($aiparts);$c++){ $pos=strpos($aiparts[$c],"="); if($pos){ $key=substr($aiparts[$c],0,$pos); $val=substr($aiparts[$c],$pos+1,strlen($aiparts[$c])); $menus[$menucount]['items'][$itemnumber][$key]=$val; $lastGoodItem=$itemnumber; $lastGoodKey=$key; } else{ if($aiparts[$c]){ $menus[$menucount]['items'][$lastGoodItem][$lastGoodKey].=";".$aiparts[$c]; } } } $itemnumber++; } else{ $pos=strpos($propsar[$b],"="); if($pos){ $key=substr($propsar[$b],0,$pos); $menus[$menucount][$key]=extractPair($key,$data[$a]); } } } $menucount++; } } } return $filedata; } function getMenusFromData($datafile) { global $_M; $menus=Array(); $menucount=0; $data=split("with",$datafile); for($a=0;$a<count($data);$a++) { if(eregi("new menuname\(", $data[$a])) { $menuname=extractMenuName($data[$a]); $menus[$menucount]["menuname"]=$menuname; $props=miner_getInnerText($data[$a], "{", "}"); $propsar=split(";",$props); $itemnumber=0; for($b=0;$b<count($propsar);$b++){ if(substr($propsar[$b],0,3)=="aI("){ $aitext=substr(miner_getInnerText($propsar[$b], "\"", "\""),1,strlen($propsar[$b])-6); $aiparts=split("",$aitext); $menus[$menucount]['items'][$itemnumber]['menu']=$menucount+count($_M); for($c=0;$c<count($aiparts);$c++){ $pos=strpos($aiparts[$c],"="); if($pos){ $key=substr($aiparts[$c],0,$pos); $val=substr($aiparts[$c],$pos+1,strlen($aiparts[$c])); $val=ereg_replace("_H_T_I_W_","with",$val); $menus[$menucount]['items'][$itemnumber][$key]=$val; $lastGoodItem=$itemnumber; $lastGoodKey=$key; } else{ if($aiparts[$c]){ $menus[$menucount]['items'][$lastGoodItem][$lastGoodKey].=";".$aiparts[$c]; } } } $itemnumber++; } else{ $pos=strpos($propsar[$b],"="); if($pos){ $key=substr($propsar[$b],0,$pos); $menus[$menucount][$key]=extractPair($key,$data[$a]); } } } $menucount++; } } return $menus; } function getSiteMapData($datafile) { global $globalValues, $styles, $menus, $useMenuStyles; $oldlevel=0; $menus=""; $data=getFormatedMenuDataFromFile($datafile); echo "<PRE style='color:red;background:#c0c0c0'>$data</PRE>"; $output=""; $mainmenus=getMainMenus(); //echo count($mainmenus)."<HR>"; if($useMenuStyles)createMenuStyleCSS(); for($a=0;$a<count($mainmenus);$a++)$items=getRecursiveItemsByMenuname($mainmenus[$a]); //echo count($items)."<HR>"; $output.="<UL>"; for($a=0;$a<count($items);$a++) { $leveldifference=$items[$a]['level']-$oldlevel; if($leveldifference>0)for($x=0;$x<$leveldifference;$x++)$output.= "<UL>\n"; if($leveldifference<0)for($x=0;$x>$leveldifference;$x--)$output.= "</UL>\n"; $item=$items[$a]['data']; $itemHTML=""; if($item['text']) { $itemHTML=ereg_replace("_H_T_I_W_","with",$item['text']); if(isset($item['image'])&&$item['image'])$itemHTML="<img src=".$item['image']." border=0>".$itemHTML; } else { } if(isset($item['url'])&&$item['url'])$itemHTML="<a href=".$item['url'].">".$itemHTML."</a>"; $mstyle=$menus[$item['menu']]['style']; $output.= "<LI class=$mstyle>$itemHTML\n"; $oldlevel=$items[$a]['level']; } $output.="</UL>"; return $output; } function getGlobalsFromData($datafile) { $menuGlobals=Array(); $menuGlobals["_menuCloseDelay"]=extractPair("_menuCloseDelay",$datafile); $menuGlobals["_menuOpenDelay"]=extractPair("_menuOpenDelay",$datafile); $menuGlobals["_subOffsetTop"]=extractPair("_subOffsetTop",$datafile); $menuGlobals["_subOffsetLeft"]=extractPair("_subOffsetLeft",$datafile); $menuGlobals["disableMouseMove"]=extractPair("disableMouseMove",$datafile); $menuGlobals["ignoreCollisions"]=extractPair("ignoreCollisions",$datafile); $menuGlobals["horizontalMenuDelay"]=extractPair("horizontalMenuDelay",$datafile); $menuGlobals["retainClickValue"]=extractPair("retainClickValue",$datafile); $menuGlobals["closeAllOnClick"]=extractPair("closeAllOnClick",$datafile); $menuGlobals["noSubImageSpacing"]=extractPair("noSubImageSpacing",$datafile); $menuGlobals["includeTabIndex"]=extractPair("includeTabIndex",$datafile); $menuGlobals["buildAllMenus"]=extractPair("buildAllMenus",$datafile); $menuGlobals["_CFix"]=extractPair("_CFix",$datafile); $menuGlobals["blankPath"]=extractPair("blankPath",$datafile); $menuGlobals["_scrollUpImage"]=extractPair("_scrollUpImage",$datafile); $menuGlobals["_scrollDownImage"]=extractPair("_scrollDownImage",$datafile); $menuGlobals["_scrollAmount"]=extractPair("_scrollAmount",$datafile); $menuGlobals["_scrollDelay"]=extractPair("_scrollDelay",$datafile); return $menuGlobals; } ################################################################################ function getStylesFromData($datafile) { $styles=Array(); $stylecount=0; $data=split("with",$datafile); for($a=0;$a<count($data);$a++) { if(eregi("new mm_style\(\)", $data[$a])) { $stylename=extractStyleName($data[$a]); $styles[$stylecount]["stylename"]=$stylename; $props=miner_getInnerText($data[$a], "{", "}"); $propsar=split(";",$props); for($b=0;$b<count($propsar);$b++){ $pos=strpos($propsar[$b],"="); if($pos){ $key=substr($propsar[$b],0,$pos); $styles[$stylecount][$key]=extractPair($key,$data[$a]); } } $stylecount++; } } return $styles; } function extractPair($data, $filedata){ if(!strpos($filedata, $data))return ""; $data=ereg_replace(" =","=",$data); $data=ereg_replace("= ","=",$data); $text=miner_getInnerText($filedata, $data."=", ";"); $text=substr($text,strlen($data)+1,strrpos($text,";")-strlen($data)-1); $filedata=miner_chopInnerText($filedata, $data, ";", 0,0); $text=ereg_replace("\"", "", $text); return $text; } function miner_replaceInnerText($haystack, $startNeedle, $endNeedle, $needle, $newneedle, $loopthru=0) { /* This function replaces text inside a specified block of text */ $pstr=$haystack; $pos=miner_getInnerStrpos($haystack,$startNeedle, $endNeedle); if(is_numeric($pos[0]) && is_numeric($pos[1])){ if($loopthru){ $tstr=$haystack; $pstr=""; while(is_numeric($pos[0]) && is_numeric($pos[1])){ $istr=substr($tstr,$pos[0],$pos[1]); $istr=ereg_replace($needle,$newneedle,$istr); $pstr.=substr($tstr,0,$pos[0]).$istr; $tstr=substr($tstr,$pos[0]+$pos[1],strlen($tstr)); $pos=miner_getInnerStrpos($tstr, $startNeedle, $endNeedle); } $pstr.=substr($tstr,0,strlen($tstr)); } else{ $pstr=substr($haystack,$pos[0],$pos[1]); $pstr=ereg_replace($needle,$newneedle,$pstr); $pstr=substr($haystack,0,$pos[0]).$pstr.substr($haystack,$pos[1]+$pos[0],strlen($haystack)); } } return $pstr; } function miner_getInnerStrpos($haystack, $startNeedle, $endNeedle) { $pos1=strpos($haystack, $startNeedle); $startNeedleWidth=strlen($startNeedle); $tstr=substr($haystack,$pos1+$startNeedleWidth,strlen($haystack)); $pos2=strpos($tstr, $endNeedle); if(is_numeric($pos2))$pos2=$pos2+strlen($startNeedle)+strlen($endNeedle); $spos[0]=$pos1; $spos[1]=$pos2; return $spos; } function miner_chopInnerText($haystack, $startNeedle, $endNeedle, $loopthru=1, $keepvars=0) { $pstr=$haystack; $pos=miner_getInnerStrpos($haystack, $startNeedle, $endNeedle); if(is_numeric($pos[0]) && is_numeric($pos[1])){ if($loopthru){ $tstr=$pstr; $pstr=""; while(is_numeric($pos[0]) && is_numeric($pos[1])){ if($keepvars){ $pstr.=substr($tstr,0,$pos[0]+strlen($startNeedle)); $tstr=substr($tstr,$pos[0]+$pos[1],strlen($tstr)); } else{ $pstr.=substr($tstr,0,$pos[0]); $tstr=substr($tstr,$pos[0]+$pos[1],strlen($tstr)); } $pos=miner_getInnerStrpos($tstr, $startNeedle, $endNeedle); } $pstr.=substr($tstr,0,strlen($tstr)+1); } else{ if($keepvars){ $pstr=substr($haystack,0,$pos[0]+strlen($startNeedle)); $pstr.=substr($haystack,$pos[1]+$pos[0]-strlen($endNeedle),strlen($haystack)); } else{ $pstr=substr($haystack,0,$pos[0]); $pstr.=substr($haystack,$pos[1]+$pos[0],strlen($haystack)); } } } return $pstr; } function miner_getInnerText($haystack, $startNeedle, $endNeedle, $includeNeedles=1) { $pos=miner_getInnerStrpos($haystack,$startNeedle, $endNeedle); $pstr=substr($haystack,$pos[0],$pos[1]); if(!$includeNeedles){ $pstr=substr($pstr,strlen($startNeedle),strlen($pstr)); $pstr=substr($pstr,0,strlen($pstr)-strlen($endNeedle)); } return $pstr; } function getDocumentRoot(){ $docRoot=$_SERVER['DOCUMENT_ROOT']; if(substr($docRoot,-1)!="/")$docRoot.="/"; return $docRoot; } function getMenuTextFromDataFile($filename) { $filedata=""; if (ereg("://", $filename)){ $handle = fopen($filename, "rb"); } else { //$filename=getDocumentRoot().$filename; //echo $filename; $handle = fopen($filename, "rb"); } $contents=""; if ($handle){ while(!feof($handle)) { $contents .= fread($handle, 8192); } } else { echo "<br><b>Couldn't open file: $filename</b><br>"; return; } fclose($handle); $filedata=$contents; if(strlen($filedata)>1) { $filedata=stripslashes($filedata); $filedata=ereg_replace("://",":",$filedata); $filedata=miner_replaceInnerText($filedata, "\"", "\"", ";", "", 1); $filedata=miner_chopInnerText($filedata, "/*", "*/", 1, 0); $filedata=miner_chopInnerText($filedata, "//", "\r", 1, 0); $filedata=ereg_replace("\t","",$filedata); $filedata=miner_replaceInnerText($filedata, "\"", "\"", "with", "_H_T_I_W_", 1); $filedata=miner_replaceInnerText($filedata, "\"", "\"", "{", "_OPEN_CUR_BRA_CKET_", 1); $filedata=miner_replaceInnerText($filedata, "\"", "\"", "}", "_CLOSE_CUR_BRA_CKET_", 1); $filedata=ereg_replace("\n",";",$filedata); $filedata=ereg_replace("\r",";",$filedata); $filedata=ereg_replace(" {2,}", " ", $filedata); $filedata=ereg_replace(" ;",";",$filedata); $filedata=ereg_replace("; ",";",$filedata); $filedata=ereg_replace("= ","=",$filedata); $filedata=ereg_replace(" =","=",$filedata); $filedata=ereg_replace(":","://",$filedata); $filedata=ereg_replace(";{2,}", ";", $filedata); } return $filedata; } function getMenuData($reset=0) { global $_S; global $_M; global $_I; global $dataRetrieved; global $menuDataFile; if(!$dataRetrieved||$reset==1) { $_M = Array(); $_S = Array(); $_I = Array(); $menuCounter=0; $styleCounter=0; $itemCounter=0; for($df=0;$df<count($menuDataFile);$df++) { $dataText=getMenuTextFromDataFile($menuDataFile[$df]); $styles=getStylesFromData($dataText); for($a=0;$a<count($styles);$a++) { $_S[$styleCounter]=Array(); foreach ($styles[$a] as $key => $value) { $_S[$styleCounter][$key]=$value; } $styleCounter++; } $menus=getMenusFromData($dataText); for($a=0;$a<count($menus);$a++){ $_M[$menuCounter]=Array(); foreach ($menus[$a] as $key => $value) { $_M[$menuCounter][$key]=$value; } $menuCounter++; } } } $dataRetrieved=1; } function getItemsByMenu($mnu) { global $_M, $_S, $_I; $items=$_M[$mnu]['items']; for($a=0;$a<count($items);$a++) { echo "$items[$a]<br>"; } } function getMenuByName($menuname) { global $_M, $_S, $_I; for($a=0;$a<count($_M);$a++) { if($menuname==$_M[$a]['menuname'])return $a; } return -1; } $dataMinerOutput=""; // Global Variable for containing details of output function outputSitemapItems($mnu) { global $_M,$dataMinerOutput; $dataMinerOutput.="<UL>\n"; $items=$_M[$mnu]['items']; for($a=0;$a<count($items);$a++) { $dataMinerOutput.="<li>\n"; if(isset($items[$a]['showmenu'])&&$items[$a]['showmenu']) { //Changed www.snipperdag.com aI(text showmenu and url 16 September 2007 if(isset($items[$a]['url'])&&$items[$a]['url']) { $dataMinerOutput.="<a href=".$items[$a]['url'].">".$items[$a]['text']."</a>\n"; } else{ $dataMinerOutput.=$items[$a]['text']."\n"; } //Changed www.snipperdag.com aI(text showmenu and url) url was not linked 16 September 2007 outputSitemapItems(getMenuByName($items[$a]['showmenu'])); } else { if(isset($items[$a]['url'])&&$items[$a]['url']) { $dataMinerOutput.="<a href=".$items[$a]['url'].">".$items[$a]['text']."</a>\n"; } else { $dataMinerOutput.="".$items[$a]['text']."\n"; } } } $dataMinerOutput.="</UL>\n"; }unction outputSitemapItems($mnu) { global $_M,$dataMinerOutput; $dataMinerOutput.="<UL>\n"; $items=$_M[$mnu]['items']; for($a=0;$a<count($items);$a++) { $dataMinerOutput.="<li>\n"; if(isset($items[$a]['showmenu'])&&$items[$a]['showmenu']) { //Changed www.snipperdag.com aI(text showmenu url 16 September 2007 if(isset($items[$a]['url'])&&$items[$a]['url']) { $dataMinerOutput.="<a href=".$items[$a]['url'].">".$items[$a]['text']."</a>\n"; } else{ $dataMinerOutput.=$items[$a]['text']."\n"; } //Changed www.snipperdag.com I(text showmenu url) url was not linked 16 September 2007 outputSitemapItems(getMenuByName($items[$a]['showmenu'])); } else { if(isset($items[$a]['url'])&&$items[$a]['url']) { $dataMinerOutput.="<a href=".$items[$a]['url'].">".$items[$a]['text']."</a>\n"; } else { $dataMinerOutput.="".$items[$a]['text']."\n"; } } } $dataMinerOutput.="</UL>\n"; } function outputNoScriptItems($mnu) { global $_M,$dataMinerOutput; $items=$_M[$mnu]['items']; $dataMinerOutput.=""; for($a=0;$a<count($items);$a++) { if(isset($_M[$mnu]['orientation'])&& $_M[$mnu]['orientation']) { if($a==0)$dataMinerOutput.="<table border=0 cellpadding=0 cellspacing=0><tr>"; $lnk=$items[$a]['text']; if(isset($items[$a]['url'])&&$items[$a]['url']) { $lnk="<a href=".$items[$a]['url'].">".$items[$a]['text'].""; } $dataMinerOutput.="<td valign=top><b>$lnk</b>"; if(isset($items[$a]['showmenu'])&&$items[$a]['showmenu']) { outputSitemapItems(getMenuByName($items[$a]['showmenu'])); } $dataMinerOutput.="</td>"; if($a==count($items))$dataMinerOutput.="</tr></table>"; } } $dataMinerOutput.=""; } function outputAsNoScript($datafile=null) { global $_M,$dataMinerOutput; $mainmenus=getMainMenus(); for($a=0;$a<count($mainmenus);$a++) { // Need to get system to scan through menus see if they are horiz or vert and draw TABLE for horiz or UL for vertical $dataMinerOutput=""; outputNoScriptItems($mainmenus[$a]); echo $dataMinerOutput; echo "<HR>"; } } function getStyles() { global $_S; getMenuData(); return $_S; } function showStyles($datafile) { global $_M, $_S, $_I; $styles=getStyles(); for($a=0;$a<count($styles);$a++) { echo "<b>".$_S[$a]['stylename']."</b><br>"; foreach ($_S[$a] as $key => $value) { if(!is_numeric($value))$value="\"".$value."\""; echo "<b>$key</b>=$value;<br />\n"; } echo "<HR>"; } } function getMainMenus() { global $_M, $_S, $_I; getMenuData(); $mainmenus = Array(); for($a=0;$a<count($_M);$a++) { if(isset($_M[$a]['alwaysvisible'])&&$_M[$a]['alwaysvisible'])$mainmenus[]=$a; } return $mainmenus; } function showMainMenus() { global $_M, $_S, $_I; $mainmenus=getMainMenus(); for($a=0;$a<count($mainmenus);$a++) { echo "<b>".$_M[$a]['menuname']."</b><br>"; foreach ($_M[$a] as $key => $value) { echo "$key=$value<br>"; } echo "<HR>"; } } function getItems() { global $_M; getMenuData(); $items=Array(); $itemCounter=0; for($a=0;$a<count($_M);$a++) { foreach ($_M[$a]['items'] as $key1 => $value1) { foreach ($value1 as $key => $value) { $items[$itemCounter][$key]=$value; } $itemCounter++; } } return $items; } function showItems() { $items=getItems(); for($a=0;$a<count($items);$a++) { foreach ($items[$a] as $key => $value) { echo "$key=$value "; } echo "<br>"; } } function getAllMenus() { global $_M; getMenuData(); return $_M; } function showAllMenus($datafile) { global $_M, $_S, $_I; $menus=getAllMenus(); for($a=0;$a<count($menus);$a++) { echo "<b>".$_M[$a]['menuname']."</b><br>"; foreach ($_M[$a] as $key => $value) { echo "$key=$value<br>"; } echo "<HR>"; } } function showMenusAndItems($datafile) { global $_M, $_S, $_I; getMenuData(); for($a=0;$a<count($_M);$a++) { echo "<b>".$_M[$a]['menuname']."</b><br>"; foreach ($_M[$a] as $key => $value) { echo ".....$key=$value<br>"; } foreach ($_M[$a]['items'] as $key1 => $value1) { echo "..........."; foreach ($value1 as $key => $value) { echo "$key=$value--"; } echo "<br>"; } } echo "<hr>"; } function newShowMenus() { global $_M, $_S, $_I; getMenuData(); for($a=0;$a<count($_S);$a++) { echo "<b>".$_S[$a]['stylename']."</b><br>"; foreach ($_S[$a] as $key => $value) { echo ".....$key=$value<br>"; } } echo "<HR>"; for($a=0;$a<count($_M);$a++) { echo "<b>".$_M[$a]['menuname']."</b><br>"; foreach ($_M[$a] as $key => $value) { echo ".....$key=$value<br>"; } foreach ($_M[$a]['items'] as $key1 => $value1) { echo ".........."; foreach ($value1 as $key => $value) { echo "$key=$value--"; } echo "<br>"; } } } ?> I have another site which gives the option at the host of changing from 5.2 to 5.3 the map fnction works in 5.2 but gives the same error when i set the php version to 5.3.... To see it in action (different site to the one i am having probs with) see http://79.170.40.43/locodocs.co.uk/misc/sitemap.php I would appreciate any thoughts regards this matter, i have of course asked milonic, but as the sitemap util is part of the extras, they dont support it as such! Hi... I could really do with some help, I have some form code I have been using for a very long time. how every my server company will not install php4 anymore Can someone have a look at this code and let me know why its not php5 compatible. Thanks <?php /* $sendto is the email where form results are sent to */ $sendto = "........"; /* $ccto is the email where form results can be carbon copied to */ $ccto = "..........."; /* O P T I O N A L V A R I A B L E S */ /* TO POST PHP ERRORS TO PAGE FOR DEBUGING SET: $report_errors = "ALL"; TO REMOVE PHP ERRORS FROM POSTING TO THE PAGE FOR USE SET: $report_errors = "NONE"; */ $report_errors = "NONE"; $setokurl = "1"; $okurls = "http://www.dwcontractors.com"; if ($report_errors == "NONE") { error_reporting(0); }else{ error_reporting(E_ALL); } /* --- I F S E T O K U R L = 1 ----- */ if ($setokurl == "1"){ $found_url = "0"; $referer =$_SERVER["HTTP_REFERER"]; $referer = str_replace("://", "[CS]", $referer); $referer_sp = explode("/", $referer); $referer = "$referer_sp[0]"; $referer .= "/"; $referer = str_replace("[CS]", "://", $referer); $referer = strtolower($referer); $okurls = split(",", $okurls); foreach ($okurls as $myokurls) { $myokurls = strtolower($myokurls); if ($referer == strtolower($myokurls)) { $found_url = "1"; } } if ($found_url == "0") { $ERROR_action = "bad_okurl"; include("$PATH_error$PAGE_error"); } } /* --- E N D I F S E T O K U R L = 1 --- */ /* check to see if posted */ if ($HTTP_GET_VARS || ! $HTTP_POST_VARS || $_GET || ! $_POST) { include("nverror.php4"); no_pst(); }else{ /* IF OLDER VERSION OF PHP CONVERT TO NEWER VARIABLES */ if (! $_POST) { $_POST = "$HTTP_POST_VARS"; } if (! $_SERVER) { $_SERVER = "$HTTP_SERVER_VARS"; } $year = date("Y"); $month = date("m"); $day = date("d"); $hour = date("h"); $min = date("i"); $tod = date("a"); $ip=$_SERVER["REMOTE_ADDR"]; $SEND_prnt = "The form below was submited by " . $_POST{"email"} . " from Ip address: $ip on $monthnameactual $month/$day/$year at $hour:$min $tod \n"; $SEND_prnt .= "--- DW Contractors ---\n\n"; /* CHECK TO SEE IF $_POST{"required"} IS SET */ if ($_POST{"required"}){ $post_required = $_POST{"required"}; $required = split(",", $post_required); $reqnum = count($required); for ($req=0; $req < $reqnum; $req++) { $REQ_name = $required[$req]; $REQ_value = $POST{"$REQ_name"}; if ($REQ_name == "email") { $goodem = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $_POST{"email"}, $trashed); if (! $goodem) { include("nverror.php4"); msng_email(); } /* end ! $goodem */ } elseif (! $_POST{"$REQ_name"}) { $isreqe = "1"; $REQ_error .= "<li> $REQ_name "; } /* end ! req val */ } /* end REQ for loop */ /* IF THERE ARE ANY REQUIRED FIELDS NOT FILLED IN */ if ($isreqe == "1") { include("nverror.php4"); msng_required(); } } /* END CHECK TO SEE IF $_POST{"required"} IS SET */ /* END IF THERE ARE ANY REQUIRED FIELDS NOT FILLED IN */ /* GET POSTED VARIABLES */ foreach ($_POST as $NVPOST_name => $NVPOST_value) { $NVPOST_value = str_replace("\n", "", $NVPOST_value); $NVPOST_value = str_replace("\r", "", $NVPOST_value); $NVPOST_value = preg_replace("'\cc:'si", "Cc ", $NVPOST_value); $NVPOST_value = preg_replace("'\bcc:'si", "bcc ", $NVPOST_value); $NVPOST_value = preg_replace("'\to:'si", "to ", $NVPOST_value); $NVPOST_value = preg_replace("'\bc:'si", "bc ", $NVPOST_value); if (strtolower($NVPOST_name) == "subject") { $NVPOST_value = str_replace(":", ";", $NVPOST_value); } /* G E T E M A I L */ if (strtolower($NVPOST_name) == "email") { $SEND_email = "$NVPOST_value"; $SEND_email = str_replace(":", "", $SEND_email); $SEND_email = str_replace(" ", "", $SEND_email); } /* END GET LEADS EMAIL */ if (! $_POST{"sort"}) { /* CHECK TO SEE IF CONFIG FIELD */ if ($NVPOST_name == "subject" || $NVPOST_name == "sort" || $NVPOST_name == "required" || $NVPOST_name == "success_page"){}else{ $SEND_prnt .= "$NVPOST_name: $NVPOST_value \n\n"; } } /* end ! sort */ } /* end foreach */ /* END GET POSTED VARIABLES */ if ($_POST{"sort"}) { /* SORT VARIABLES */ $sortvars = split(",", $_POST{"sort"}); $sortnum = count($sortvars); for ($num=0; $num < $sortnum; $num++) { $SEND_prnt .= "$sortvars[$num]: " . $_POST{"$sortvars[$num]"} . " \n\n"; } } /* END SORT VARIABLES */ /* send mail */ if (! $ccto) { $header = "From: $SEND_email\r\nReply-to: $SEND_email"; }else{ $header = "From: $SEND_email\r\nReply-to: $SEND_email\r\nCc: $ccto"; } mail($sendto, $_POST{"subject"}, $SEND_prnt, $header); /* END sendmail */ /* CHECK TO SEE IF FORM SPECIFYS A SUCCESS PAGE */ if (! $_POST{"success_page"}) { include("nverror.php4"); default_success(); }else{ $successpage=$_POST{"success_page"}; header("Location: $successpage"); /* redirect */ exit; } } /* END IF POSTED */ ?> Hi, I am trying to migrate my project from mysql to mysqli but with little knowledge of the later. Among the noticeable errors is that the code is no longer fetching data from the database, and I am also getting UNDEFINED VARIABLE errors on the in the mysqli statement that should be binding results to variables. Here is the code if you can help: //set connection variables $host = "localhost"; $username = "root"; $password = "password"; $db_name = "mydb"; //database name //connect to mysql server $mysqli = new mysqli($host, $username, $password, $db_name); //check if any connection error was encountered if(mysqli_connect_errno()) { echo "Error: Could not connect to database."; exit; } //Just counting ...required for pagination... $query = "SELECT COUNT(*) FROM t_persons"; $result = mysqli_query($mysqli,$query) or die(mysqli_connect_errno()); $num_rows = mysqli_fetch_row($result); $pages = new Paginator; $pages->items_total = $num_rows[0]; $pages->mid_range = 9; // Number of pages to display. Must be odd and > 3 $pages->paginate(); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } if ($stmt = $mysqli->prepare("SELECT p.PersonID, p.ImagePath, p.FamilyName, p.FirstName, p.OtherNames, p.Gender, p.CountryID, p.StatusID, i.IncidentDate, i.IncidentCountryID, i.AgencyID, i.KeywordID FROM t_incidents i INNER JOIN t_incident_persons ip ON ip.IncidentID = i.IncidentID INNER JOIN t_persons p ON ip.PersonID = p.PersonID WHERE p.PersonID>0" . $likes . " ORDER BY p.PersonID DESC $pages->limit")) { /* Execute the prepared Statement */ $stmt->execute(); /* Bind results to variables */ $stmt->bind_result($PersonID,$ImagePath,$FamilyName,$FirstName,$OtherNames,$Gender,$CountryID,$StatusID,$IncidentDate,$IncidentCountryID,$AgencyID,$KeywordID); /* fetch values */ while ($rows = $stmt->fetch()) { // display records in a table // $PersonID=$row[0]; ?> <div class="thumbnail"> <a href=details.php?PersonID=<?php echo $PersonID ?> target=gallery><img src="./Persons_Images/<?php echo $row[1]; ?>" width="100" height="130" alt="" /></a><br> <a href="details.php?PersonID=<?php echo $PersonID; ?>"> <?php echo $row[2]; ?> <?php echo $row[3]; ?></a> </div> <?php }?> <?php } /* Close the statement */ $stmt->close(); /* close our connection */ $mysqli->close(); ?>I will appreciate. Joseph I just finished (or so I thought) a project. But my client's server runs PHP4, so I need to adapt my code. Here's what stopped working: Code: [Select] $localClasses = new DOMDocument; $localClasses -> load("file.xml"); $localClasses -> get_elements_by_tagname('Title') -> item(0) -> firstChild -> nodeValue Here's my petty attempt at trying to adapt this code to run in PHP4: Code: [Select] $file = file_get_contents("localClasses.xml"); $localClasses = new DOMDocument($file); $test = $localClasses -> get_elements_by_tagname('Title'); $testText = $test -> item[0] -> firstChild -> nodeValue; print $testText; This doesn't give me any errors, but nothing shows up. Any help would be appreciated. Thanks for reading! Do any one have an Idea on how to transmit xml or json from one site to another with php4......... any help please.. Thanks in advance I am trying to convert a php4 app to php5 and am getting this error (Fatal error: Cannot re-assign $this in ) when I call this class. $this = $this->createUnique($new); is the line that generates the error. I try to rename $this to $_this but it does not help. I think I lose the reference to the object later on in the code. Then I will get an error like (Fatal error: Call to a member function createUnique() on a non-object in) Is there another way to reference the current instance of an object in php5? Any help appreciated... Code Example: Code: [Select] class imageobject{ var $handle; var $height=0; var $width=0; var $directory; var $filename; //constructor function imageobject($directory,$filename,$width=0,$height=0,$color="FFFFFF") { $this->directory = $directory; $this->filename = $filename; if ($filename=="" && $width>0 && $height>0){ $new = $this->createImage($width,$height); $this = $this->createUnique($new); }elseif (file_exists($directory.$filename)){ $size = GetImageSize($directory.$filename); if ($size) $this->handle = $this->getHandle($directory.$filename,$size[2]); $this->width = $size[0]; $this->height = $size[1]; } function createUnique($imgnew) { $this->type = substr($this->output,0,3); $unique_str = $this->uniqueName(); switch ($this->type){ case "png": imagepng($imgnew,RES_DIR.$unique_str); break; default: imagejpeg($imgnew,RES_DIR.$unique_str,$this->quality); break; } $this->handle && imagedestroy($this->handle); $newobject = new imageobject(RES_DIR,$unique_str,$this->type); return $newobject; } )//end class I have had a problem with some scripts I wrote (Screenscrapers) that worked great in PHP4, but stopped working the minute I upgraded to PHP5. I can change all of my filenames to have the .PHP4 extension and this solves the problem, but since this encompasses a number of sites, internal links and hundreds of files, this is not my first choice solution. Here is the scraper, what it does, is it takes items from the zazzle Results Page by category, strips out the formatting, adds my affiliate ID and then I can present these items on my page. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Test of scrape</title> <link rel="stylesheet" type="text/css" href="/css/scraper.css" /> <script type='text/javascript' src='http://www.zazzle.com/js/logging/omniture/s_code.zjs/r-52.78223/site-zazzle.js'></script> </head> <body> <div class="gridCell " id="page_productsGrid_assetCell1"> <?php $page = file_get_contents("http://www.zazzle.com/cool+smiley+gifts"); //comment out the <span> tags completely $page = preg_replace('/<span/', "<!-- <span", $page); $page = preg_replace('/<\/span>/', "<\/span> -->", $page); $page = preg_replace('/<a /', "<a rel=\"nofollow\" ", $page); $rf_id="238219236805025733"; // Regular expression to parse "&rf=" and the $rf_id into the existing link $page=preg_replace("/(.*?)(href\s*=+\s*[\"\'])(.*?)([\"\'])(.*?)/is","$1$2$3?rf=$rf_id$4$5",$page); $test = explode('<div style="position:relative" class="clearfix">',$page); for($t=1;$t<=count($test)-2;$t++){ print "<div class=\"gridCellInfo\" id=\"page_products\">"; print $test[$t]; } ?> </body> </html> This works find in PHP4; not at all in PHP5. My ideal solution would be an .htaccess file that I could put in any directory under PHP5 to make it default to php4. I have tried this, to no avail (.htaccess): Code: [Select] <IfModule mod_rewrite.c> RewriteEngine On AddType text/html .php4 AddHandler php4-script .php .html php5 </IfModule> I have also tried a few alternatives... this appears to be a common problem and I have scoured the web and found no solution. Here are the two pages in PHP4 and PHP5: php4: http://www.killersmiley.com/test/cool-smiley.php4 php5: http://www.killersmiley.com/test/cool-smiley.php So this script did work in previous versions oh php but in php5 I get the error, "Sorry, uploaded images must be of type jpg or jpeg, (not )." So it looks like it's not recognizing my file as a jpeg?? Any contributions towards a fix are GREATLY appreciated!!! If there are clean, nice (EASY) php5 scripts available for this simple image uploading and thumbnail creation I would consider starting this over. //Listing page code: echo "<form name=\"addCat\" enctype=\"multipart/form-data\" action=\"preview.php\" method=\"post\">"; <INPUT type="file" name="pic1" size="50" value=""> <INPUT type="file" name="pic2" size="50" value=""> <INPUT type="file" name="pic3" size="50" value=""> <INPUT type="file" name="pic4" size="50" value=""> <input type="submit" value="Upload Images"> //preview.php page code: $pic1 = $_FILES['pic1']; $pic2 = $_FILES['pic2']; $pic3 = $_FILES['pic3']; $pic4 = $_FILES['pic4']; function ResizeImage($im,$maxwidth,$maxheight,$name){ $width = imagesx($im); $height = imagesy($im); if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){ if($maxwidth && $width > $maxwidth){ $widthratio = $maxwidth/$width; $RESIZEWIDTH=true; } if($maxheight && $height > $maxheight){ $heightratio = $maxheight/$height; $RESIZEHEIGHT=true; } if($RESIZEWIDTH && $RESIZEHEIGHT){ if($widthratio < $heightratio){ $ratio = $widthratio; }else{ $ratio = $heightratio; } }elseif($RESIZEWIDTH){ $ratio = $widthratio; }elseif($RESIZEHEIGHT){ $ratio = $heightratio; } $newwidth = $width * $ratio; $newheight = $height * $ratio; if(function_exists("imagecopyresampled")){ $newim = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); }else{ $newim = imagecreate($newwidth, $newheight); imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); } ImageJpeg (($newim),$name . ".jpg"); ImageDestroy ($newim); }else{ ImageJpeg ($im,$name . ".jpg"); } } // Set up some variables flush(); set_time_limit(210); // set process page limit to 3.5 minutes $maxfilesize = "102400"; //# individual file size limit - in bytes (102400 bytes = 100KB) $path="2012images"; $thumbpath="thumbs"; // two data pulls to rename images - would be easier to have a permanent counter...fix later $mysql[getpicname] = mysql_query("select pic from picname"); $z = mysql_fetch_array($mysql[getpicname]); $new_filename=$z[pic]; $new_z[pic]=$z[pic]+$total_pics; if(@mysql_query("UPDATE picname SET pic = '$new_z[pic]' ")) echo ""; // Create thumbnail from imgurl and store in thumbs // Height to reszie image to (in pixels) $RESIZEHEIGHT=200; // Width to reszie image to (in pixels) $RESIZEWIDTH=200; //thumbnail to thumbs folder, named same as 1st image $FILENAME=$thumbpath."/".$new_filename; $thumb_name=$thumbpath."/".$new_filename.".jpg"; // create a thumbnail from the first image only $im = imagecreatefromjpeg($_FILES['pic1']['tmp_name']); if($im) { if(file_exists("$pic_1.jpg")) { unlink("$pic_1.jpg"); } if (ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$FILENAME)) ImageDestroy ($im); } //now upload the images..... for ($i=1;$i<5;$i++) { //check if blank or image $xpic="pic".$i; if (($$xpic<>"none") and ($$xpic<>"")) { // check if jpg $cert1 = "image/pjpeg"; //jpg $cert2 = "image/jpeg"; //jpg (for MAC) $xtype =$HTTP_POST_FILES[$xpic]['type']; $xsize =$HTTP_POST_FILES[$xpic]['size']; if (($xtype <> $cert1) AND ($xtype <> $cert2)) { echo "<DIV class=\"errorsubheading\"><br><br>Alert - Missing or Invalid Information</DIV><br>"; echo "<DIV class=\"requiredtext\">Sorry, uploaded images must be of type jpg or jpeg, (not $xtype).</DIV><BR>"; echo "<BR><br><br>"; include ("footer.php"); exit(); } if ($xsize > $maxfilesize) { echo "<DIV class=\"errorsubheading\"><br><br>Alert - Missing or Invalid Information</DIV><br>"; echo "<DIV class=\"requiredtext\">Sorry, uploaded images must be under the maximum size requirements.</DIV><BR>"; echo "<BR><br><br>"; include ("footer.php"); exit(); } else { // upload to server $dest=$path."/".$new_filename.".jpg"; If (move_uploaded_file($$xpic, $dest)) { $photo[$i]=$dest; $new_filename+=1; } else { echo "<DIV class=\"errorsubheading\"><br><br>Alert - Upload Failed!</DIV><br>"; echo "<BR><br><br>"; include ("footer.php"); exit(); } // upload sucessful } // end type check } // end check if blank } I have an application that was written back in PHP4 days and has ceased development ever since. PHP 4 is basically gone, i can't get it to install on any of my machines now and what i use on my windows boxes (XAMPP) doesn't include PHP4 anymore. When i set everything up, i get ~50 of these: Deprecated: Assigning the return value of new by reference is deprecated in.... and on every line it looks like: $var =& _____ or $var = &something... yada-yada and removing the & symbol removes the error message. Using editplus i removed all the "=&" and "= &" and just replaced the & with space, i had read on google PHP5 doesn't need it anymore so that should've worked. But as my luck would have it, the server errors out with 500 code until i replace all the &'s back, and then the errors show up yet again. Is there anyway to force php5 to run this program despite having php4 things in it? I need someone that is really good with php forms, looking for major help. ok i have a questions i making a form so when users sign up to my website they we have an account page and in the account page the will have some more fields they need to filll in which i would use INSERT to put the things inside my db but what if they want to update there account should i use UPDATE I am attempting to create a login page, but my script is giving errors in relation to the forms. Involved PHP: Code: [Select] $username = mysql_real_escape_string($_POST['username']); if ($_POST['submit']=='Login') { $md5pass = md5($_POST['password']); $sql = "SELECT id,username FROM members WHERE username = '$username' AND password = '$md5pass'"; //etc etc... Involved HTML: Code: [Select] <form id="f6" action="" method="post" onsubmit="return weCheckForm(this)"> <fieldset id="e6" class="cc32"> <label id="e5" class="cc33" for="e4"> Username </label> <input id="e4" class="cc34" type="text" name="username" title="username" size="23"><br> <label id="e3" class="cc33" for="e2"> Password </label> <input id="e2" class="cc34" type="password" name="password" title="password" size="23"><br> <input id="e1" class="cc35" type="submit" title="submit" value="Login"> </fieldset> </form> Errors received: Notice: Undefined index: username in C:\(etc etc...) on line 4 Notice: Undefined index: submit in C:\(etc etc...) on line 6 Now I know that the problem is username and submit are undefined. However, I do not know how to define them in relation to the forms. i need a form that is hidden until the user clicks a button on a calendar only Then the form will be visible and have a field for the day that way pressed on submit the form would go back to being invisible.
not sure how to implement this can anyone help
I am starting to build out a class to handle forms. I want to be able to add and edit data in some cases and just add data in other cases. Also want to do some ajax stuff to prevent from having to reload the pages in certain cases. I would like to view how some other form classes work so I can model mine to what I like about others but suit my needs. I was wondering if anyone has worked with any preexisting form classes that they could recommend. I know libraries like zend and so on have these built in and wasnt sure if anyone liked any one specifically and why. We have this form that customers can make their own contact forms, and then it gets inserted to the database. We can show the forms with no problems, the problem lies when someone hits submit, how do I echo out the values of the form when I'm not sure what the input name or id is going to be? This sample form generated this code Code: [Select] <div class="element"> <label id="label-element-3" class="label" style="color:#4DBCE9;font-family:Trebuchet MS;font-size:1.2em;font-weight:normal;"> <span class="labelelementvalue">Email</span> <span class="required">*</span></label> <div class="errormessage" id="errormessage-element-3"></div> <div class="option-container"> <input class="af-inputtext af-email af-formvalue " type="text" name="element-3" id="element-3" value="" style="color:#000000;font-family:Verdana;font-size:0.8em;font-weight:normal;width:260px;border-style:solid; border-color:#dcdcdc;-moz-border-radius:5px;-khtml-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;border-width:1px;padding:5px;"></div> </div> <div class="element"> <label id="label-element-4" class="label" style="color:#4DBCE9;font-family:Trebuchet MS;font-size:1.2em;font-weight:normal;"> <span class="labelelementvalue">Textarea</span></label> <div class="errormessage" id="errormessage-element-4"></div> <div class="option-container"> <textarea class="af-textarea af-formvalue " name="element-4" id="element-4" style="color:#000000;font-family:Verdana;font-size:0.8em;font-weight:normal;width:300px;border-style:solid; border-color:#dcdcdc;-moz-border-radius:5px;-khtml-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;border-width:1px;padding:5px;" rows="6"></textarea></div> </div> <div class="element"> </div> If you notice, each input type is named "element-" with a number afterwards. So each input could be like "element-4", "element-21", and so forth. How would I post those values of the input fields when they are automatically named? Thanks in advance Hi there, I'm new to php/MySQL. Just wondering how to create a multipage form with a back, save and submit button. Also, how do you stored the form data into the datebase and how do you display a list of submitted forms by the user to the user. Hello, I just assembly a form and for styling it I am using CSS in an external file. Problem is that IE8 and I don't know about 7 (in IE9 is ok) it doesn't show the styling inside the form... My structure is something like this: (in any other situation my css styling is displayed normally) Code: [Select] <form> <span class="myclass"> </span> </form>Is there any fix for it? Thank you print("<form name='form1' method='post' action='create-b.php' enctype='application/x-www-form-urlencoded' style='margin:0px'> <input type='hidden' name='time' value='werwRG/443gooa22a04c0c2d46c802cc7e3b262398852$glg/WE?F'> <input name='name' value='Anonymous' type='text' MAXLENGTH='15' style='position:absolute;width:650px;left:67px;top:142px;z-index:11'> <input name='subject' value='(No subject)' MAXLENGTH='15' type='text' style='position:absolute;width:650px;left:67px;top:166px;z-index:11'> <textarea name='body' MAXLENGTH='255' type='text' style='position:absolute;left:67px;top:191px;width:650px;height:98px;z-index:11'></textarea> <input name='submit' type='submit' value='Create thread' style='position:absolute;left:614px;top:291px;z-index:11'> <div id='captcha' style='position:absolute; overflow:hidden; left:10px; top:296px; z-index:10'> require_once('captc/recaptchalib.php'); $publickey = '*******************************************'; echo recaptcha_get_html($publickey); </form> </div>"); How can I make the highlighted text be read as PHP and not just text? It has to be in the form tags... before you reply saying you forgot the php tags, no i didn't. I can't use php tags inside php tags... hi, I have a form in which some information is required but the username is optional however if it is left blank it says that username is taken please choose another one. how can I make it accept it if a username isn't entered? Code: [Select] <?php if (!isset($_SESSION)){ session_start(); } $fname=""; $lname=""; $username=""; $password=""; $reenterPassword=""; $address=""; $state=""; $city=""; $zip=""; $phone=""; $fax=""; $email =""; $re_enter_email =""; $payment = ""; $paypal_username=""; $ship_first_name=""; $ship_last_name=""; $ship_address=""; $ship_city=""; $ship_state=""; $ship_zip=""; $ship_email=""; $ship_re_email=""; $pet_name=""; $age=1; $breed=""; $pet_name2=""; $age2=1; $breed2=""; // Logout if(isset($_POST['logout'])){ unset($_SESSION['user']); } // Loading captcha file require_once('recaptchalib.php'); $privatekey = "6LdxwsoSAAAAAO4CWYDjkrGQsf5GXuIopJcC6SkE"; $publickey = "6LdxwsoSAAAAAFrZTLjBoDvLLjk9_NR_ubncL-24"; require_once("functions.php"); DatabaseConnection(); $state = $_POST['state']; $payment = $_POST['payment_Method']; $breed = $_POST['breed']; $ship_state=$_POST['Shipstate']; if((isset($_REQUEST["submit"]) && $_REQUEST["submit"]=="Log in") || $_SESSION['user']){ if(!$_SESSION['user']){ $login_username = isset($_REQUEST["username"])?$_REQUEST["username"]:""; $login_password = isset($_REQUEST["password"])?$_REQUEST["password"]:""; $msg = array(); if ($login_username == "") $login_msg['username_empty'] = "Please enter your name"; if ($login_password == "") $login_msg['password_empty'] = "Please enter your password"; $query = "SELECT * FROM customers WHERE username = '$login_username' AND password = '".$login_password."'"; }else{ $customer_id = $_SESSION['user']; $query = "SELECT * FROM customers WHERE customer_id='$customer_id'"; } if (!$login_msg){ $login_process = true; $result = mysql_query($query) or die("Database error: " . mysql_error()); if (mysql_num_rows($result) > 0){ $row = mysql_fetch_object($result); $customer_id = $row->customer_id; $_SESSION['user'] = $customer_id; $fname = $row->fname; $lname = $row->lname; $username=$row->username; $address=$row->address; $state=$row->state; $city=$row->city; $zip=$row->zip; $phone=$row->phone; $fax=$row->fax; $email =$row->email; $payment = $row->payment_method; $paypal_username=$row->paypal_username; $ship_first_name=$row->ship_first_name; $ship_last_name=$row->ship_last_name; $ship_address=$row->ship_address; $ship_city=$row->ship_city; $ship_state=$row->ship_state; $ship_zip=$row->ship_zip; $ship_email=$row->ship_email; $pet_name=$row->pet_name; $age=$row->age; $age_month=$row->age_month; $breed=$row->breed; $pet_name2=$row->pet_name2; $age2=$row->age2; $age_month2=$row->age_month2; $breed2=$row->breed2; }else{ $login_msg['login_fail'] = "Username, password combination is not valid."; } } } if(isset($_REQUEST["submit"]) && $_REQUEST["submit"]=="submit"){ $msg=array(); $fname=isset($_REQUEST["fname"])?$_REQUEST["fname"]:""; $lname=isset($_REQUEST["lname"])?$_REQUEST["lname"]:""; $username=isset($_REQUEST["lname"])?$_REQUEST["username"]:""; $password=isset($_REQUEST["lname"])?$_REQUEST["password"]:""; $reenterPassword=isset($_REQUEST["lname"])?$_REQUEST["reenterPassword"]:""; $address=isset($_REQUEST["address"])?$_REQUEST["address"]:""; $state=isset($_REQUEST["state"])?$_REQUEST["state"]:""; $city=isset($_REQUEST["city"])?$_REQUEST["city"]:""; $zip=isset($_REQUEST["zipcode"])?$_REQUEST["zipcode"]:""; $phone=isset($_REQUEST["phone"])?$_REQUEST["phone"]:""; $fax=isset($_REQUEST["fax"])?$_REQUEST["fax"]:""; $email =isset($_REQUEST["email"])?$_REQUEST["email"]:""; $re_enter_email =isset($_REQUEST["re_email"])?$_REQUEST["re_email"]:""; $re_enter_email= $email; $payment = isset($_POST['payment_Method'])?$_POST['payment_Method']:""; $paypal_username=isset($_REQUEST["PayPal_username"])?$_REQUEST["PayPal_username"]:""; $ship_first_name=isset($_REQUEST["Shipfname"])?$_REQUEST["Shipfname"]:""; $ship_last_name=isset($_REQUEST["Shiplname"])?$_REQUEST["Shiplname"]:""; $ship_address=isset($_REQUEST["Shipaddress"])?$_REQUEST["Shipaddress"]:""; $ship_city=isset($_REQUEST["Shipcity"])?$_REQUEST["Shipcity"]:""; $ship_state=isset($_REQUEST["Shipstate"])?$_REQUEST["Shipstate"]:""; $ship_zip=isset($_REQUEST["Shipzipcode"])?$_REQUEST["Shipzipcode"]:""; $ship_email=isset($_REQUEST["Shipemail"])?$_REQUEST["Shipemail"]:""; $ship_re_email=$ship_email; $pet_name=isset($_REQUEST["petName"])?$_REQUEST["petName"]:""; $age=isset($_REQUEST["age"])?$_REQUEST["age"]:''; $age=isset($_REQUEST["age_month"])?$_REQUEST["age_month"]:1; $breed=isset($_REQUEST["breed"])?$_REQUEST["breed"]:""; $nutritional_needs=isset($_REQUEST["nutritionalNeeds"])?$_REQUEST["nutritionalNeeds"]:""; $special_instructions=isset($_REQUEST["specialInstructions"])?$_REQUEST["specialInstructions"]:""; $pet_name2=isset($_REQUEST["petName2"])?$_REQUEST["petName2"]:""; $age2=isset($_REQUEST["age2"])?$_REQUEST["age2"]:""; $age2=isset($_REQUEST["age_month2"])?$_REQUEST["age_month2"]:1; $breed2=isset($_REQUEST["breed2"])?$_REQUEST["breed2"]:""; $nutritional_needs2=isset($_REQUEST["nutritionalNeeds2"])?$_REQUEST["nutritionalNeeds2"]:""; $special_instructions2=isset($_REQUEST["specialInstructions2"])?$_REQUEST["specialInstructions2"]:""; // Products information $product_name=isset($_REQUEST["productname"])?$_REQUEST["productname"]:""; $quantity=isset($_REQUEST["quantity"])?$_REQUEST["quantity"]:0; $price=isset($_REQUEST["price"])?$_REQUEST["price"]:0; $quantity_diff=isset($_REQUEST["quantity_diff"])?$_REQUEST["quantity_diff"]:0; $price_diff=isset($_REQUEST["price_diff"])?$_REQUEST["price_diff"]:0; $sales_tax=isset($_REQUEST["salestax"])?$_REQUEST["salestax"]:0; $subtotal=isset($_REQUEST["subtotal"])?$_REQUEST["subtotal"]:0; $shipping_cost=isset($_REQUEST["shippingcost"])?$_REQUEST["shippingcost"]:0; $total=isset($_REQUEST["total"])?$_REQUEST["total"]:0; // check for login if(isset($_POST['customer_id'])){ $customer_id = $_POST['customer_id']; $query = "SELECT * FROM customers WHERE customer_id='$customer_id'"; $result = mysql_query($query) or die("Database error: " . mysql_error()); if (mysql_num_rows($result) > 0){ $login_process = true; $_SESSION['user'] = $customer_id; $row = mysql_fetch_object($result); $fname = $row->fname; $lname = $row->lname; $username=$row->username; } } // Is username taken ? if(!$login_process){ $query = "SELECT * FROM customers WHERE username = '$username'"; $result = mysql_query($query) or die("Database error: " . mysql_error()); if (mysql_num_rows($result) > 0){ array_push($msg,"This username is already taken, please choose another one."); } } if($fname==""){ array_push($msg,"Please Enter First Name."); } if($lname==""){ array_push($msg,"Please Enter Last Name."); } /* if($username==""){ array_push($msg,"Please Enter User Name."); } if(!$login_process){ if($password==""){ array_push($msg,"Please Enter Password."); } if($reenterPassword==""){ array_push($msg,"Please Enter Re-Enter Password."); } if($reenterPassword!=$password){ array_push($msg,"Both passwords does not match."); } }*/ if($address==""){ array_push($msg,"Please Enter Address."); } if($city==""){ array_push($msg,"Please Enter City."); } if($state=="Please choose a state"){ array_push($msg,"Please Select State."); } if($zip==""){ array_push($msg,"Please Enter Zip."); } else { if(!is_numeric($zip)){ array_push($msg,"Please Enter Digits In Zip."); } } if($phone==""){ array_push($msg,"Please Enter Phone."); } else { if(!is_numeric($phone)){ array_push($msg,"Please Enter Digits In Phone."); } } if($email==""){ array_push($msg,"Please Enter Email."); } if($payment==""){ //array_push($msg,"Please Select Payment Method."); } if($paypal_username==""){ // array_push($msg,"Please Enter Paypal User Name."); } if($ship_first_name==""){ array_push($msg,"Please Enter Shipping First Name."); } if($ship_last_name==""){ array_push($msg,"Please Enter Shipping Last Name."); } if($ship_address==""){ array_push($msg,"Please Enter Shipping Address."); } if($ship_city==""){ array_push($msg,"Please Enter Shipping City."); } if($ship_state==""){ array_push($msg,"Please Select Shipping State."); } if($ship_zip==""){ array_push($msg,"Please Enter Shipping Zip."); } else { if(!is_numeric($ship_zip)){ array_push($msg,"Please Enter Digits In Shipping Zip."); } } if($ship_email==""){ // array_push($msg,"Please Enter Shipping Email."); } // Check Captcha $resp = recaptcha_check_answer ($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]); if (!$resp->is_valid) { array_push($msg,"Wrong Captcha, please try again."); } // Insert customer if($login_process){ $sql0 = "UPDATE customers SET address='$address',city='$city', state='$state', zip='$zip', phone='$phone', fax='$fax', email='$email', re_enter_email='$re_enter_email', ship_first_name='$ship_first_name', ship_last_name='$ship_last_name', ship_address='$ship_address', ship_city='$ship_city', ship_state='$ship_state', ship_zip='$ship_zip', ship_email='$ship_email', ship_re_enter_email='$ship_re_email', pet_name='$pet_name', age='$age', breed='$breed', pet_name2='$pet_name2', age2='$age2', breed2='$breed2', age_month='$age_month', age_month2='$age_month2' WHERE customer_id='$customer_id'"; if(count($msg) == 0){ $r= mysql_query($sql0) or die("Query Error : " . mysql_error()); $customer = $customer_id; } }else{ $sql0="INSERT INTO customers (fname, lname,username,password, address, city, state, zip, phone, fax, email, re_enter_email, ship_first_name, ship_last_name, ship_address, ship_city, ship_state, ship_zip, ship_email, ship_re_enter_email , pet_name, age, breed, pet_name2, age2, breed2, age_month, age_month2) VALUES ('$fname', '$lname','$username','$password', '$address', '$city', '$state', '$zip', '$phone', '$fax', '$email', '$re_enter_email', '$ship_first_name', '$ship_last_name', '$ship_address', '$ship_city', '$ship_state', '$ship_zip', '$ship_email', '$ship_re_email', '$pet_name', '$age', '$breed', '$pet_name2', '$age2', '$breed2', '$age_month', '$age_month2')"; if(count($msg) == 0){ $r= mysql_query($sql0) or die("Query Error : " . mysql_error()); $customer = mysql_insert_id(); } } // Insert Order $sql1="INSERT INTO orders (product_name, customer, quantity, price, sales_tax, subtotal, shipping_cost, total, nutritional_needs, special_instructions, nutritional_needs2, special_instructions2) VALUES ('$product_name', '$customer', '$quantity_diff', '$price_diff', '$sales_tax', '$subtotal', '$shipping_cost', '$total', '$nutritional_needs', '$special_instructions', '$nutritional_needs2', '$special_instructions2')"; if(count($msg) == 0){ $m= mysql_query($sql1) or die("Query Error : " . mysql_error()); } } ?> |