Free Web Hosting Forum
Go Back   Free Web Hosting Forum > Website Building > Web Programming
Reload this Page no entries on my data base
Reply
 
Thread Tools Display Modes
(#1 (permalink))
Old
chat_sauvage_1's Avatar
Member
chat_sauvage_1 is on a distinguished road
 
Posts: 41
Join Date: Nov 2011
Default no entries on my data base - 01-03-2012, 04:13 PM

Hi!

I try to connect to my database
This script seem work but I have not entries on my data base
This page appears with the data to register and the submit button with the following error message
the form variables are not declared this is a message error I include at the end off script in french Inscription

Prénom:
Nom:
Adresse:
Ville:
Province:
Code postale:
Pseudo:
Adresse courriel:
Mot de passe:

Les variable du formulaire ne sont pas déclarées

PHP Code:
<?php
//on se connecte à notre base   
$base mysql_connect ('mysql16.000webhost.com''a5094737_louise1''Password');
mysql_select_db ('a5094737_echange'$base);
?>

<h1><strong>Inscription</strong></h1> 
 
Prénom:  <input type="text" name="prenom" /></br>   
  Nom: <input type="text" name="nom" /></br>    
  Adresse: <input type="text" name="adresse" /></br>    
  Ville:<input type="text" name="ville" /></br>    
  Province:<input type="text" name="province" /></br>   
  Code postale:<input type="text" name="code_postale" /> </br>   
  Pseudo:<input type="text" name="pseudo" /></br>    
  Adresse courriel:<input type="text" name="adresse_courriel" /> </br>   
  Mot de passe:<input type="password" name="mot_de_passe" /> </br>   
 
<input type="submit" name="submit" value="Valider" /></br>    
</form>   

<?php
//on teste si les variables du formulaire sont bien déclarées
if (isset($_POST['ID']) && isset($_POST['prenom']) && isset($_POST['nom'])&& isset($_POST['adresse'])&& isset($_POST['ville'])&& isset($_POST['province'])
&& isset(
$_POST['code_postale'])&& isset($_POST['pseudo'])&& isset($_POST['adresse_courriel'])&& isset($_POST['mot_de_passse'])){

//on prépare la requete pour récupérer le numero du propriétaire
$sql 'SELECT ID FROM inscription WHERE nom = "'.$POST['prenom'].'"';

//on lance la requete et on impose un message erreur
$req mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());

//on recupere le résultat sous forme de tableau
$data mysql_ferch_array($req);

//on libere espace mémoire alloué pour cette interrogation de la vase 
mysql_free_result ($req);

//on insere le tuple et au cas ou on écrira un petit messsage erreur si la requete ne passe pas bien
$sql 'INSERT INTO inscription  VALUES ("'.$data['prenom'].'", "'.$data['nom'].'", "'.$data['adresse'].'", "'.$data['ville'].'",
"'
.$data['province'].'", "'.$data['code_postale'].'", "'.$data['pseudo'].'", "'.$data['adresse_courriel'].'",
"'
.$data['mot_de_passe'].'")';

//on insere le tuple et au cas ou on ecrire un petit message erreur si la requete ne passe pas 
mysql_query ($sql) or die ('Erreur SQL ! '.$sql.'<br/>'.mysql_error());

//on ferme la connexion a la base
mysql_close();

echo 
'nous venons inserer  '.$_Post['prenom'];
}
else{
echo 
'Les variable du formulaire ne sont pas déclarées';
}
?>
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 4,609
Join Date: Jul 2009
Location: Spain
Default 01-03-2012, 04:33 PM

I think that you have not written the beginning of the form which indicates the action to perform with the data of the form and method of sending data.

You should add the beginning of the form from the line number 8. The above code would be as follows:

PHP Code:
<?php
//on se connecte à notre base   
$base mysql_connect ('mysql16.000webhost.com''a5094737_louise1''Password');
mysql_select_db ('a5094737_echange'$base);
?>

<h1><strong>Inscription</strong></h1> 
<!-- Add next line (beginer form) -->
<form method="post" id="formulario" action="<?php $_SERVER['PHP_SELF'];?>">
  
