0

I have this html code:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Registrazione</title>
<link href="CSSProgetto.css" rel="stylesheet" type="text/css">
</head>

<body bgcolor="#000000" >
<div id="container" align="center">
<div id="logo" align="center"><img src="grafiche/NewFashion.png" width="80%" height="200px" alt=""/></div>
<p id="novitauno"> Inserire i dati per l'iscrizione: </p>

<form method="GET" action="reg.php">
<table id="reg" align="center">
    <tr>
       <td>Nome:</td>
       <td><input type="text" name="nome"> </td>
   </tr>
   <tr>
      <td>Cognome: </td>
      <td><input type="text" name="cognome"></td>
   </tr>
   <tr>
      <td>Email: </td>
      <td><input type="text" name="email"></td>
   </tr>
   <tr>
      <td>Nome Utente: </td>
      <td><input type="text" name="username"></td>
   </tr>
  <tr>
      <td>Password: </td>
      <td><input type="text" name="pass"></td>
   </tr>
  <tr><td style="position:absolute" rowspan="2" align="center"><input type="submit" value="   INVIO   "></td></tr>
</table>
</form>
</div>
</body>
</html>

and this php code:

<?php
 $localhost="127.0.0.1";
 $utente="root";
 $pass="";
 $dbname="progetto";
 $nome=$_GET['nome'];
 $cognome=$_GET['cognome'];
 $username=$_GET['username'];
 $email=$_GET['email'];
 $pss=$_GET['pass'];
  
 $link=mysql_connect($localhost,$utente,$pass);
 //if connection is not successful you will see text error
 if (!$link) {
       die('Could not connect: ' . mysql_error());
 }
 mysql_select_db($dbname, $link);
 
 $link=mysql_connect($localhost,$utente,$pass);
 //if connection is not successful you will see text error
 if (!$link) {
       die('Could not connect: ' . mysql_error());
 }
 echo 'Connected successfully';
 mysql_select_db($dbname, $link);

 $query = "SELECT CodCliente FROM utente";
 $resultnum = mysql_query($query, $link) or die('Errore...');
 // conto il numero di clienti trovati nel db
 $numrows = mysql_num_rows($resultnum); 
 
 if (isset($nome) && isset($cognome) && isset($username) && isset($email) && isset($pass)) { 
         $toinsert = "INSERT INTO utente (Nome, Cognome, Username, Email, Pass, CodCliente)
    VALUES('$nome','$cognome', '$username', '$email', '$pass', '$numrows')";

 //declare in the order variable
  $result = mysql_query($toinsert, $link); //order executes
  if($result){
   echo 'Registrazione avvenuta correttamente';
  }else{
   echo 'Errore nella registrazione';
  }
 } 
 else echo 'No isset!';
 mysql_close($link);
?>

I don't understand what I'm doing wrong.

The errors are:

Notice: Undefined index: nome in D:\xampp\htdocs\Progetto\reg.php on line 6

Notice: Undefined index: cognome in D:\xampp\htdocs\Progetto\reg.php on line 7

Notice: Undefined index: username in D:\xampp\htdocs\Progetto\reg.php on line 8

Notice: Undefined index: email in D:\xampp\htdocs\Progetto\reg.php on line 9

Notice: Undefined index: pass in D:\xampp\htdocs\Progetto\reg.php on line 10 Connected successfullyNo isset!

Thanks for help D:

  • the reason is it does not know when it was submitted when it is submitted it can get those indexs – The Beast Dec 31 '15 at 14:52
  • 1
    Just as an aside - you're using `GET` to submit your form; this puts the submitted data into the URL. One of the fields that you've got in your form is a password field, which is very insecure. – andrewsi Dec 31 '15 at 14:53
  • like if you were using POST you would do this PHP you would do: if(isset($_POST['submit'])) – The Beast Dec 31 '15 at 14:53
  • if it is not submitted it can not get that data – The Beast Dec 31 '15 at 14:54

0 Answers0