943,769 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 2579
  • PHP RSS
Jun 12th, 2008
0

Take part of URL, put into form, post to database.

Expand Post »
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['id']; ?>
<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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bigbob is offline Offline
6 posts
since Jun 2008
Jun 12th, 2008
0

Re: Take part of URL, put into form, post to database.

$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.
Reputation Points: 232
Solved Threads: 137
Practically a Master Poster
buddylee17 is offline Offline
665 posts
since Nov 2007
Jun 12th, 2008
0

Re: Take part of URL, put into form, post to database.

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 Syntax (Toggle Plain Text)
  1. <?php require_once('modulatemedia.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6. $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  7.  
  8. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  9.  
  10. switch ($theType) {
  11. case "text":
  12. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  13. break;
  14. case "long":
  15. case "int":
  16. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  17. break;
  18. case "double":
  19. $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  20. break;
  21. case "date":
  22. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  23. break;
  24. case "defined":
  25. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  26. break;
  27. }
  28. return $theValue;
  29. }
  30. }
  31.  
  32. // *** Redirect if username exists
  33. $MM_flag="MM_insert";
  34. if (isset($_POST[$MM_flag])) {
  35. $MM_dupKeyRedirect="register2.php";
  36. $loginUsername = $_POST['username'];
  37. $LoginRS__query = sprintf("SELECT username FROM members WHERE username=%s", GetSQLValueString($loginUsername, "text"));
  38. mysql_select_db($database_modulatemedia, $modulatemedia);
  39. $LoginRS=mysql_query($LoginRS__query, $modulatemedia) or die(mysql_error());
  40. $loginFoundUser = mysql_num_rows($LoginRS);
  41.  
  42. //if there is a row in the database, the username was found - can not add the requested username
  43. if($loginFoundUser){
  44. $MM_qsChar = "?";
  45. //append the username to the redirect page
  46. if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
  47. $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
  48. header ("Location: $MM_dupKeyRedirect");
  49. exit;
  50. }
  51. }
  52.  
  53. $editFormAction = $_SERVER['PHP_SELF'];
  54. if (isset($_SERVER['QUERY_STRING'])) {
  55. $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  56. }
  57.  
  58. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  59. $insertSQL = sprintf("INSERT INTO members (firstname, lastname, username, password, email, recomendedbyid) VALUES (%s, %s, %s, md5(%s), %s, %s)",
  60. GetSQLValueString($_POST['firstname'], "text"),
  61. GetSQLValueString($_POST['lastname'], "text"),
  62. GetSQLValueString($_POST['username'], "text"),
  63. GetSQLValueString($_POST['password'], "text"),
  64. GetSQLValueString($_POST['email'], "text"),
  65. GetSQLValueString($_POST['recomendedbyid'], "int"));
  66. mysql_select_db($database_modulatemedia, $modulatemedia);
  67. $Result1 = mysql_query($insertSQL, $modulatemedia) or die(mysql_error());
  68.  
  69. $insertGoTo = "stores.html";
  70. if (isset($_SERVER['QUERY_STRING'])) {
  71. $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  72. $insertGoTo .= $_SERVER['QUERY_STRING'];
  73. }
  74. header(sprintf("Location: %s", $insertGoTo));
  75. }
  76. ?>
  77.  
  78. <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  79. <label></label>
  80. <table width="241" border="0" align="center">
  81. <tr>
  82. <td colspan="2"><h2 align="center" class="style4">Registration</h2> </td>
  83. </tr>
  84. <tr>
  85. <td width="79"><span class="style3"><strong>
  86.  
  87. </strong>
  88.  
  89. </span> <span class="style2">
  90.  
  91. </span> <div align="right" class="style3"><strong>*Username:</strong></div> </td>
  92. <td width="152"><input name="username" type="text" id="username" tabindex="1" maxlength="20" /></td>
  93. </tr>
  94. <tr>
  95. <td><span class="style3"><strong>
  96.  
  97. </strong>
  98.  
  99. </span> <span class="style2">
  100.  
  101. </span> <div align="right" class="style3"><strong>*Password:</strong></div> </td>
  102. <td><input name="password" type="password" id="password" tabindex="2" maxlength="20" /></td>
  103. </tr>
  104. <tr>
  105. <td><span class="style3"><strong>
  106.  
  107. </strong>
  108.  
  109. </span> <span class="style2">
  110.  
  111. </span> <div align="right" class="style3"><strong>*Email:</strong></div> </td>
  112. <td><input name="email" type="text" id="email" tabindex="3" maxlength="50" /></td>
  113. </tr>
  114. <tr>
  115. <td class="style3"><div align="right"><strong>*Firstname:</strong></div></td>
  116. <td><input name="firstname" type="text" id="firstname" tabindex="3" maxlength="50" /></td>
  117. </tr>
  118. <tr>
  119. <td class="style3"><div align="right"><strong>*Lastname:</strong></div></td>
  120. <td><input name="lastname" type="text" id="lastname" tabindex="3" maxlength="50" /></p></td>
  121. </tr>
  122. <tr>
  123. <td><div align="right">*Referal ID</div></td>
  124. <td><?php $id = $_GET['id']; ?>
  125. <input type="int" name="id" id="textfield"?></td>
  126. </tr>
  127. <tr>
  128. <td>&nbsp;</td>
  129. <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>
  130. </tr>
  131. <tr>
  132. <td>&nbsp;</td>
  133. <td><span class="style7"><a href="file:///C|/Users/Up Stairs/Desktop/login script/login.php">login</a></span></td>
  134. </tr>
  135. <tr>
  136. <td>&nbsp;</td>
  137. <td><span class="style7">*required fields</span></td>
  138. </tr>
  139. </table>
  140. <input type="hidden" name="MM_insert" value="form1" />
  141. </form>

Thanks again for the help.
Last edited by peter_budo; Jun 16th, 2008 at 9:00 am. Reason: Keep It Organized - please use [code] tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bigbob is offline Offline
6 posts
since Jun 2008
Jun 12th, 2008
0

Re: Take part of URL, put into form, post to database.

Ok, so it should be name="recomendedbyid" and not name="id". Just skimmed over the code.
Reputation Points: 232
Solved Threads: 137
Practically a Master Poster
buddylee17 is offline Offline
665 posts
since Nov 2007
Jun 12th, 2008
0

Re: Take part of URL, put into form, post to database.

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bigbob is offline Offline
6 posts
since Jun 2008
Jun 13th, 2008
0

Re: Take part of URL, put into form, post to database.

shade out ? You mean read only ?
<input type="text" name="id" readonly>
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: insert data from box
Next Thread in PHP Forum Timeline: storing url in variable and query update error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC