Hi, I am very new to php and this forum so sorry if this has been asked over and over but I can't find anything when searching.

Anyway I have used some script I found on the net which has a register a new member form and a login form which then redirects to a secure page, all of this works fine. I have added an extra textfield in the register form which will pull the id from the url i.e. www.mysite/register.php?id=1 and then echo it back into the new textfield of the form. I have done this so if a new member has been refered by a member the id in the url will relate to the referer and I can then find out where the new member came from however when I submit the form I get this message - Notice: Undefined index: recomendedbyid in C:\wamp\www\mysite\register.php on line 65
Column 'recomendedbyid' cannot be null. It's as if it can't see the id that is showing in the textfield. The way I got the id into the textfield was by using
<td><?php $id = $_GET; ?>
<input type="int" name="textfield" id="textfield" value="<?php echo htmlentities($id);?>" /></td>
but that is all I have done, I havn't changed anything else in the orriginal code. I hope this makes sense and any help would be great.

$id = $_GET['id']; This is looking for a get variable with name='id'. Change
name="textfield"
to
name="id". I believe this will fix it.

Hi, thanks for your quick reply but I need the id to from the url to show in the text field so when I submit the form the id will post to the database. If it helps this is the code I'm using to submit the form and the form itself with the change advised from you.

<?php require_once('modulatemedia.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
  $MM_dupKeyRedirect="register2.php";
  $loginUsername = $_POST['username'];
  $LoginRS__query = sprintf("SELECT username FROM members WHERE username=%s", GetSQLValueString($loginUsername, "text"));
  mysql_select_db($database_modulatemedia, $modulatemedia);
  $LoginRS=mysql_query($LoginRS__query, $modulatemedia) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);

  //if there is a row in the database, the username was found - can not add the requested username
  if($loginFoundUser){
    $MM_qsChar = "?";
    //append the username to the redirect page
    if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
    $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
    header ("Location: $MM_dupKeyRedirect");
    exit;
  }
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO members (firstname, lastname, username, password, email, recomendedbyid) VALUES (%s, %s, %s, md5(%s), %s, %s)",
                       GetSQLValueString($_POST['firstname'], "text"),
					   GetSQLValueString($_POST['lastname'], "text"),
					   GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['recomendedbyid'], "int"));
  mysql_select_db($database_modulatemedia, $modulatemedia);
  $Result1 = mysql_query($insertSQL, $modulatemedia) or die(mysql_error());

  $insertGoTo = "stores.html";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>

<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <label></label>
  <table width="241" border="0" align="center">
    <tr>
      <td colspan="2"><h2 align="center" class="style4">Registration</h2>        </td>
    </tr>
    <tr>
      <td width="79"><span class="style3"><strong>
        
      </strong>        
        
      </span>        <span class="style2">
     
      </span>      <div align="right" class="style3"><strong>*Username:</strong></div>      </td>
      <td width="152"><input name="username" type="text" id="username" tabindex="1" maxlength="20" /></td>
    </tr>
    <tr>
      <td><span class="style3"><strong>
       
      </strong>        
        
      </span>        <span class="style2">
      
      </span>     <div align="right" class="style3"><strong>*Password:</strong></div>      </td>
      <td><input name="password" type="password" id="password" tabindex="2" maxlength="20" /></td>
    </tr>
    <tr>
      <td><span class="style3"><strong>
        
      </strong>        
       
      </span>        <span class="style2">
     
      </span>      <div align="right" class="style3"><strong>*Email:</strong></div>      </td>
      <td><input name="email" type="text" id="email" tabindex="3" maxlength="50" /></td>
    </tr>
    <tr>
      <td class="style3"><div align="right"><strong>*Firstname:</strong></div></td>
      <td><input name="firstname" type="text" id="firstname" tabindex="3" maxlength="50" /></td>
    </tr>
    <tr>
      <td class="style3"><div align="right"><strong>*Lastname:</strong></div></td>
      <td><input name="lastname" type="text" id="lastname" tabindex="3" maxlength="50" /></p></td>
    </tr>
    <tr>
      <td><div align="right">*Referal ID</div></td>
      <td><?php $id = $_GET['id']; ?>
        <input type="int" name="id" id="textfield"?></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input name="submit" type="submit" id="submit" tabindex="4" onclick="MM_validateForm('username','','R');MM_validateForm('password','','R');MM_validateForm('email','','RisEmail');return document.MM_returnValue" value="Register" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><span class="style7"><a href="file:///C|/Users/Up Stairs/Desktop/login script/login.php">login</a></span></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><span class="style7">*required fields</span></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>

Thanks again for the help.

Ok, so it should be name="recomendedbyid" and not name="id". Just skimmed over the code.

You are an absolute star that works fine and such a simple fix, always learning.
One last thing on this, do you know a way to shade out the textfield so the id that has been echo'ed back can't be typed over.

Once again many thanks.

shade out ? You mean read only ?
<input type="text" name="id" readonly>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.