Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

posting problem with action parameter !!

Status
Not open for further replies.

mnassih

IS-IT--Management
Jun 29, 2005
64
0
0
SE
My problem is :
I have a query like :
----
$query = "INSERT INTO conge (matricule, nom, responsable, de, a, approuver) VALUES ('$matricule','$nom','$resp', '$de','$a','$approuver')";

mysql_query($query) or die(mysql_error());
-----
when I use :
<form action=demapprobconge.php method="POST">
the data does not insered in the database.

but when I use :

<form method="POST"> -Without action parameter-

It works !!

please help.
 
Hi

mnassih said:
the data does not insered in the database.
You have to debug it and post more details. That is not enough for us to give a diagnosis.

In meantime I would try :
Code:
<form action="[red]<?php echo $_SERVER[PHP_SELF]; ?>[/red]" method="post">
[small]Note : "You should always use quotes around a string literal array index." - PHP docs[/small]

Feherke.
 
and remember to enquote the html tag parameters in double quotes
and escape your data before inserting it into a database.
 
Now :

when I use :
<form action=demapprobconge.php method="POST">

the data is insered in the database. but the date is insered like 0000-00-00

but when I use :

<form method="POST"> -Without action parameter-

the date is insered correctly


with <form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="post">

it works
please help.
 
Hi

Well, you did not forced yourself too much... That is almost the same information as before.

Anyway, that 0000-00-00 gave me an idea. Do you have more than one [tt]input[/tt] with the same [tt]name[/tt] ?

If that page is available on-line, would help us to have an idea what you done there. I think the problem is on the client side.

Feherke.
 
Hi,
many thanks feherke,
here the code :
-------------
<?php
require($_SERVER["DOCUMENT_ROOT"]."/gestionconges/config/db_config.php");
mysql_connect("$db_host","$db_user","$db_password");
mysql_select_db("congedb");

echo "<h3>Demande de congé :</h3>";

$matricule = $_GET["matricule"];

$len = strlen($matricule);
if ($len > 0)
{
$sql = "select matricule, nomprenom, departement, responsable, nbrejoursan, nbrejoursrest FROM employees WHERE matricule = $matricule";
$requeteid = mysql_query($sql) or die("Erreur SQL " . mysql_errno() . ": " . mysql_error() . " dans la requete " . $sql);
$ligne=mysql_fetch_assoc($requeteid);
echo "<p></p>";
echo "Matricule : ";
echo $matricule;
echo " <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nom : ", $ligne["nomprenom"], " </td>";
echo " <td><p>Département : ", $ligne["departement"], " </td>";
echo " <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Responsable : ", $ligne["responsable"], " </td></p>";
echo " <td><p>Nombre de jours annuel : ", $ligne["nbrejoursan"], " </td>";
echo " <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nombre de jours restant : ", $ligne["nbrejoursrest"], " </td></p>";
echo "</tr>\n";
$nom = $ligne["nomprenom"];
$resp = $ligne["responsable"];
$de = $_POST["de"];
$a = $_POST["a"];
$approuver = '0';

$query = "INSERT INTO conge (matricule, nom, responsable, de, a, approuver) VALUES ('$matricule','$nom','$resp', '$de','$a','$approuver')";

mysql_query($query) or die(mysql_error());

}
?>

<form action= demapprobconge.php method="POST">

<center>
<table>

<tr>
<td>
De :
</td>
<td>
<input type="date" name="de" size="8">
</td>
</tr>

<tr>
<td>
A :
</td>
<td>
<input type="date" name="a" size="8">
</td>
</tr>


<tr>
<td>
<input type="reset" value="Annuler" />
</td>

<td>
<input type="submit" value="Demander Approbation" />
</td>

</td>
</tr>

</table>
</center>
</form>

-------------
demapprobconge.php is :

<?php

Echo " Votre demande est bien envoyé à votre supérieur pour approbation";

?>
-- What exactly I want to do is : if mysql_query is true the code display demapprobconge.php.



 
Hi

Seems that my theory of HTML [tt]form[/tt] error is not correct.

jpadie mentioned two errors. You should correct them first, to eliminate them as source of the problem.

Feherke.
 
Feherke, my comp, please explain more
 
Hello Feherke,
The 2 inputs that I have are :
<input type="date" name="de" size="8">
<input type="date" name="a" size="8">
and with different name !
 
what is an input type of date? i've never heard of this?

do you not mean "text"?

Code:
<input type="text" name="de" />
 
I change it to text, but I had always 0000-00-00 as a data in the date field in the table- in the database-.
 
that is because the date format that you are using is probably incorrect.

tu sais qu'il doit etre dans le format YYYY-MM-DD pour etre utilise dans b-d.

try this as an alternative

Code:
<?php
require($_SERVER["DOCUMENT_ROOT"]."/gestionconges/config/db_config.php");
mysql_connect("$db_host","$db_user","$db_password") or die(mysql_error());
mysql_select_db("congedb") or die (mysql_error());

echo "<h3>Demande de congé :</h3>";

$matricule = isset($_GET["matricule"]) ? mysql_real_escape_string(trim($_GET['matricule'] )) : "";

