Error

+1 Zeinab spears · August 5, 2014
Hi Bucky,
I have a problem each time I run this form it doesn't execute ,what i mean that each time i try to insert data into this form it doesn't store in the database (Tables always empty) , and I really don't whats the error .(It always happens to me even in Java every time i try to execute a code it never works). Please help me .






<?php

if(isset($_POST['sub1']))
$conn = mysql_connect("localhost","root","");
mysql_select_db("thenewme"); 


   $q=mysql_query("INSERT INTO  users ('id','username','email','phone','address')VALUESS ('{$_POST['ID']}','{$_POST['Name']}','{$_POST['E-mail']}','{$_POST['Phone']}','{$_POST['address']}')");


$retval = mysql_query( $q, $conn );
if(! $retval )
{
  die('Could not enter data: ' . mysql_error());
}


echo "New Customer Added";



?>
<fieldset>
<legend>Register Here:</legend>
<center>
<FORM METHOD="POST" ACTION="" > 
        <TABLE WIDTH="75%" align="center"> 
          <TR> 
             <TD>id:</TD> 
             <TD><INPUT TYPE="TEXT" SIZE="30" NAME="ID"></TD> 
          </TR> 
        
          <TR> 
             <TD> name:</TD> 
             <TD><INPUT TYPE="TEXT" SIZE="30" NAME="Name"></TD> 
          </TR> 
          <TR> 
             <TD>Email:</TD> 
             <TD><INPUT TYPE="TEXT" SIZE="30" NAME="E-mail"  id= "E-mail"></TD> 
          </TR> 
          <TR> 
             <TD>phone:</TD> 
             <TD><INPUT TYPE="TEXT" SIZE="30" NAME="Phone"  id= "Phone"></TD> 
          </TR> 
          <TR> 
             <TD>Address:</TD> 
             <TD><INPUT TYPE="TEXT" SIZE="15" NAME="address" id= "address"></TD> 
          </TR> 
          
          
          
          <TR> 
             <TD>&nbsp;</TD> 
             <TD><INPUT TYPE="submit"  name="sub1" id="sub1" VALUE="Submit"></TD> 
          </TR> 
        </TABLE>
        </FORM>
        </center> 
        </fieldset>

</body>
</html>

Post a Reply

Replies

Oldest  Newest  Rating
0 Zeinab spears · August 9, 2014
thank u all
0 JOhaL jaTT · August 6, 2014
Save as index.php i have just modified your code and it looks like this. 

<html>
<body>
<fieldset>
<legend>Register Here:</legend>
<center>
<FORM METHOD="POST" ACTION="<?php $_SERVER['PHP_SELF'];?>"> 
        <TABLE WIDTH="75%" align="center"> 
          
          <TR> 
             <TD> name:</TD> 
             <TD><INPUT TYPE="TEXT" SIZE="30" NAME="Name"></TD> 
          </TR> 
          <TR> 
             <TD>Email:</TD> 
             <TD><INPUT TYPE="TEXT" SIZE="30" NAME="Email"  id= "Email"></TD> 
          </TR> 
          <TR> 
             <TD>phone:</TD> 
             <TD><INPUT TYPE="TEXT" SIZE="30" NAME="Phone"  id= "Phone"></TD> 
          </TR> 
          <TR> 
             <TD>Address:</TD> 
             <TD><INPUT TYPE="TEXT" SIZE="15" NAME="address" id= "address"></TD> 
          </TR> 
          
          
          
          <TR> 
             <TD>&nbsp;</TD> 
             <TD><INPUT TYPE="submit"  VALUE="Submit"></TD> 
          </TR> 
        </TABLE>
        </FORM>
        </center> 
        </fieldset>

</body>
</html>
<?php

if(isset($_POST['Name'])){
$db_conx = mysqli_connect("localhost", "root", "","yourdatabase" ) or die (mysqli_error());
$name = $_POST['Name'];
$email = $_POST['Email'];
$phone = $_POST['Phone'];
$address = $_POST['address'];

$query = "INSERT INTO users(username,email,phone,address) VALUES ('$name','$email','$phone','$address')";

$retval =  mysqli_query($db_conx,$query)or die(mysqli_error());
if(! $retval )
{
  die('Could not enter data: ' . mysqli_error());
}


echo "New Customer Added";

}

?>
+1 Franz Schmidt · August 6, 2014
You have got a syntax problem: Change this line:

$q=mysql_query("INSERT INTO  users ('id','username','email','phone','address')VALUESS ('{$_POST['ID']}','{$_POST['Name']}','{$_POST['E-mail']}','{$_POST['Phone']}','{$_POST['address']}')");



to:


$q="INSERT INTO  users VALUES ('{$_POST['ID']}','{$_POST['Name']}','{$_POST['E-mail']}','{$_POST['Phone']}','{$_POST['address']}')";
  • 1

SQL & Databases

107,285 followers
About

Everything SQL and Databases related in here!

Links
Moderators
Bucky Roberts Administrator