/    Sign up×
Community /Pin to ProfileBookmark

Need help with a form

Hello guys,
i have a form with the code below
[B] <form action=”annuaire.php” method=”post” name=”annuaire”>
<table width=”314″ border=”0″>
<tr>
<td width=”117″><span class=”Style16″>Nom: </span></td>
<td width=”187″><input type=”text” name=”nom” /></td>
</tr>
<tr>
<td><span class=”Style16″>Pr&eacute;nom: </span></td>
<td><input type=”text” name=”prenom” /></td>
</tr>
<tr>
<td><span class=”Style16″>Poste:</span></td>
<td><input type=”text” name=”poste” /></td>
</tr>
<tr>
<td><span class=”Style16″>Direction: </span></td>
<td><input type=”text” name=”direction” /></td>
</tr>
<tr>
<td><span class=”Style16″>GSM:</span></td>
<td><input name=”gsm” type=”text” maxlength=”8″ /></td>
</tr>
<tr>
<td><span class=”Style16″>fixe:</span></td>
<td><input name=”fixe” type=”text” maxlength=”8″ /></td>
</tr>
<tr>
<td><span class=”Style16″>email:</span></td>
<td><input name=”email” type=”text” maxlength=”50″ /></td>
</tr>
</table>
<input type=”submit” name=”Submit”value=”Ajouter” />
</form>
<p>
<?php

if(isset($_POST[‘Submit’])){

$nom = $_POST[‘nom’];
$prenom = $_POST[‘prenom’];
$poste = $_POST[‘poste’];
$direction = $_POST[‘direction’];
$gsm = $_POST[‘gsm’];
$fixe = $_POST[‘fixe’];
$email = $_POST[’email’];

mysql_connect(“localhost”,”root”,””) or die(mysql_error());
mysql_select_db(“maktaba”) or die(mysql_error());
$sql = ‘INSERT INTO annuaire VALUES(“”,”‘.$nom.'”,”‘.$prenom.'”,”‘.$poste.'”,”‘.$direction.'”,”‘.$gsm.'”,”‘.$fixe.'”,”‘.$email.'”)’;
mysql_query($sql)or die (‘Erreur SQL ! ‘.$sql.'<br/>’.mysql_error());
mysql_close();[/B]

[COLOR=”DarkRed”][B]The problem is that after submitting the form, i get an error page but all the informations given in the form are added to the database.

Can anyone help plz??[/B][/COLOR]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@thraddashJan 03.2011 — Only saw one html attribute that needed spacing, and a closing bracket in the PHP code...

[code=html]<form action="annuaire.php" method="post" name="annuaire">
<table width="314" border="0">
<tr>
<td width="117"><span class="Style16">Nom: </span></td>
<td width="187"><input type="text" name="nom" /></td>
</tr>
<tr>
<td><span class="Style16">Pr&eacute;nom: </span></td>
<td><input type="text" name="prenom" /></td>
</tr>
<tr>
<td><span class="Style16">Poste:</span></td>
<td><input type="text" name="poste" /></td>
</tr>
<tr>
<td><span class="Style16">Direction: </span></td>
<td><input type="text" name="direction" /></td>
</tr>
<tr>
<td><span class="Style16">GSM:</span></td>
<td><input name="gsm" type="text" maxlength="8" /></td>
</tr>
<tr>
<td><span class="Style16">fixe:</span></td>
<td><input name="fixe" type="text" maxlength="8" /></td>
</tr>
<tr>
<td><span class="Style16">email:</span></td>
<td><input name="email" type="text" maxlength="50" /></td>
</tr>
</table>
<input type="submit" name="Submit" value="Ajouter" />
</form>[/code]


[code=php]if(isset($_POST['Submit'])) {

$nom = $_POST['nom'];
$prenom = $_POST['prenom'];
$poste = $_POST['poste'];
$direction = $_POST['direction'];
$gsm = $_POST['gsm'];
$fixe = $_POST['fixe'];
$email = $_POST['email'];

mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("maktaba") or die(mysql_error());
$sql = 'INSERT INTO annuaire (field1, field2, field3, field4, field5, field6, field7, field8) VALUES ("","'.$nom.'","'.$prenom.'","'.$poste.'","'.$direction.'","'.$gsm.'","'.$fixe.'","'.$email.'")';
mysql_query($sql) or die ('Erreur SQL ! '.$sql.'<br/>'.mysql_error());
mysql_close();
}[/code]


I'm going to recommend that you specify the field names you are inserting data into, it will help later if you add more columns in the future.
×

Success!

Help @braunprinz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...