$len = strlen($matricule);
if ($len > 0) {
	processHolidayRequest();
} else {
	displayForm();
}

function processHolidayRequest() {
	$sql = "	select 
					matricule, 
					nomprenom, 
					departement, 
					responsable, 
					nbrejoursan, 
					nbrejoursrest 
				FROM 
					employees 
				WHERE 
					matricule = '$matricule'";
					
	$requeteid = mysql_query($sql) or die("Erreur SQL " . mysql_errno() . ": " . mysql_error() . " dans la requete " . $sql);

	$ligne=mysql_fetch_assoc($requeteid);

	echo "<p></p>";
	echo "Matricule : ";
	echo $matricule;
	echo " <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nom : ", $ligne["nomprenom"], " </td>";
	echo " <td><p>Département : ", $ligne["departement"], " </td>";
	echo " <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Responsable : ", $ligne["responsable"], " </td></p>";
	echo " <td><p>Nombre de jours annuel : ", $ligne["nbrejoursan"], " </td>";
	echo " <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nombre de jours restant : ", $ligne["nbrejoursrest"], " </td></p>";
	echo "</tr>\n";

	//set up variables for use in the update query
	$nom = mysql_real_escape_string($ligne["nomprenom"]);
	$resp = mysql_real_escape_string($ligne["responsable"]);
	$de =  isset($_POST["de"])? $_POST['de'] : ''; 
	$a =  isset($_POST["a"])? $_POST['a'] : '';;
	$approuver = '0';

	//convert the dates
	$de = date("Y-m-d", strtotime(trim($de)));
	$a = date("Y-m-d", strtotime(trim($a)));


	$query = "	INSERT 
				INTO conge 
				set
					matricule = '$matricule',
					nom = '$nom',
					responsable = '$resp', 
					de = '$de',
					a = '$a',
					approuver = '$approuver'"; 

	mysql_query($query) or die(mysql_error() . "<br/>sql etait: $query<br/>");
	showSuccessMessage();
} //end process function

function displayForm() {
?>
<form  action="<?=$_SERVER['PHP_SELF']?>" method="POST" enctype="application/x-[URL unfurl="true"]www-form-urlencoded">[/URL]

<center>
<table>

<tr>
<td>
De :
</td>
<td>
<input type="text" name="de" size="8">
</td>
</tr>

<tr>
<td>
A :
</td>
<td>
<input type="text" name="a" size="8">
</td>
</tr>


<tr>
<td>
<input type="reset" value="Annuler" />
</td>

<td>
<input type="submit" value="Demander Approbation" />
</td>

</td>
</tr>

</table>
</center>
</form>
<? } 

function showSuccessMessage(){
	echo " Votre demande est bien envoyé à votre supérieur pour approbation";
}

?>
 
Hi jpadie,

It works with action="<?=$_SERVER['PHP_SELF']?>" but when action= "demapprobconge.php" it does not.
many thanks for the support.
 
look, the action of a form is to deliver the contents of a form to a server side script.

above you say that demapprobconge.php contains only the following

Code:
<?php

Echo " Votre demande est bien envoyé à votre supérieur pour approbation";

?>

this does not do anything with the incoming data. the script that i provided you is called an auto-processing script. that is to say that it serves the form and handles the receipt of the form. Par contre, you have the processing code in the wrong file.


 
Hi jpadie,

Your code give me a some errors, I made an other small test :

I create testdate table :
numero : INT autoincrement.
Datedeb : Date.

and I execute the code test.php:
---
<?php

require($_SERVER["DOCUMENT_ROOT"]."/gestionconges/config/db_config.php");
mysql_connect("$db_host","$db_user","$db_password");
mysql_select_db("congedb");
echo "<h3>Demande de congé :</h3>";

$datedebut = $_POST["datedebut"];


$datedebut = date("YYYY-mm-d", strtotime(trim($datedebut)));


$result = mysql_query("INSERT INTO testdate (datedeb) VALUES ('$datedebut')");

if (!$result) {
die('Requête invalide : ' . mysql_error());
}
else
{

echo "<form action='demapprobconge.php' method='post'>";

}


?>

<form action='<?php echo $_SERVER[PHP_SELF]; ?>' method="post">


<center>
<table>

<tr>
<td>
De :
</td>
<td>
<input type="text" name="datedebut" size="8">
</td>
</tr>


<tr>
<td>
<input type="reset" value="Annuler" />
</td>

<td>
<input type="submit" value="Demander Approbation" />
</td>

</td>
</tr>

</table>
</center>
</form>

---
When I display the table i got :

Numero : 1
datedeb : 0000-00-00
--

Can you please debug this small code in your machine and try to see why I got always 0000-00-00.

 
look carefully at the code i posted. particularly this line

Code:
 $de = date("Y-m-d", strtotime(trim($de)));
 
Yes, I changed this line to

$de = date("Y-m-d", strtotime(trim($de)));

now the date that I had in the database is always :
1970-01-01 !!
 
Very strange jpadie,

My $de is like : 2007-08-08 as I entered it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top