insert into database problem

Thread Solved

Join Date: Jul 2008
Posts: 39
Reputation: god_1896 is an unknown quantity at this point 
Solved Threads: 0
god_1896 god_1896 is offline Offline
Light Poster

insert into database problem

 
0
  #1
Aug 11th, 2008
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.

  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. ?>
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 791
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 109
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster

Re: insert into database problem

 
0
  #2
Aug 11th, 2008
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?)
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 145
Reputation: queenc is an unknown quantity at this point 
Solved Threads: 4
queenc's Avatar
queenc queenc is offline Offline
Junior Poster

Re: insert into database problem

 
0
  #3
Aug 11th, 2008
	 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());
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 48
Reputation: Demiloy is an unknown quantity at this point 
Solved Threads: 4
Demiloy Demiloy is offline Offline
Light Poster

Re: insert into database problem

 
0
  #4
Aug 11th, 2008
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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 39
Reputation: god_1896 is an unknown quantity at this point 
Solved Threads: 0
god_1896 god_1896 is offline Offline
Light Poster

Re: insert into database problem

 
0
  #5
Aug 11th, 2008
well thanks, but the requirement that i need to fullfil is must be a classes, thank any i try code.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 39
Reputation: god_1896 is an unknown quantity at this point 
Solved Threads: 0
god_1896 god_1896 is offline Offline
Light Poster

Re: insert into database problem

 
0
  #6
Aug 11th, 2008
hi, well, there is no error after i click the submmit button;
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 39
Reputation: god_1896 is an unknown quantity at this point 
Solved Threads: 0
god_1896 god_1896 is offline Offline
Light Poster

Re: insert into database problem

 
0
  #7
Aug 12th, 2008
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);

}
}
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC