Jump to content

Send to database error


TheSky

Recommended Posts

Hello i have some problems i hope some one can help me, first i want add new field data for like (data number) but if i add $name=$_POST['NR']; and make new

<td><div align="left">Your number</div></td>

    <td><input name="NR" type="text" size="40"></td>

and

$query=( "INSERT INTO user (uname, pw,email,NR,date_joined,ip,level) VALUES ('$name',password('$pw1'),'$email',NOW(),'$ip','Normal')");

i get no result  to database what could be the problem (database table exsist)

<?php 
if(isset($_POST['Submit'])){
//NEED TO CHECK IF FIELDS ARE FILLED IN
if( empty($_POST['name']) && (empty($_POST['email']))){
header("Location:Messages.php?msg=3"); 
exit();
}
if( empty($_POST['pw1']) && (empty($_POST['pw2']))){
header( "Location:Messages.php?msg=4" ); 
exit();
}
$name=$_POST['name'];
$email=$_POST['email'];
$pw1=$_POST['pw1'];
$pw2=$_POST['pw2'];
if("$pw1" !== "$pw2"  ){
header( "Location:Messages.php?msg=5" ); 
exit();
}
$ip = $_SERVER['REMOTE_ADDR'];
//connect to the db server , check if uname exist
include('config.php');
$query=("Select * from user where uname='$name'");
$result= mysql_query($query); 
$num=mysql_num_rows($result);
if ($num > 0) {//Username already exist
header( "Location:Messages.php?msg=6" ); 
exit();
}else{
//if username does not exist insert user details
$query=( "INSERT INTO user (uname, pw,email,date_joined,ip,level) VALUES ('$name',password('$pw1'),'$email',NOW(),'$ip','Normal')");
if (@mysql_query ($query)) {
header("location:login.php?reg=1");
exit;
}
}
mysql_close();
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/Auth.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Registration</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="styleLog.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%"  border="0" cellspacing="7" cellpadding="0">
  <tr class="temptitle">
    <td><!-- InstanceBeginEditable name="EditRegion4" -->New User Registration <!-- InstanceEndEditable --></td>
  </tr>
  <tr>
    <td><!-- InstanceBeginEditable name="EditRegion3" -->
<form name="form1" action="register.php" method="post">
<table width="657" border="0">
  <tr>
    <td width="122"><div align="left">Name</div></td>
    <td width="525"><input name="name" type="text" size="40"></td>
  </tr>
  <tr>
    <td><div align="left">Email</div></td>
    <td><input name="email" type="text" size="40"></td>
  </tr>
  <tr>
    <td><div align="left">Password</div></td>
    <td><input name="pw1" type="password" size="40"></td>
  </tr>
  <tr>
    <td ><div align="left">Confirm Password </div></td>
    <td><input name="pw2" type="password" size="40"></td>
  </tr>
  <tr>
    <td></td>
    <td> <input name="Submit" type="submit"></td>
  </tr>
</table>
  </form>
  <!-- InstanceEndEditable --></td>
  </tr>
  <tr>
    <td><div align="center">Copyright 2005 </div></td>
  </tr>
</table>
</body>
<!-- InstanceEnd --></html>

Link to comment
https://forums.phpfreaks.com/topic/232438-send-to-database-error/
Share on other sites

check the structure of the table, each field must exists in the database to be added.

you cannot do this:

$query=( "INSERT INTO user (uname, pw,email,NR,date_joined,ip,level) VALUES ('$name',password('$pw1'),'$email',NOW(),'$ip','Normal')");

because you want to insert 7 items but you only sent 6

 

should look like this:

$query=( "INSERT INTO user (uname, pw,email,NR,date_joined,ip,level) VALUES ('$name',password('$pw1'),'$email','$NR',NOW(),'$ip','Normal')");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.