Solved: Integrating PHP and HTML

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Elton
Forum Newbie
Posts: 5
Joined: Tue Dec 12, 2006 4:11 am

Solved: Integrating PHP and HTML

Post 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
Last edited by Elton on Thu Dec 14, 2006 5:51 am, edited 3 times in total.
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

Re: Integrating PHP and HTML

Post by hrubos »

in the insert.php, you have to have $_POST['']
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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 ?
Elton
Forum Newbie
Posts: 5
Joined: Tue Dec 12, 2006 4:11 am

Post 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]
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post 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'; ?>
Elton
Forum Newbie
Posts: 5
Joined: Tue Dec 12, 2006 4:11 am

Post 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
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
Elton
Forum Newbie
Posts: 5
Joined: Tue Dec 12, 2006 4:11 am

Post by Elton »

Ok

I will try these

Thanks...
Elton
Forum Newbie
Posts: 5
Joined: Tue Dec 12, 2006 4:11 am

Post 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. :)
Post Reply