Prénom:  <input type="text" name="prenom" /></br>   
  Nom: <input type="text" name="nom" /></br>    
  Adresse: <input type="text" name="adresse" /></br>    
  Ville:<input type="text" name="ville" /></br>    
  Province:<input type="text" name="province" /></br>   
  Code postale:<input type="text" name="code_postale" /> </br>   
  Pseudo:<input type="text" name="pseudo" /></br>    
  Adresse courriel:<input type="text" name="adresse_courriel" /> </br>   
  Mot de passe:<input type="password" name="mot_de_passe" /> </br>   
 
<input type="submit" name="submit" value="Valider" /></br>    
</form>   

<?php
//on teste si les variables du formulaire sont bien déclarées
if (isset($_POST['ID']) && isset($_POST['prenom']) && isset($_POST['nom'])&& isset($_POST['adresse'])&& isset($_POST['ville'])&& isset($_POST['province'])
&& isset(
$_POST['code_postale'])&& isset($_POST['pseudo'])&& isset($_POST['adresse_courriel'])&& isset($_POST['mot_de_passse'])){

//on prépare la requete pour récupérer le numero du propriétaire
$sql 'SELECT ID FROM inscription WHERE nom = "'.$POST['prenom'].'"';

//on lance la requete et on impose un message erreur
$req mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());

//on recupere le résultat sous forme de tableau
$data mysql_ferch_array($req);

//on libere espace mémoire alloué pour cette interrogation de la vase 
mysql_free_result ($req);

//on insere le tuple et au cas ou on écrira un petit messsage erreur si la requete ne passe pas bien
$sql 'INSERT INTO inscription  VALUES ("'.$data['prenom'].'", "'.$data['nom'].'", "'.$data['adresse'].'", "'.$data['ville'].'",
"'
.$data['province'].'", "'.$data['code_postale'].'", "'.$data['pseudo'].'", "'.$data['adresse_courriel'].'",
"'
.$data['mot_de_passe'].'")';

//on insere le tuple et au cas ou on ecrire un petit message erreur si la requete ne passe pas 
mysql_query ($sql) or die ('Erreur SQL ! '.$sql.'<br/>'.mysql_error());

//on ferme la connexion a la base
mysql_close();

echo 
'nous venons inserer  '.$_Post['prenom'];
}
else{
echo 
'Les variable du formulaire ne sont pas déclarées';
}
?>


