hi all;

I create a php classes to insert my data into database, but it doest work, please help me with this. here is my whole code.

<?php
require_once('connect.php');

class email {
	
		var $mail_id; 	  // hotel id in emailRecord Auto_increment.
		var $name; 		  // hotel name in emailRecord.
		var $email;       // hotel email id.
		var $phone; 	  // hotel contact number in emailRecord.
		var $senderName;  // Guest name.
		var $guestPhone;  // Guest Phone number.
		var $guestEmail;  // Guest email id.
		var $subject;     // Guest title.
		var $message;     // Guest message.
	
	function email() {
		
			$this->mail_id = $mail_id;
			$this->name = $name;
			$this->phone = $phone;
			$this->senderName = $senderName;
			$this->guestPhone = $guestPhone;
			$this->guestEmail = $guestEmail;
			$this->subject = $subject;
			$this->message = $message;
	}
	function storedRecord($mail_id, $name, $phone, $senderName, $guestEmail, $guestPhone, $subject, $message) {
			
			$sql="INSERT INTO emailrecord (name, phone, senderName, guestEmail, guestPhone, subject, message) 
				  VALUES ('$name', '$phone', '$senderName', '$guestEmail', '$guestPhone', '$subject', '$message')";
			echo $sql;
		}
	}
?>

The only thing I can see wrong with your sql statement is that you don't need single quotes around your variables. But I wouldn't think that would cause an error. What happens when you call the storedRecord function? (It should just print the sql statement to the screen, but what is being printed?)

mysql_query("INSERT INTO emailrecord (name, phone, senderName, guestEmail, guestPhone, subject, message) 
	VALUES ('$name', '$phone', '$senderName', '$guestEmail', '$guestPhone', '$subject', '$message')") or die("ERROR:".mysql_error());

Ok...

1. When you do "$this->mail_id = $mail_id;", you're referencing the same thing. $this->mail_id is used inside functions to reference the variables in the parent class. So, basically, your email() function is unneeded.

2. Also, if all you're doing is echoing your query, and not using mysql_query, then obviously you're not going to be doing any action is your database.

I think a much simpler way to do this, without classes, is:

function storedRecord($mail_id, $name, $phone, $senderName, $guestEmail, $guestPhone, $subject, $message) {
			
			$sql="INSERT INTO emailrecord (name, phone, senderName, guestEmail, guestPhone, subject, message) 
				  VALUES ('$name', '$phone', '$senderName', '$guestEmail', '$guestPhone', '$subject', '$message')";
			$result = mysql_query($sql) or die(mysql_error());

return $result;
		}

well thanks, but the requirement that i need to fullfil is must be a classes, thank any i try code.

hi, well, there is no error after i click the submmit button;

hi all;

thanks alot for all the replies, I finnaly solve ny problem, here is the whole code, actually I made a changes and add the line of code. hope this code will be more perfect as challenge.

class request {


var $mail_id;     // hotel id in emailRecord Auto_increment.
var $name;        // hotel name in emailRecord.
var $email;       // hotel email id.
var $phone;       // hotel contact number in emailRecord.
var $senderName;  // Guest name.
var $guestPhone;  // Guest Phone number.
var $guestEmail;  // Guest email id.
var $subject;     // Guest title.
var $message;     // Guest message.


// this get the data


function store($input) {


// this will perform an insertion


$sql = "insert into emailrecord (name, phone, senderName, guestEmail, guestPhone, subject, message)
values
('$input->name', '$input->phone', '$input->senderName', '$input->guestEmail', '$input->guestPhone', '$input->subject', '$input->message')";


$result = mysql_query($sql);


}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.