Php help Required

hello,

I am using html form for getting

Name and Message.

i-e

User will require to enter his name in one field named "name"

And his message to field name "Message"

form action is post to file "message.php"

like

Is it possible to add two files in action tab ?

i-e

??

No but you can include the database file from within message.php using php:

<?php

include "database.php";

i need to post data to two separate files.. .

message.php (which will send message)

Database.php (for saving the records) .

[quote=", post:, topic:"]

i need to post data to two separate files… .

message.php (which will send message)

Database.php (for saving the records) .

[/quote]

You can only post to one file. Say you post to only message.php. It gets the data in the $_POST[] array right? So it goes about its business and sends the message. Then once its done that it includes database.php as shown above. Then you can execute any functions in database.php passing it the appropriate $_POST variable. So the data is then saved and everyone is happy. Finally you can display a relevant “message sent” page to the user. Do you understand now?

Thanks for the help .. let me try it now

Try it :)

<?php


$name=$_POST['name'];

$message=$_POST['message'];

// Replace these with your DB user name,password and DB

$dbuser= "test";

$dbpassword= "test";

$db="test";

// keeping the date in record is a good 

$date= date('H:i, j F Y');


/* what ever you want to place here in, even can 

your layout

*/

echo "Your name is: $name 
"; echo "Your Message is: $message"; echo "Date is: $date"; /*connection to Database */ mysql_connect("localhost", "$dbuser", "$dbpassword") or die(mysql_error()); mysql_select_db("$db") or die(mysql_error()); // Now lets insert the Name,message and the in the database (record is the table) mysql_query("INSERT INTO record (name,message,date) VALUES('$name','$message','$date') ") or die(mysql_error()); ?>

[quote=", post:, topic:"]

Thanks for the help … let me try it now
[/quote]

I suggest you take a look at some coding techniques like Model View Control or MVC.



Its good that you are separating the database from the rest of the code. You should also separate the presentation so that templating is possible.

You can also study some open source projects like drupal and see how they go about their coding.

I am using this code in html form

[quote=", post:, topic:"]

[/quote]

And This code in database.php

[quote=", post:, topic:"]
<?php

define('DB_NAME', 'test');

/** MySQL database username */

define('DB_USER', 'root');

/** MySQL database password */

define('DB_PASSWORD', 'password');

/** MySQL hostname */

define('DB_HOST', 'localhost');

$phone=$_POST['FName'];

$text=$_POST['LName'];

$ip=$_POST['PHO'];

mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD) or die

('Error connecting to mysql');

$query="INSERT INTO Table (ID, phone, text, ip)VALUES ('NULL'

Mysql_query($query) or die ('Error connecting database');

Echo "Data Saved with:" .$phone. " ".$text. " ".$ip ;

?>

[/quote]

Getting this error

[quote=", post:, topic:"]
Parse error: syntax error, unexpected T_STRING in G:\xampp\htdocs\database.php on line 26
[/quote]

Please guide me where i am wrong

fix it

 mysql_query("INSERT INTO Table (ID, phone, text, ip) VALUES ('NULL'
Mysql_query($query) or die ('Error connecting database')"); </pre><p>should work now.</p>

Still not .. Getting this

[quote=", post:, topic:"]
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in G:\xampp\htdocs\database.php on line 19
[/quote]

Here it says user ODBC@localhost but i have defined user root in database.php, using xampp phpmyadmin

to minimize the conncetion errors i use the following code

//////////////////////////////

include("dbinfo.inc.php");

mysql_connect(localhost,$username,$password);

@mysql_select_db($database) or die( "Unable to select database");

//////////////

i declare username and password etc in a separate file i-e "dbinfo.inc.php" and then include in required page like login.php

[quote=", post:, topic:"]

Still not … Getting this

Here it says user ODBC@localhost but i have defined user root in database.php, using xampp phpmyadmin

[/quote]

Constants that are made using the “define” statement do not have “$” prepended to them.

So the mistake is in this line:

mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD) or die

(‘Error connecting to mysql’);

It should be:

mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die

(‘Error connecting to mysql’);

Thanks .. its working now

need any further help

i think if help is complete then post should b locked

^ Whether the thread should be closed or not is really none of your business. Stop posting needlessly or I'll ban you for spamming.

for PHP help and scripts - www.phpmagicbook.com