Si este mensaje te ha servido de ayuda no dudes en pulsar sobre el botón karma
Reply With Quote
(#3 (permalink))
Old
chat_sauvage_1's Avatar
Member
chat_sauvage_1 is on a distinguished road
 
Posts: 41
Join Date: Nov 2011
Default 01-03-2012, 04:52 PM

Thanks
I insert the code you sent but I still no data in my database
what is the id="formulario
Reply With Quote
(#4 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 4,609
Join Date: Jul 2009
Location: Spain
Default 01-03-2012, 05:14 PM

One moment please.

I'm reading your code carefully and do not quite understand.
Your code does the following:
1. You ask the user to fill out a form with your data. OK.
2. You check that the user has filled in all the fields (boxes) of the form. OK
3. You find in the database whose prénom ID entered by user (the query should return an item, the ID) OK
4. You save this information (ID) in an array called $data. OK
5. After you attempt to save the database you suppose different values ​​that are within the array $data, but array $data there is only one piece of information (the ID of your have find prénom before) Error
The data entered by a user in the form are stored in the array $_POST. You can try the following code:
(Corrected an error in line $ data = mysql_ferch_array ($ req)

PHP Code:
<?php
//on se connecte à notre base   
$base mysql_connect ('mysql16.000webhost.com''a5094737_louise1''Password');
mysql_select_db ('a5094737_echange'$base);
?>

<h1><strong>Inscription</strong></h1> 
<!-- Add next line (beginer form) -->
<form method="post" id="formulario" action="<?php $_SERVER['PHP_SELF'];?>">
  
Prénom:  <input type="text" name="prenom" /></br>   
  Nom: <input type="text" name="nom" /></br>    
  Adresse: <input type="text" name="adresse" /></br>    
  Ville:<input type="text" name="ville" /></br>    
  Province:<input type="text" name="province" /></br>   
  Code postale:<input type="text" name="code_postale" /> </br>   
  Pseudo:<input type="text" name="pseudo" /></br>    
  Adresse courriel:<input type="text" name="adresse_courriel" /> </br>   
  Mot de passe:<input type="password" name="mot_de_passe" /> </br>   
 
<input type="submit" name="submit" value="Valider" /></br>    
</form>   

<?php
//on teste si les variables du formulaire sont bien déclarées
if (isset($_POST['ID']) && isset($_POST['prenom']) && isset($_POST['nom'])&& isset($_POST['adresse'])&& isset($_POST['ville'])&& isset($_POST['province'])
&& isset(
$_POST['code_postale'])&& isset($_POST['pseudo'])&& isset($_POST['adresse_courriel'])&& isset($_POST['mot_de_passse'])){

//on prépare la requete pour récupérer le numero du propriétaire
$sql 'SELECT ID FROM inscription WHERE nom = "'.$POST['prenom'].'"';

//on lance la requete et on impose un message erreur
$req mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());

//on recupere le résultat sous forme de tableau
$data mysql_fetch_array($req);

//on libere espace mémoire alloué pour cette interrogation de la vase 
mysql_free_result ($req);

//on insere le tuple et au cas ou on écrira un petit messsage erreur si la requete ne passe pas bien
$sql 'INSERT INTO inscription  VALUES ("'.$_POST['prenom'].'", "'.$_POST['nom'].'", "'.$_POST['adresse'].'", "'.$_POST['ville'].'",
"'
.$_POST['province'].'", "'.$_POST['code_postale'].'", "'.$_POST['pseudo'].'", "'.$_POST['adresse_courriel'].'",
"'
.$_POST['mot_de_passe'].'")';

//on insere le tuple et au cas ou on ecrire un petit message erreur si la requete ne passe pas 
mysql_query ($sql) or die ('Erreur SQL ! '.$sql.'<br/>'.mysql_error());

//on ferme la connexion a la base
mysql_close();

echo 
'nous venons inserer  '.$_Post['prenom'];
}
else{
echo 
'Les variable du formulaire ne sont pas déclarées';
}
?>


Si este mensaje te ha servido de ayuda no dudes en pulsar sobre el botón karma
Reply With Quote
(#5 (permalink))
Old
chat_sauvage_1's Avatar
Member
chat_sauvage_1 is on a distinguished road
 
Posts: 41
Join Date: Nov 2011
Default 01-03-2012, 06:55 PM

If I understand what you're telling me in line 31 I should add other entries
sorry I am French and I have a little trouble understanding some explanation
Thanks for the help

$sql = 'SELECT ID FROM inscription WHERE nom = "'.$POST['prenom'].'"' "'.$POST['nom'].'"'; ect ect
Reply With Quote
(#6 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 4,609
Join Date: Jul 2009
Location: Spain
Default 01-03-2012, 07:07 PM

Sorry, I am Spanish and my English is not very good.

I do not understand parts of your code. On line # 30 you're looking for the ID of the user whose nom is $ _POST ['prénom']. What are you doing this?

The point of the code I wrote above is that on line #36 I have corrected an error in the function name. The function is mysql_fetch_array($ req) instead of mysql_ferch_array

In line 43 and following the data collected in the form are stored in the database. In your above code is not very well trying to keep the base data (¿ $data array?)


Si este mensaje te ha servido de ayuda no dudes en pulsar sobre el botón karma
Reply With Quote
(#7 (permalink))
Old
chat_sauvage_1's Avatar
Member
chat_sauvage_1 is on a distinguished road
 
Posts: 41
Join Date: Nov 2011
Default 01-03-2012, 07:35 PM

Thanks again I am not very good in English to

I take examples in different courses on the internet because I'm new, and with this cours I make my web page

could you give me an example when you do your form. Because it's been several weeks I 'm trying to do a inscription form all sorts of ways and nothing works
Reply With Quote
(#8 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 4,609
Join Date: Jul 2009
Location: Spain
Default 01-03-2012, 08:04 PM

Today I can not, but I will try to "fix" the code you've put it to work fine.

I just saw another problem. On the form there is no field called ID, so there is no variable $_POST['ID'] and the following condition always returns false:
PHP Code:
<?php
//on teste si les variables du formulaire sont bien déclarées
if (isset($_POST['ID']) && isset($_POST['prenom']) && isset($_POST['nom'])&& isset($_POST['adresse'])&& isset($_POST['ville'])&& isset($_POST['province'])
&& isset(
$_POST['code_postale'])&& isset($_POST['pseudo'])&& isset($_POST['adresse_courriel'])&& isset($_POST['mot_de_passse'])){
....


Si este mensaje te ha servido de ayuda no dudes en pulsar sobre el botón karma
Reply With Quote
(#9 (permalink))
Old
chat_sauvage_1's Avatar
Member
chat_sauvage_1 is on a distinguished road
 
Posts: 41
Join Date: Nov 2011
Default 01-03-2012, 08:08 PM

Ok Thanks I appreciate
have a good day
Reply With Quote
(#10 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 4,609
Join Date: Jul 2009
Location: Spain
Default 01-04-2012, 07:24 PM

You can try with next code PHP. When you copy the code, do not forget to change in your code the password to access your database.
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>INSCRIPTION</title>
<script type="text/javascript">
<!--
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' need to contain a email.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' need to contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' neet to contain number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' need to contain a value.\n'; }
    } if (errors) alert('following bugs have been produced:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
//-->
</script>
</head>
<body>
<?php

if (!isset($_POST['prenom'])) 
{
?>
<h1><strong>Inscription</strong></h1> 
<!-- Add next line (beginer form) -->
<form method="post" name="form1" id="form1" action="<?php $_SERVER['PHP_SELF'];?>" onsubmit="MM_validateForm('prenom','','R','nom','','R', 'adresse','','R','ville','','R','province','','R','code_postale','','R','pseudo','','R','adresse_courriel','','R', 'mot_de_passe','','R'); return document.MM_returnValue"> 
  <label for="prenom">Prénom:</label><input type="text" name="prenom" id="prenom" /></br>   
  <label for="nom">Nom:</label> <input type="text" name="nom" id="nom" /></br>    
  <label for="adresse">Adresse:</label> <input type="text" name="adresse" id="adresse" /></br>    
  <label for="ville">Ville:</label><input type="text" name="ville" id="ville" /></br>    
  <label for="province">Province:</label><input type="text" name="province" id="province" /></br>   
  <label for="code_postale">Code postale:</label><input type="text" name="code_postale" id="code_postale" /> </br>   
  <label for="pseudo">Pseudo:</label><input type="text" name="pseudo" id="pseudo" /></br>    
  <label for="adresse_courriel">Adresse courriel:</label><input type="text" name="adresse_courriel" id="adresse_courriel" /> </br>   
  <label for="mot_de_passe">Mot de passe:</label><input type="password" name="mot_de_passe" id="mot_de_passe" /> </br>   
 
<input type="submit" name="submit" id="submit" value="Valider" /></br>    
</form>   

<?php
} else {
//on se connecte à notre base   
$base mysql_connect ('mysql16.000webhost.com''a5094737_louise1''Password');
mysql_select_db ('a5094737_echange'$base);

//print_r($_POST);

// sanitize array $_POST for prevent sql injection attacks
foreach( $_POST as $variable => $valor ){ 
    
$_POST[$variable] = mysql_escape_string($_POST[$variable]);


//on insere le tuple et au cas ou on écrira un petit messsage erreur si la requete ne passe pas bien
$sql 'INSERT INTO inscription  VALUES ("'.$_POST['prenom'].'", "'.$_POST['nom'].'", "'.$_POST['adresse'].'", "'.$_POST['ville'].'", "'.$_POST['province'].'", "'.$_POST['code_postale'].'", "'.$_POST['pseudo'].'", "'.$_POST['adresse_courriel'].'", "'.$_POST['mot_de_passe'].'")';

//on insere le tuple et au cas ou on ecrire un petit message erreur si la requete ne passe pas 
mysql_query ($sql) or die ('Erreur SQL ! '.$sql.'<br/>'.mysql_error());

//on ferme la connexion a la base
mysql_close();

echo 
'nous venons inserer  '.$_POST['prenom'].'. <a href="yourpagehome.html">Return to home page</a>';
}

?>
</body>
</html>


Si este mensaje te ha servido de ayuda no dudes en pulsar sobre el botón karma
Reply With Quote
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 Off
Pingbacks are Off
Refbacks are Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com