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

Thread Solved

Join Date: Jun 2008
Posts: 6
Reputation: bigbob is an unknown quantity at this point 
Solved Threads: 0
bigbob bigbob is offline Offline
Newbie Poster

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

 
0
  #1
Jun 12th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

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

 
0
  #2
Jun 12th, 2008
$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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 6
Reputation: bigbob is an unknown quantity at this point 
Solved Threads: 0
bigbob bigbob is offline Offline
Newbie Poster

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

 
0
  #3
Jun 12th, 2008
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.

  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

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

 
0
  #4
Jun 12th, 2008
Ok, so it should be name="recomendedbyid" and not name="id". Just skimmed over the code.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 6
Reputation: bigbob is an unknown quantity at this point 
Solved Threads: 0
bigbob bigbob is offline Offline
Newbie Poster

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

 
0
  #5
Jun 12th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

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

 
0
  #6
Jun 13th, 2008
shade out ? You mean read only ?
<input type="text" name="id" readonly>
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC