| | |
insert into database problem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jul 2008
Posts: 39
Reputation:
Solved Threads: 0
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.
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)
<?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?)
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. 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());•
•
Join Date: Aug 2008
Posts: 48
Reputation:
Solved Threads: 4
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. 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)
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; }
Last edited by Demiloy; Aug 11th, 2008 at 6:31 am.
•
•
Join Date: Jul 2008
Posts: 39
Reputation:
Solved Threads: 0
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);
}
}
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);
}
}
![]() |
Similar Threads
- MSSql 2000 Unable to insert into database (MS SQL)
- Insert Into Syntax Problem (MS SQL)
- Please help(Problem in insertion data to database) (JSP)
- MySQL insert statement (MySQL)
- problem in Start time and end time reservation (JSP)
- Error connecting to database (ASP.NET)
- problem with commondialog (Visual Basic 4 / 5 / 6)
- CDBException can't solve problem (ASP.NET)
- adding a database to my webpage (PHP)
Other Threads in the PHP Forum
- Previous Thread: write to an Exel file
- Next Thread: Need to work in echo in PHP
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube





