943,671 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1274
  • PHP RSS
Aug 11th, 2008
0

insert into database problem

Expand Post »
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 Syntax (Toggle Plain Text)
  1. <?php
  2. require_once('connect.php');
  3.  
  4. class email {
  5.  
  6. var $mail_id; // hotel id in emailRecord Auto_increment.
  7. var $name; // hotel name in emailRecord.
  8. var $email; // hotel email id.
  9. var $phone; // hotel contact number in emailRecord.
  10. var $senderName; // Guest name.
  11. var $guestPhone; // Guest Phone number.
  12. var $guestEmail; // Guest email id.
  13. var $subject; // Guest title.
  14. var $message; // Guest message.
  15.  
  16. function email() {
  17.  
  18. $this->mail_id = $mail_id;
  19. $this->name = $name;
  20. $this->phone = $phone;
  21. $this->senderName = $senderName;
  22. $this->guestPhone = $guestPhone;
  23. $this->guestEmail = $guestEmail;
  24. $this->subject = $subject;
  25. $this->message = $message;
  26. }
  27. function storedRecord($mail_id, $name, $phone, $senderName, $guestEmail, $guestPhone, $subject, $message) {
  28.  
  29. $sql="INSERT INTO emailrecord (name, phone, senderName, guestEmail, guestPhone, subject, message)
  30. VALUES ('$name', '$phone', '$senderName', '$guestEmail', '$guestPhone', '$subject', '$message')";
  31. echo $sql;
  32. }
  33. }
  34. ?>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
god_1896 is offline Offline
39 posts
since Jul 2008
Aug 11th, 2008
0

Re: insert into database problem

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?)
Reputation Points: 395
Solved Threads: 192
Veteran Poster
darkagn is offline Offline
1,136 posts
since Aug 2007
Aug 11th, 2008
0

Re: insert into database problem

	 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());
Reputation Points: 9
Solved Threads: 4
Junior Poster
queenc is offline Offline
145 posts
since Mar 2008
Aug 11th, 2008
0

Re: insert into database problem

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:

php Syntax (Toggle Plain Text)
  1. function storedRecord($mail_id, $name, $phone, $senderName, $guestEmail, $guestPhone, $subject, $message) {
  2.  
  3. $sql="INSERT INTO emailrecord (name, phone, senderName, guestEmail, guestPhone, subject, message)
  4. VALUES ('$name', '$phone', '$senderName', '$guestEmail', '$guestPhone', '$subject', '$message')";
  5. $result = mysql_query($sql) or die(mysql_error());
  6.  
  7. return $result;
  8. }
Last edited by Demiloy; Aug 11th, 2008 at 6:31 am.
Reputation Points: 12
Solved Threads: 6
Light Poster
Demiloy is offline Offline
48 posts
since Aug 2008
Aug 11th, 2008
0

Re: insert into database problem

well thanks, but the requirement that i need to fullfil is must be a classes, thank any i try code.
Reputation Points: 10
Solved Threads: 0
Light Poster
god_1896 is offline Offline
39 posts
since Jul 2008
Aug 11th, 2008
0

Re: insert into database problem

hi, well, there is no error after i click the submmit button;
Reputation Points: 10
Solved Threads: 0
Light Poster
god_1896 is offline Offline
39 posts
since Jul 2008
Aug 12th, 2008
0

Re: insert into database problem

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);

}
}
Reputation Points: 10
Solved Threads: 0
Light Poster
god_1896 is offline Offline
39 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Need urgent assistance with php date function and recoring it into MySQL
Next Thread in PHP Forum Timeline: Need to work in echo in PHP





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC