Page 1 of 1

Solved: Integrating PHP and HTML

Posted: Tue Dec 12, 2006 5:05 am
by Elton
Hi,

I want to call a php code from a html "submit" button.

I write the following code:

<form action="insert.php" method="post">
....
</form>


but the insert.php file is opened and is not executed.

I want that to be executed.

Is there anything wrong or something I have to add

Thank you in advance

Re: Integrating PHP and HTML

Posted: Tue Dec 12, 2006 5:07 am
by hrubos
in the insert.php, you have to have $_POST['']

Posted: Tue Dec 12, 2006 5:10 am
by CoderGoblin
It would help if you showed us the form html code and the contents of the insert.php file...
"but the insert.php file is opened and is not executed" is a little vague... What do you mean not executed ?

Posted: Tue Dec 12, 2006 5:15 am
by Elton
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Than you for the fast response.


The insert.php is as following:

Code: Select all

<?
$username="username";
$password="password";
$database="your_database";

$first=$_POST['first'];
$last=$_POST['last'];
$phone=$_POST['phone'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$email=$_POST['email'];
$web=$_POST['web'];

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')";
mysql_query($query);

mysql_close();
?>
so $_POST exists there.

Do u mean I have to add at the end of the file again?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Dec 12, 2006 5:19 am
by matthijs
but the insert.php file is opened and is not executed
Are you sure you have PHP enabled? If not, try <?php echo 'Hello world'; ?>

Posted: Tue Dec 12, 2006 5:24 am
by Elton
When I click at Submit button, the insert.php is just opened.
Nothing happens at mysql Db
I am expecting one row to be inserted.


I think php is enabled.
If not, how can I enable that?

(just want to add that I am not very familiar with php :))

Additional info:
I have installed xamp and I can see apache and mysql running and my os is win Xp Professional SP2

Posted: Tue Dec 12, 2006 5:31 am
by CoderGoblin
use '<?php' rather than '<?' as short tags may be off as part of your settings.

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
?>
May show php errors.

In cases like this I often just insert a debug echo in to ensure things are getting to a location... like

Code: Select all

<?php
echo 'bleep<br />';
$username="username";
$password="password";
$database="your_database";
If the 'bleep' shows you know the php code is executing at that point.

Posted: Tue Dec 12, 2006 6:14 am
by Elton
Ok

I will try these

Thanks...

Posted: Thu Dec 14, 2006 5:55 am
by Elton
This problem is solved.

There was a mistake in my insert.php file.

I integrated the php code inside html tags adding also echo 'The row was inserted'
and opened that as html by calling from the Submit button of the main html form.

I saw that the row was inserted in my db

Thanks for your advices. :)