0

How to send data from one page to another without using form? I am getting id and type by GET method

 <a href="form.php?id=<?php echo $_GET['id']."&".$_GET['type']; ?>" class="orderbtn">Order Now</a> 

When I go to form.php, I fill the form and click on the submit button my form page code is below

form.php

<div id="form"> <p class="rf">*Required Fields </p> <form action="formsubmitted.php" onsubmit="return formValidate()" method="post" name="myform"> <span class="required" title="Required Field">*</span> <span style="font-size:16px; color:#000; font-family:Arial, Helvetica, sans-serif;">Name: </span> <input id="name" title="Enter Your Full Name" type="text" name="name" autofocus="autofocus" required="required" value=""/><br/> <span class="required" title="Required Field">*</span> <span style="font-size:16px;color:#000; font-family:Arial, Helvetica, sans-serif;padding-right:10px;">Email:</span> <input id="email" type="email" name="email" required="required" placeholder="[email protected]"/><br/> <span class="required" title="Required Field">*</span> <span style="font-size:16px;color:#000; font-family:Arial, Helvetica, sans-serif;">Address:</span> <input id="address" title="Enter Address" type="text" name="address" required="required" value=""/><br/> <span class="required" title="Required Field">*</span> <span style="font-size:16px;color:#000; font-family:Arial, Helvetica, sans-serif;">Contact Number:</span> <input id="contactno" title="Enter Number" type="text" name="contact" required="required" value=""/><br/> <input id="submit" name="submit" type="submit" value="Submit"/></span> </form> </div> 

When I submitted it goes to formsubmitted.php page where I am inserting data into database using post method i.e.

formsubmitted.php

 <?php $connection = mysql_connect("localhost","root",""); $select_db = mysql_select_db("fashion",$connection); if(!$connection) { die ("Could not Connect".mysql_error()); } $query = "INSERT INTO `order` (flname,email,address,contact) VALUES ('{$_POST['name']}','{$_POST['email']}','{$_POST['address']}','{$_POST['contact']}');"; echo $query . "<br />"; $res = mysql_query($query,$connection); if(!$res) {die("Could Not Enter Data".mysql_error());} else { echo "Enter Data Successfully."; } ?> 

I want to insert the id and type which I am getting in the url in form page how can i do that?

3
  • 1
    I see inline-styling and usage of mysql_query both of which are bad practices in web design. I think you should be concerned about those for now. Commented Dec 12, 2013 at 17:38
  • Your code provides an excellent example of how to construct dangerous SQL queries. stackoverflow.com/questions/60174/… Commented Dec 12, 2013 at 17:44
  • yes u both r rights but next time i will be surely not doing that designing Commented Dec 12, 2013 at 19:10

2 Answers 2

1

You need to add &type=

 <a href="form.php?id=<?php echo $_GET['id']."&type=".$_GET['type']; ?>" class="orderbtn">Order Now</a> 

...................................................................................................^

You need use to $_GET in form.php

 <?php $id = $_GET['id']; $type = $_GET['type']; ?> <form action="formsubmitted.php" onsubmit="return formValidate()" method="post" name="myform"> ...... <input name="id" type="hidden" value="<?php echo $id;?>"> <input name="type" type="hidden" value="<?php echo $type;?>"> </form> 

in formsubmitted.php:

 <?php echo $_POST['id']; echo $_POST['type']; ?> 
Sign up to request clarification or add additional context in comments.

9 Comments

i do that but it is inserting the id value in type coloumn in database and id is 0 when a new record is added..
in formsubmitted.php, use print_r($_POST); to verify the posted value
it is printing now like this Array ( [name] => Imran Mushtaq [email] => [email protected] [address] => 3280y28y [contact] => 73427343 [id] => 7 [type] => winter [submit] => Submit ) but the same problem id colomn=0 and Type colomn has the value of id...
[id] => 7 [type] => winter, it carried and posted the proper values.
how you say id=0 ? can you show your formsubmitted.php file source'
|
0

You can send this params in a hidden field As this:

<input type="hidden" name="type" id="type" value="<?php echo $_GET['type'];?>"/> 

And you need to add protection against XSS

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.