Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Please check my code

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Please check my code

Postby coolamigo » Sat Jul 20, 2013 5:59 am

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");

$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.

Please Help :(
coolamigo
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sat Jul 20, 2013 5:46 am

Re: Please check my code

Postby johnj » Sun Jul 21, 2013 9:38 pm

try a simple code and make sure php is properly installed on your computer.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Please check my code

Postby Strider64 » Mon Jul 22, 2013 3:59 am

Code: Select all
<?php

// Show all information, defaults to INFO_ALL
phpinfo();

// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);

?>
User avatar
Strider64
New php-forum User
New php-forum User
 
Posts: 62
Joined: Sat Mar 23, 2013 8:24 am

Re: Please check my code

Postby coolamigo » Tue Jul 23, 2013 12:35 am

Got it!

I was double clicking the HTML file :D
coolamigo
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sat Jul 20, 2013 5:46 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.