Go Back   PHP-Editors > Programming Help > PHP Programming Help

PHP Programming Help Post any question relating to PHP Programming here and hopefully someone can help.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2008-09-25, 12:56 PM
Junior Member
 
Join Date: Aug 2004
Posts: 7
santille
Default Problem PHP form

Hi,
Just a question of neophyte : could you tell me what's wrong with these codes?
I'm able to delete but not to update nor to add.
Thanks?

formulaire.php :

<html>
<body>
PHP Code:
<?
if ($_GET["action"] == "update") {
$hote "localhost";
$username "root";
$password "";

$connexion mysql_connect($hote,$username,$password);

//echo $connexion;

$nomdelabase "labase";

mysql_select_db($nomdelabase,$connexion);

$requete "SELECT * FROM latable WHERE numero = $_GET[num]";

$resultat mysql_query($requete,$connexion);
$test mysql_fetch_row($resultat);
list(
$numero,$nom,$informations,$categorie) = $test;
}
?>
<form name="leformulaire" action="execute.php
PHP Code:
<?

/*if ($_GET[action] == "update") 
{echo "?action=update&num=$_GET[num]"; }
elseif ($_GET[action] == "insert")
{echo "?action=insert";}*/

switch($_GET["action"]) {
    case 
"update":
    echo 
"?action=update&num=$_GET[num]";
    break;
    case 
"insert":
    echo 
"?action=insert";
    break;    
}
?>
" method="post">au repos
Nom :<br>
<input name="nom" type=text length=30 value=
PHP Code:
<?if ($_GET[action] == "update") {echo "'$nom'";}?>
><br>
Informations :<br>
<textarea name="informations" cols=35 rows=6 value=
PHP Code:
<?if ($_GET[action] == "update") {echo $informations;}?>
></textarea><br>
Catégorie :<br>
<input type=radio name="categorie" value="news"
PHP Code:
<?if ($categorie == "news") {echo "CHECKED";}?>
>
News<br>
<input type=radio name="categorie" value="infos"
PHP Code:
<?if ($categorie == "infos") {echo "CHECKED";}?>
>
Infos<br>
<input type=radio name="categorie" value="photos"
PHP Code:
<?if ($categorie == "photos") {echo "CHECKED";}?>
>
Photos<br>
<input type=submit value="Vazy Envoie !">
</form>
</body>
</html>

execute.php:

PHP Code:
<?
echo $_POST["nom"]."<br>";
echo 
nl2br(stripslashes($_POST["informations"]))."<br>";
echo 
$_POST["categorie"];

$hote "localhost";
$username "root";
$password "";

$connexion mysql_connect($hote,$username,$password);

//echo $connexion;

$nomdelabase "labase";

mysql_select_db($nomdelabase,$connexion);

if(
$_GET["action"] == "suppr") {
   
   
$requetespace "DELETE FROM latable WHERE numero = $_GET[num]";
   
mysql_query($requetespace,$connexion);
   } elseif (
$_GET[action] == "update") {
    
$requetespace "UPDATE latable SET numero='$_Get[num], nom='$_POST[nom], informations='$_POST[informations], categorie='$_POST[categorie] WHERE numero='$_GET[num]'";
    
mysql_query($requetespace,$connexion);}
    elseif (
$_GET[action] == "insert") {
    
$requetespace "INSERT latable SET numero='', nom='$_POST[nom], informations='$_POST[informations], categorie='$_POST[categorie]";
    
mysql_query($requetespace,$connexion);
    }

$requete "SELECT * FROM latable";


echo 
$requete;

$resultat mysql_query($requete,$connexion);
echo 
$resultat;
?>
<table border="1">
PHP Code:
<?
while ($test mysql_fetch_row($resultat)) {

//print_r($test);


list($numero,$nom,$informations,$categorie) = $test;
echo 
'<tr><td>';
echo 
$nom;
echo 
'</td><td>';
echo 
"<a href = 'execute.php?num=$numero&action=suppr'><img src = 'images/supprimer.gif'></a>";
echo 
'</td><td>';
echo 
"<a href = 'formulaire.php?num=$numero&action=update'><img src = 'images/modifier.gif'></a>";
echo 
'</td></tr>';
}
?>
<tr><td>
<a href = 'formulaire.php?action=insert'><img src='images/ajouter.gif'></a>
</td></tr>
</table>
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:12 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.