Return to Snippet

Revision: 43579
at October 8, 2011 01:02 by kidmizere


Updated Code
<?php
session_start();
 
	$fields = '';
	$values = '';
	$sql = display_post_get();
 
echo "<br>strSQL:<br>" . $sql;
 
 
function display_post_get() { 
   if ($_POST) { 
      while (list($result_nme, $result_val) = each($_POST)) { 
 		$fields .= $result_nme . "," ;
		$values .= $result_val . "','" ;
      } 
	$fields=substr($fields,0,strlen($fields)-5);
	$values=substr($values,0,strlen($values)-12);  
	echo "Field Count : " . count(explode(",", $fields)) . "<p />";
	echo "Fields: " . $fields;
	echo "<p />Value Count : " . count(explode(",", $values)) . "<p />";
	echo "Values: " . $values . "<p />";
	$strSQL = "Insert into YOURDB ($fields) VALUES ('$values)";
	return $strSQL;
	} 
   if ($_GET) { 
      while (list($result_nme, $result_val) = each($_GET)) { 
 		$fields .= $result_nme . "," ;
		$values .= $result_val . "','" ;
      } 
	$fields=substr($fields,0,strlen($fields)-5);
	$values=substr($values,0,strlen($values)-12);  
	echo "Field Count : " . count(explode(",", $fields)) . "<p />";
	echo "Fields: " . $fields;
	echo "<p />Value Count : " . count(explode(",", $values)) . "<p />";
	echo "Values: " . $values . "<p />";
	$strSQL = "Insert into YOURDB ($fields) VALUES ('$values)";
	return $strSQL;
   } 
} 
 
?>

Revision: 43578
at October 8, 2011 00:58 by kidmizere


Updated Code
<?php
session_start();
 
	$fields = '';
	$values = '';
	$sql = display_post_get();
 
echo "<br>strSQL:<br>" . $sql;
 
 
function display_post_get() { 
   if ($_POST) { 
      while (list($result_nme, $result_val) = each($_POST)) { 
 		$fields .= $result_nme . "," ;
		$values .= $result_val . "','" ;
      } 
	$fields=substr($fields,0,strlen($fields)-5);
	$values=substr($values,0,strlen($values)-12);  
	echo "<br>Count Fields: " . count(explode(",", $fields)) . "<br>";
	echo "Fields: " . $fields;
	echo "<br>Count Values: " . count(explode(",", $values)) . "<br>";
	echo "<br>Values: " . $values;
	$strSQL = "Insert into YOURDB ($fields) VALUES ('$values)";
	return $strSQL;
	} 
   if ($_GET) { 
      while (list($result_nme, $result_val) = each($_GET)) { 
 		$fields .= $result_nme . "," ;
		$values .= $result_val . "','" ;
      } 
	$fields=substr($fields,0,strlen($fields)-5);
	$values=substr($values,0,strlen($values)-12);  
	echo "<br>Count Fields: " . count(explode(",", $fields)) . "<br>";
	echo "Fields: " . $fields;
	echo "<br>Count Values: " . count(explode(",", $values)) . "<br>";
	echo "<br>Values: " . $values;
	$strSQL = "Insert into YOURDB ($fields) VALUES ('$values)";
	return $strSQL;
   } 
} 
 
?>

Revision: 43577
at March 27, 2011 01:40 by kidmizere


Initial Code
<?php
session_start();

	$fields = '';
	$values = '';
	$sql = display_post_get();

echo "<br>strSQL:<br>" . $sql;


function display_post_get() { 
   if ($_POST) { 
      while (list($result_nme, $result_val) = each($_POST)) { 
 		$fields .= $result_nme . "," ;
		$values .= $result_val . "," ;
      } 
	$fields=substr($fields,0,strlen($fields)-1);
	$values=substr($values,0,strlen($values)-1);  
	echo "Fields: " . $fields;
	echo "<br>Values: " . $values;
	$strSQL = "Insert into YOURDB ($fields) VALUES ($values)";
	return $strSQL;
	} 
   if ($_GET) { 
      while (list($result_nme, $result_val) = each($_GET)) { 
 		$fields .= $result_nme . "," ;
		$values .= $result_val . "," ;
      } 
	$fields=substr($fields,0,strlen($fields)-1);
	$values=substr($values,0,strlen($values)-1);  
	echo "Fields: " . $fields;
	echo "<br>Values: " . $values;
	$strSQL = "Insert into YOURDB ($fields) VALUES ($values)";
	return $strSQL;
   } 
} 

?>

Initial URL

                                

Initial Description
This generates a simple insert statement for mysql based on all the variables in $_GET or $_POST using a simple page. It does not do the inserts although that is a simple addition - just builds and displays your insert statement.

Initial Title
CREATE INSERT FOR ALL FORM VARIABLES (POST /GET) INTO MYSQL USING PHP

Initial Tags
form, mysql, php

Initial Language
PHP