2 Replies - 830 Views - Last Post: 22 April 2009 - 06:39 AM Rate Topic: -----

#1 SunnyVB  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 14-March 09

Store details from an HTML form in the Database

Posted 21 April 2009 - 11:27 AM

Hi guys,

I tried developing an HTML form which contains 6 fields.
but each time I sumbit the form just 2 of the fields get stored in the database.(only the email and the description get inserted).
Below is the code that does the posting. Tha Table name is R_description

require_once('admin/db2_connect.php');
			
		
			
			
			$email = GetSQLValueString($email, 'text');
			$firstname = GetSQLValueString($firstname, 'text');
			$surname = GetSQLValueString($surname, 'text');
			$address = GetSQLValueString($address, 'text');
			$description = GetSQLValueString($description, 'text');
			$phone = GetSQLValueString($phone, 'integer');
			
						
			$values = array('email' => $email, 'firstname' => $firstname, 'surname' => $surname, 'address' => $address, 'description' => $description, 'phone' => $phone);
			db_insert('R_description', $values);

			echo '
			
			<h2>Descriptions sent!</h2>
			
			
			';
		
		else {
			echo '
			<h2>there was a problem sending your form</h2>
			
			';
		


The function db_insert looks like this

function db_insert($table, $content) {
	global $comm;

	$sql = 'INSERT INTO '.$table.' (';
	foreach ($content as $column => $val) {
		$sql .= $column.', ';
	}
	$sql = substr($sql, 0, -2);
	$sql .= ') VALUES (';
	foreach ($content as $column => $val) {
		$sql .= $val.', ';
	}
	$sql = substr($sql, 0, -2);
	$sql .= ')';
	
	$result = mysql_query($sql, $comm) or die(mysql_error());
	unset($_SESSION['formINFO']);




the function GetSQLValueString looks like.


function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
	case "text":
	  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "''";
	  break;	
	case "long":
	case "int":
	case "integer":
	  $theValue = ($theValue != "") ? intval($theValue) : "''";
	  break;
	 case "defined":
	  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
	  break;
  }
  return $theValue;



Is This A Good Question/Topic? 0
  • +

Replies To: Store details from an HTML form in the Database

#2 pemcconnell  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 54
  • View blog
  • Posts: 472
  • Joined: 05-August 08

Re: Store details from an HTML form in the Database

Posted 21 April 2009 - 12:08 PM

could you post the HTML for your form please? One thing I noticed off the bat is that the values ($email, $firstname etc... don't pull in from any POST / GET form methods, so the are never assigned.

e.g.

<?php
echo $email;
?>



does nothing, whereas...

<?php
echo $_POST['email'];
?>
<form method="post" action="<?=$_SERVER['PHP_SELF'];?>">
<input type="text" name="email" />
<input type="submit" name="sub" value="save now" />
</form>



will echo out anything you type into the 'email' text field and is 'posted' back to the page
Was This Post Helpful? 1
  • +
  • -

#3 SunnyVB  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 14-March 09

Re: Store details from an HTML form in the Database

Posted 22 April 2009 - 06:39 AM

Thanks.
I did not remember to include the metheod Post for the other four.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1