Page 1 of 1

double entry

Posted: Tue Nov 15, 2005 12:45 am
by spitfire_esquive
hi guys, here is my code

Code: Select all

<form method="post">
<html>
	<head><title>ewan</title></head>
	<body>
<?php
	//create variable name
	$id2=$HTTP_GET_VARS['id'];
	//show the id
	echo "<p>lalabas kaya ang id? : $id2</p>";
	

?>

<br><p><input type="text" maxlength="60" name="query"></p><br>
<input type="submit" value="submit">


<?php
	//create variable names 2
	$query=$_POST['query'];
	
	//connect to mysql
	$a=mysql_pconnect('localhost','root','96051152');

	if (!$a)
	{
	echo "<p>Could not connect to mysql server.  Please try again later.</p>";
	exit;
	}

	//select db
	mysql_select_db('toby');

	$query="insert into query values 
	('".$id2."','".$query."')";
	
	$results=mysql_query($query);

	$num_results=mysql_num_rows($results);
	
	echo "<p>$num_results</p>";
?>


</body>
</html>
but the thing when i look into the table "query" there are two values entered for "$id". i checked and i can see that the first instance of loading for $id2 gets inserted into the database when the page is loaded. can you tell me the problem in the code please?

Image


many thanks!

Posted: Tue Nov 15, 2005 12:59 am
by Buddha443556
Use $_SERVER['REQUEST_METHOD'] to seperate the GET and POST.

Code: Select all

if($_SERVER['REQUEST_METHOD'] == 'GET') {

// FORM HTML HERE

} else {

// DATABASE STUFF HERE

}