3 Replies - 4169 Views - Last Post: 19 April 2012 - 07:26 AM Rate Topic: -----

#1 loveandwar  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 14
  • Joined: 08-April 12

How to call php form script in same html file

Posted 19 April 2012 - 01:21 AM

hi ,
i have written this code which is inserting some values into database , first i have created 2 files one for from.html and the other for form.php, in form.php file i written the php code which inserts values into database and then i called this form.php file in action attribute of html form.
how can i write write this php code in html form and call it in same file , and what should be the action attribute if php code is present in html file.
here is my code


<Head>
      <title>Contact form</title>
      <style type="text/css">
                  table{
                  border:1;
                  border-collapse:collapse;
                  font: normal 12px 'Lucida Grande',Verdana,sans-serif;
                  }
                  td{
                  color:#663333;font-family:verdana;
                  border-bottom: 1px solid #666;
                  padding-left:10px;
                  background-color:#F0F8FF;
                  }
                  #sub{ text-align:center;}
      </style>
</Head>
<body>
<?php
include("connection.php");
//Get data in local variable
$v_username=$_POST['username'];
$v_email=$_POST['email'];
$v_package=$_POST['mydropdown'];
$v_msg=$_POST['msg'];
// check for null values
if ($v_username==""  or $v_msg=="")
echo "All fields must be entered, hit back button and re-enter information";
else{
$query="insert into contact(username,email,package,msg) values('$v_username','$v_email','$v_package','$v_msg')";
mysql_query($query)  or die(mysql_error());
echo "Your message has been received";
}

?>
      <h2> FeedBack/Contact Form</h2>
      <form action="#" method="POST">
                  <table>
                              <tr>
                                          <td >Name*</td>
                                          <td  ><input type="text" size=40 name="username"></td>
                              </tr>
                              <tr>
                                          <td >Email</td>
                                          <td  ><input type="text" size=40 name="email"></td>
                              </tr>
							  <tr>
                                          <td >Package</td>
                                          <td  ><select name="mydropdown">
			   <option value="Fresh Milk">Fresh Milk</option>
			   <option value="Old Cheese Cheese">Old Cheese</option>
			   <option value="Hot Bread">Hot Bread</option>
			   </select></td>
                              </tr>
                              <tr>
                                          <td >Comments/Suggestions*</td>
                                          <td  ><textarea  name="msg" cols=40 rows=7></textarea> </td>
                              </tr>
                              <tr>
                                          <td colspan=2 id="sub"><input type="submit" name="submit" value="submit" ></td>
                              </tr>
                  </Table>
      </form>
</BODY>
</Html>

This post has been edited by Dormilich: 19 April 2012 - 01:22 AM
Reason for edit:: please use [code] [/code] tags when posting code


Is This A Good Question/Topic? 0
  • +

Replies To: How to call php form script in same html file

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,227
  • Joined: 08-June 10

Re: How to call php form script in same html file

Posted 19 April 2012 - 01:25 AM

there is no need to do the form processing and the formís HTML output in the same file. however, if you like, you can include() the form HTML after youíre done processing.
Was This Post Helpful? 0
  • +
  • -

#3 loveandwar  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 14
  • Joined: 08-April 12

Re: How to call php form script in same html file

Posted 19 April 2012 - 01:57 AM

View PostDormilich, on 19 April 2012 - 01:25 AM, said:

there is no need to do the form processing and the formís HTML output in the same file. however, if you like, you can include() the form HTML after youíre done processing.


i will really appreciate if you will write the method how can i do this .because i want to write both code in same file.
thanks
Was This Post Helpful? -2
  • +
  • -

#4 Tsukuyomi  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 93
  • Joined: 22-February 11

Re: How to call php form script in same html file

Posted 19 April 2012 - 07:26 AM

View Postloveandwar, on 19 April 2012 - 01:57 AM, said:

View PostDormilich, on 19 April 2012 - 01:25 AM, said:

there is no need to do the form processing and the formís HTML output in the same file. however, if you like, you can include() the form HTML after youíre done processing.


i will really appreciate if you will write the method how can i do this .because i want to write both code in same file.
thanks


http://www.w3schools...hp_includes.asp
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1