Jump to content

Form methods


anevins

Recommended Posts

I don't know if this belongs here; sorry if it doesn't.

 

I'm using a method=get on a form as I need to pass information through a URL once the form has been submitted.

But I also need to INSERT some data from that form to multiple tables.

 

- How can I stop the GET from passing my other variables into the URL?

- How do I make the form submit to itself? I need to use the 'index.php?p=checkout' as this matches with a switch statement, which matches to the checkout page. The function PHP_SELF will just refresh to the index.php page, which will not have any of this checkout's page validation.

 

Here's my code:

<h2>Please enter your details</h2>
<h3>All fields required</h3>
<div id="checkout">

<?php

if (isset($_GET['checkout'])){
require_once ('./includes/connectvars.php');

$title = $_GET['title'];
$fname = $_GET['fname'];
$sname = $_GET['sname'];
$ctype = $_GET['ctype'];
$cnumber = md5($_GET['cnumber']);
$syear = $_GET['smonth'] . $_GET['syear'];
$fyear = $_GET['fmonth'] . $_GET['fyear'];
$service = $_GET['cardAuth'];
$amount = $_REQUEST[$total];
$msg = rand(1000,9999);
$api = 'd41d8cd98f00b204e9800998ecf8427e';
$b_house = $_GET['b_house'];
$b_postcode = $_GET['b_postcode'];
$b_city = $_GET['b_city'];
$b_country = $_GET['b_country'];
$d_house = $_GET['d_house'];
$d_postcode = $_GET['d_postcode'];
$d_city = $_GET['d_city'];
$d_country = $_GET['d_country'];

$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

$query = "INSERT INTO customer
	 (cust_id, first_name, last_name) VALUES ('', '$fname', '$sname')
	  ";
$query = "INSERT INTO bill 
	  (cust_id) VALUES ('')
	  ";
$query = "INSERT INTO deliver
	  (cust_id) VALUES ('')
	  ";
	  
mysqli_query($dbc, $query);
}

//.'service='.$service.'msg_id='.$msg.'num_md5='.$cnumber.'amount='.$amount.'currency=GBP'.'api_key='.$api.

?>

<form method="get" action="index.php?p=checkout">

<table>
<tr>
	<td><input type="hidden" name="cardAuth" /></td>
</tr>
	<tr>	
		<td>
			Title:
		</td>
		<td>
			<select name="title" value="<?php if (!empty($title)) echo $title; ?>" >
				<option></option>
				<option>Mr</option>
				<option>Sir</option>
				<option>Ms</option>
				<option>Miss</option>
				<option>Mrs</option>
			</select>
		</td>
	</tr>
	<tr>
		<td>
			First Name:
		</td>
		<td>
			<input type="text" name="fname" value="<?php if (!empty($fname)) echo $fname; ?>"/>
		</td>
	</tr>
	<tr>
		<td>
			Surname:
		</td>
		<td>
			<input type="text" name="sname" value="<?php if (!empty($sname)) echo $sname; ?>"/>
		</td>
	</tr>	
	<tr>
		<td> </td>
	</tr>
	<tr>
		<td>
			Card Type:
		</td>
		<td>
			<select name="ctype" value="<?php if (!empty($ctype)) echo $ctype; ?>">
				<option>mastercard</option>
				<option>visa</option>
				<option>amex</option>
				<option>solo</option>
				<option>maestro</option>
				<option>jcb</option>
				<option>diners</option>
			</select>
		</td>
	</tr>
	<tr>
		<td>
			Card Number:
		</td>
		<td>
			<input type="text" name="cnumber" value="<?php if (!empty($cnumber)) echo $cnumber; ?>"/>
		</td>
	</tr>
	<tr>
		<td>
			Valid From:
		</td>
		<td>
			<select name="smonth" value="<?php if (!empty($smonth)) echo $smonth; ?>">
				<option>01</option>
				<option>02</option>
				<option>03</option>
				<option>04</option>
				<option>05</option>
				<option>06</option>
				<option>07</option>
				<option>08</option>
				<option>09</option>
				<option>10</option>
				<option>11</option>
				<option>12</option>					
			</select>
			<select name="syear" value="<?php if (!empty($syear)) echo $syear; ?>">
				<option>07</option>
				<option>08</option>
				<option>09</option>
				<option>10</option>
				<option>11</option>					
			</select>
		</td>
	</tr>
	<tr>
		<td>
			Expires End:
		</td>
		<td>
			<select name="fmonth" value="<?php if (!empty($fmonth)) echo $fmonth; ?>">
				<option>01</option>
				<option>02</option>
				<option>03</option>
				<option>04</option>
				<option>05</option>
				<option>06</option>
				<option>07</option>
				<option>08</option>
				<option>09</option>
				<option>10</option>
				<option>11</option>
				<option>12</option>					
			</select>
			<select name="fyear" value="<?php if (!empty($fyear)) echo $fyear; ?>">
				<option>10</option>
				<option>11</option>
				<option>12</option>
				<option>13</option>
				<option>14</option>					
			</select>
		</td>
	</tr>
	<tr>
		<td><h4>Billing Address</h4></td>
	</tr>
	<tr>
		<td>
			House Name/ Number:
		</td>
		<td>
			<input type="text" name="b_house" />
		</td>
	</tr>
	<tr>
		<td>
			Postcode
		</td>
		<td>
			<input type="text" name="b_postcode" />
		</td>
	</tr>
	<tr>
		<td>
			City: 
		</td>
		<td>
			<input type="text" name="b_city" />
		</td>
	</tr>
	<tr>
		<td>
			Country:
		</td>
		<td>
			<input type="text" name="b_country" />
		</td>
	</tr>
	<tr>
		<td><h4>Delivery Address</h4></td>
	</tr>
	<tr>
		<td>
			House Name/ Number:
		</td>
		<td>
			<input type="text" name="d_house" />
		</td>
	</tr>
	<tr>
		<td>
			Postcode
		</td>
		<td>
			<input type="text" name="d_postcode" />
		</td>
	</tr>
	<tr>
		<td>
			City: 
		</td>
		<td>
			<input type="text" name="d_city" />
		</td>
	</tr>
	<tr>
		<td>
			Country:
		</td>
		<td>
			<input type="text" name="d_country" />
		</td>
	</tr>
	<tr>
		<td> </td>
	</tr>
	<tr>		
		<td> </td>
		<td>
			<input type="submit" name="checkout" value="Checkout"/>
		</td>
	</tr>		
</table>

</form>
</div>

Link to comment
Share on other sites

Personally I wouldnt advise of a get method on a form, but thats me, as its easier to influence the inputs from a 3rd party script off site. But thats me, I'd use post. Anyway

 

Make the form post to itself? as in post to the same page the script is on?

<?php echo $_SERVER['PHP_SELF']; ?>

 

but since your using variables checkout in this case as your switch as you put it.

<?php echo $_SERVER['PHP_SELF']; ?>?p=checkout

 

all $_SERVER['PHP_SELF'] does is get the file name basicly so if your on index.php or main.php or whatever .php its going to use that as the "SELF" portion, it doesnt grab variables from the URL so that you have to add as above mentioned in the second example.

 

As for how do you stop it passing whatever into the URL Im not exactly sure I understand what you mean by that, but basicly you structure the URLs to your liking

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.