Jump to content

kanchatchai

Members
  • Posts

    107
  • Joined

  • Last visited

Posts posted by kanchatchai

  1. code without database. (Idia only)

    <?phpsession_start();/*$_SESSION["customer_id"]=77;//test customer_idecho 'customer id='.$_SESSION["customer_id"].'<br/>';*//*-------------------------------------- Show Product --------------------------------------*/?><FORM Name="Form1" Method="POST"><input type="hidden" name="productid" value ="4">Product 4: aa   <input type="text" name="count" value="1" size="4" maxlength="4" >   <input type="submit" name="button" id="button" value="Add to Card" /> </form><FORM Name="Form1" Method="POST"><input type="hidden" name="productid" value ="5">Product 5: bb   <input type="text" name="count" value="1" size="4" maxlength="4" >   <input type="submit" name="button" id="button" value="Add to Card" /> </form><FORM Name="Form1" Method="POST"><input type="hidden" name="productid" value ="7">Product 7: cc   <input type="text" name="count" value="1" size="4" maxlength="4" >   <input type="submit" name="button" id="button" value="Add to Card" /> </form> <?PHP /*-------------------------------------- Add--------------------------------------*/if (isset($_POST['count'])){if (isset($_SESSION["product"][$_POST['productid']]))    $_SESSION['product'][$_POST['productid']]=$_SESSION['product'][$_POST['productid']]+$_POST['count'];else    $_SESSION['product'][$_POST['productid']]=$_POST['count'];}/*-------------------------------------- Delete --------------------------------------*/ if (isset($_POST['delete_selected'])) {             if (isset($_POST['check']))             foreach($_POST['check'] as $key=>$value){             unset ($_SESSION['product'][$key]);             //echo $key;             } } /*-------------------------------------- Update --------------------------------------*/  if (isset($_POST['update'])) {             if (isset($_POST['new_count']))             foreach($_POST['new_count'] as $key=>$value){             //Can Use...             //$_SESSION['product'][$key]=$_POST['value'][$key];             //or Use ...             $_SESSION['product'][$key]=$value;             }            //echo '<br/>value updated<br/><br/>'; }  /*-------------------------------------- Show Cart --------------------------------------*/ if (isset($_SESSION['product'])){echo '<b>Your Cart</b><br/><FORM Name="Form1" Method="POST">';         foreach($_SESSION['product'] as $key=>$value){          echo '<input type="checkbox" name="check['.$key.']" >'.$key.'=<input type="text" name="new_count['.$key.']" value="'.$_SESSION['product'][$key].'"><br/>';          }  echo '<input type="submit" name="delete_selected" value="Delete Selected" />';  echo  '<input type="submit" name="update" value="Update" />';  echo  '<input type="submit" name="buynow" value="Buy Now" />';  echo '</form>';  }    // If Click Update show ..Updated...    if (isset($_POST['update'])) echo "Your Card Updated";    if (isset($_POST['buynow']))    {                if (isset($_SESSION["customer_id"]))                {                /*Update To Database                ...and show user...                */                echo "Your Cart Completed";                //Next Clear Cart Session                unset($_SESSION['product']);                }                else                {    echo "Please Login to Complete Cart.";}    }  ?>

  2. <form id="form1" name="form1" method="post" action="">  <input type="submit" name="buttonAdd" id="buttonAdd" value="Add" />  <input type="submit" name="buttonUpdate" id="buttonUpdate" value="Update" />  <input type="submit" name="buttonDelete" id="buttonDelete" value="Delete" /></form><?PHP if (isset($_POST['buttonAdd']))  {echo('Add');} if (isset($_POST['buttonUpdate']))  {echo('Update');} if (isset($_POST['buttonDelete']))  {echo('Delete');}?>[/Code]

  3. that sound good. :rofl:If we can not "modify header".we can use this script.

    <html><head><head><script type="text/javascript">function replaceDoc()  {  window.location.replace("http://www.w3schools.com")  }</script></head> <body OnLoad="replaceDoc();"></body></html>

  4. have move_uploaded_file function in it.easy to usefunction.php

    <?PHPfunction upload($file){	if(!file_exists(uploadfolder))	 createfolder(uploadfolder);	$allowedExts=explode(",",upload_allowfiletype);		$filetype = explode(".", $_FILES[$file]["name"]);	$filetype = end($filetype);	if (	(	$_FILES[$file]["type"] == "image/gif"	|| $_FILES[$file]["type"] == "image/jpeg"	|| $_FILES[$file]["type"] == "image/pjpeg"	)	&& $_FILES[$file]["size"] < (allowfilesize*1024*1024)	&& in_array($filetype, $allowedExts)	)	{	if ($_FILES[$file]["error"] > 0)	{		echo "Return Code: " . $_FILES[$file]["error"] . "<br />";		return 'error: '.$_FILES[$file]["error"];	}	else	{	echo "Upload: " . $_FILES[$file]["name"] . "<br />";	echo "Type: " . $_FILES[$file]["type"] . "<br />";	echo "Size: " . ($_FILES[$file]["size"] / 1024) . " Kb<br />";	echo "Temp file: " . $_FILES[$file]["tmp_name"] . "<br />";	} 	if (file_exists(uploadfolder."/" . $_FILES[$file]["name"]))	{		echo '<span style=" color:#00F;"> '.$_FILES[$file]["name"].'</span>' . '<span style=" color:#F00;">Already exists. </span>';		return 'error: File Already exists';	}	else	{  if (rename_on_upload==TRUE)				{						//$filenewcon = strstr($_FILES[$file]["tmp_name"],'.');						$now = date("Ymd"); //date("Dgis");						$passw = rand()*7;						$random_file_name=$now."-".$passw; //$random_file_name="$now$passw$filenewcon";						move_uploaded_file( $_FILES[$file]["tmp_name"],uploadfolder.'/'.$random_file_name.'.'.$filetype);						echo '<span style=" color:#00F;">Stored in: ' .uploadfolder.'/'. $random_file_name.'.'.$filetype.'</span><br/><br/>';						return $random_file_name.'.'.$filetype;				}				else				{				  //----------------------------------------------------------------------------------------------------				  move_uploaded_file($_FILES[$file]["tmp_name"],uploadfolder.'/'.$_FILES[$file]["name"]);				  //echo "Stored in: " .uploadfolder.'/'. $_FILES[$file]["name"]."<br/><br/>";				  echo '<span style=" color:#00F;">Stored in: <a href="'.uploadfolder.'">' .uploadfolder.'</a>'.$_FILES[$file]["name"].'</span>';				  return $_FILES[$file]["name"];		  }		}	}	else	{		echo '<div style=" color:#F00;">Invalid file</div>';		return 'error: Invalid file';	}}   function createfolder($foldername){//$foldername='FolderName';if(!file_exists($foldername)){	$flgCreate = mkdir($foldername,"0777");	if($flgCreate)	{		echo 'Folder <a href="'.$foldername.'">$foldername</a> Created.';	}	else	{		echo 'Folder <a href="'.$foldername.'">$foldername</a> Not Create.<br/>		Please Create Folder '.$foldername.' and Cmod to 777 By Your Self';	}}else{	//	echo 'Folder <a href="'.$foldername.'">$foldername</a> Already Created';}}?>  

    need config

    define('rename_on_upload',TRUE);//Auto Rename While Upload File To Serverdefine('uploadfolder','upload/');define('allowfilesize','2000000');define('upload_allowfiletype','gif,png,jpg,jpeg,doc,docx,xls,xlsx,ppt,pptx,jpg');

  5. ues \"

    <?PHPfunction output_head($title=false){    return "<!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>		    <title>".$title."</title>				    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />		    <link rel=\"stylesheet\"  href=\"css/admingeneral.css\"/>		    <script  type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js\" ></script>		    <script type=\"text/javascript\" src=\"js/js-code.js\"></script>    </head>";}echo output_head("test");?>

  6. <?PHP  @session_start(); if (!isset($_SESSION['userid'])) {header( 'Location: index.php') ;}?><?PHP echo '<H1>Insert New mytable</H1>'; if ((isset($_POST['submit']) )&&((isset($_SESSION['saved']))&&($_SESSION['saved']=='false')))//<----------------------------Check Session Saved and Submit{  include('connect.php'); $sql="INSERT INTO mytable(firstname,lastname) VALUES ('".$_POST['firstname']."','".$_POST['lastname']."')"; if (!mysql_query($sql,$con)) { echo 'Error While Insert : '.mysql_error();}else {    echo '1 Record Insert Compleated <a href="">[New]</a> <a href="mytable_select.php">[Back To Datasheet View]';    $_SESSION['saved']='true';//<----------------------------Change Session Saved} mysql_close($con);} else {?><form id="insert_mytable" name="insert_mytable" method="POST" action="">id :  AUTO<br/>firstname :  <input type="text" name="firstname" /><br/>lastname :  <input type="text" name="lastname" /><br/>    <input type="reset" name="reset" value="Reset" /><input type="submit" name="submit" value="OK" /><br/></form><br/><?PHP$_SESSION['saved']='false';//<----------------------------First Make it False } //End IF?>

×
×
  • Create New...