PHP code returned on webpage
Posted by: coolamigo (39.47.198.---)
Date: July 22, 2013 11:34AM

I am learning Php and am using WAMP

Following is my html code as form.html
<html>
<body>

<form action="insert.php" method="post">
First Name: <input type="text" name="first"><br>
Last Name: <input type="text" name="last"><br>
Phone: <input type="text" name="phone"><br>
Mobile: <input type="text" name="mobile"><br>
Fax: <input type="text" name="fax"><br>
E-mail: <input type="text" name="email"><br>
Web: <input type="text" name="web"><br>
<input type="Submit">
</form>

</body>
</html>

and Php code as insert.php

<?php
$user="root";
$password="";
$database="phpdata";

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

mysql_connect("",$user,$password);
@mysql_select_db($database) or die( "Unable to select database"winking smiley;

$query="CREATE TABLE contacts (id int(6) NOT NULL auto_increment,first varchar(15) NOT NULL,last varchar(15) NOT NULL,phone varchar(20) NOT NULL,mobile varchar(20) NOT NULL,fax varchar(20) NOT NULL,email varchar(30) NOT NULL,web varchar(30) NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))";
$query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')";
mysql_query($query);

mysql_close();
?>

When I fill the form and submit, it displays the PhP code which is kind of strange. Also when I enclose the php code in html, nothing is displayed

Please Help sad smiley

Options: ReplyQuote
Re: PHP code returned on webpage
Posted by: RiggsFolly (---.as13285.net)
Date: July 22, 2013 12:10PM

Stop doubleclicking on the files from explorer.

Use your browser and put this as the address, i assume you are coding in the c:\wamp\www folder so it would be 'http://localhost/form.html'

This will server tha pages via Apache ( which doubleclicking on the filename in explorer will not ). You need apache to see the PHP code and therefore pass it to the PHP interpreter for execution.


Additional Note:

Dont code in the www folder. Create yourself a subfolder under the www folder, one for each project you undertake. Then you would use the address 'http://localhost/project1/form.html' for example.

Options: ReplyQuote
Re: PHP code returned on webpage
Posted by: ClearModule.com (---.mysmart.ie)
Date: July 22, 2013 08:25PM

Are known file extensions hidden in Windows? Is your form.php really form.php.txt? There are also a few errors in your code. You should not be creating the table in your code. You create it once manually and then insert into the table each time. Have a look at [www.youtube.com] in particular 9 and 10. These videos will show you how to setup your database in SQlBuddy and insert data in to the table.

Options: ReplyQuote
Re: PHP code returned on webpage
Posted by: coolamigo (65.49.14.---)
Date: July 23, 2013 09:23AM

Thank you soooo much.
Yes there are errors yet but the main problem is solved smiling smiley

Options: ReplyQuote


Sorry, only registered users may post in this forum.