Jump to content

Recommended Posts

Hi all. For some reason this code won't return the firstname, lastname, email or statement from my form data when i submit it..

 

its blank when it inserts it.

 

how can i fix it so it reads whats in the database, and returns a thank you message like so: "Thanks for signing up, $_POST['firstname'], $_POST['lastname']."!" " ?

 

heres the lines that return nothing that SHOULD return SOMETHING..

 

if($numrows > 0){
while($row = mysql_fetch_array($site_con))
{

echo "row: ".$row."<br>\n";
echo "first: ".$row['firstname']."<br>\n";
echo "last: ".$row['lastname']."<br>\n";
echo "email: ".$row['email']."<br>\n";
echo "statement: ".$row['statement']."<br>\n";
echo "first: ".$firstname."<br>\n";
echo "last: ".$lastname."<br>\n";
echo "email: ".$email."<br>\n";
echo "statement: ".$statement."<br>\n";
echo "first: ".$_REQUEST['firstname']."<br>\n";
echo "last: ".$_REQUEST['lastname']."<br>\n";
echo "email: ".$_REQUEST['email']."<br>\n";
echo "statement: ".$_REQUEST['statement']."<br>\n";
echo "user: ".$_POST['firstname'].", ".$_POST['lastname'].", email: ".$_POST['email']." already exists!<br>"."\n";
echo "user: ".$_GET['firstname'].", ".$_GET['lastname'].", email: ".$_GET['email']." already exists!<br>"."\n";
}

 

and..

 

here is the code:

 

send.php:

 

<?php
$conn = "localhost";
$user = "myuser";
$pass = "mypass";
$dbname = "metaldetect01";
$tbl = "users0001";
$con = mysql_connect($conn,$user,$pass);
if (!$con)
  {
  die('Could not connect to database: "' . $dbname . '" because ' . mysql_error());
  }

mysql_select_db($dbname, $con);

$sql_site = ("SELECT * FROM $tbl WHERE `firstname` = '$_GET[firstname]' AND `lastname` = '$_GET[lastname]' AND `email` = '$_GET[email]' AND `statement` = '$_GET[statement]'; ");
$site_con = mysql_query($sql_site) or die(mysql_error());
$numrows = mysql_num_rows($site_con);

if($numrows > 0){
while($row = mysql_fetch_array($site_con))
{

echo "row: ".$row."<br>\n";
echo "first: ".$row['firstname']."<br>\n";
echo "last: ".$row['lastname']."<br>\n";
echo "email: ".$row['email']."<br>\n";
echo "statement: ".$row['statement']."<br>\n";
echo "first: ".$firstname."<br>\n";
echo "last: ".$lastname."<br>\n";
echo "email: ".$email."<br>\n";
echo "statement: ".$statement."<br>\n";
echo "first: ".$_REQUEST['firstname']."<br>\n";
echo "last: ".$_REQUEST['lastname']."<br>\n";
echo "email: ".$_REQUEST['email']."<br>\n";
echo "statement: ".$_REQUEST['statement']."<br>\n";
echo "user: ".$_POST['firstname'].", ".$_POST['lastname'].", email: ".$_POST['email']." already exists!<br>"."\n";
echo "user: ".$_GET['firstname'].", ".$_GET['lastname'].", email: ".$_GET['email']." already exists!<br>"."\n";

//echo "Taking you to the main page..";
//echo "<script>setTimeout('alert(\'Goodbye!\'), document.location = \"./index.html\";', 2000);</script>";

}

}else{

$sql="INSERT INTO $tbl (firstname, lastname, email, statement)
VALUES
('".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['email']."','".$_POST['statement']."')";

echo "You were successfully added to the database, ".$_POST['firstname'].", ".$_POST['lastname']."!<br>";
echo "Returning you to the previous page...";

echo "<script>setTimeout('document.location = \"./index.html\";', 2000);</script>";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

}

function safe($value){

   return mysqli_real_escape_string($con, $value);
} 

function recordExists($id,$idval,$table,$db) {//check for id=idval in table and return TRUE or FALSE
   $result = mysql_query("SELECT * FROM ".$table." WHERE ".$id."='".$idval."'") or die(mysql_error());
if(mysql_num_rows($result) > 0) {//if we found more than 0
      return true;
   }//end if row
   return false;
}

mysql_close($con)
?>

 

and finally..

 

here's the form page:

 

index.html:

 

<html>
<head><title>Blah</title></head>
<body oncontextmenu="return false;">

<script>

function alldata(f){
checkdata(f);
emailCheck(f.email.value);
}

function checkCheckBox(f) {
  if (f.agree.checked == false) {
    alert('You MUST agree to the terms by checking the box above.');
  }
}

function goSubmit() {

  if (agree==0) {
    alert("DISGREE: You can insert the next step here");
  } else if (agree==1 && document.enableform.box.value=='') {
      alert("You must enter your name!");
      document.enableform.box.focus();
  } else {
    alert("AGREE: You can insert the next step here");
  }
}
var max=255;
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit){ // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
}else{
countfield.value = maxlimit - field.value.length;
}
}
function submitonce(theform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}
}
function checkdata(which) {
  var pass=true;
var t1 = document.forms.test;
  for (i=0;i<which.length;i++) {
    var tempobj=which.elements[i];
    if (tempobj.name.substring(0,=="required") {
      if (((tempobj.type=="text"||tempobj.type=="textarea")&&
          tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
          tempobj.selectedIndex==0)) {
        pass=false;
        break;
      }
    }
  }
  if (!pass) {
    shortFieldName=tempobj.name.substring(8,30).toUpperCase();
    alert("The "+shortFieldName+" field is a required field.");
    return false;
  } else {
  return true;
  }
}
function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

alert("Email address seems incorrect (don't forget to add an @ and a . to your email address!)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert("The username doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}
</script>
<Center><H1>Blah - Contact Us</H1></Center><br>
<Center><H1>Our hours of operation are: </H1></Center><br>
<Center><H1>10 AM - 8 PM (CST) Monday - Friday</H1></Center><br>
<Center><H1>11 AM - 5 PM (CST) Saturday & Sunday</H1></Center><br>
Please contact us!<br><br>
*Please note you can submit the form ONLY once. Any double form submissions will be deleted.<br>
*You will be emailed depending on your statement whether or not you've been approved to the group!<br>
<form name="test" id="test" method="POST" onsubmit="return alldata(this)" action="send.php">
<div id = "div01" style="width: 100; height: 25;">
  Firstname: <input name="requiredfirstname" id="firstname" type="text" />
  Lastname: <input name="requiredlastname" id="lastname" type="text" />
  Email: <input name="requiredemail" id="email" type="text" /><br /><br />
</div>
<H4>Your statement: </H4>
  <textarea onKeyDown="textCounter(this.form.statement,this.form.counter,max);" onKeyUp="textCounter(this.form.statement,this.form.counter,max);" name="requiredstatement" id="statement" rows="15" cols="40"></textarea><br />
Characters left: <input readonly="readonly" value="255" size=3 maxlength=3 type="text" name="counter" id="counter"><br/><br />
<textarea name="license" cols="40" rows="15" id="license">I agree to give 20% of my earnings to the club and in return will get 20% back when the company has 50% earnings!</textarea><br/>
<input name="requiredcb" id="agree" type="checkbox"> I have read & agree to the above<br/>
  <input name="s1" id="s1" value="Submit" type="submit" /> <input type="reset" name="rset" value="Reset" /><br/>
</form>
</body>
</html>

 

ANY help is GREATLY appreciated! :)

$sql_site = ("SELECT * FROM $tbl WHERE `firstname` = '$_GET[firstname]' AND `lastname` = '$_GET[lastname]' AND `email` = '$_GET[email]' AND `statement` = '$_GET[statement]'; ");

 

Change the $_GET to $_POST and you should be able to receive queries, your GET variable is empty due to the fact that you are sending form via POST...

it's still returning blank..

 

I now have:

 

$sql_site = ("SELECT * FROM $tbl WHERE `firstname` = '$_POST[firstname]' AND `lastname` = '$_POST[lastname]' AND `email` = '$_POST['email]' AND `statement` = '$_POST[statement]'; ");

 

and it still doesnt work..

 

send.php:

 


<?php
$conn = "localhost";
$user = "myuser";
$pass = "mypass";
$dbname = "metaldetect01";
$tbl = "users0001";
$con = mysql_connect($conn,$user,$pass);
if (!$con)
  {
  die('Could not connect to database: "' . $dbname . '" because ' . mysql_error());
  }

mysql_select_db($dbname, $con);

$sql_site = ("SELECT * FROM $tbl WHERE `firstname` = '$_POST[firstname]' AND `lastname` = '$_POST[lastname]' AND `email` = '$_POST['email]' AND `statement` = '$_POST[statement]'; ");
$site_con = mysql_query($sql_site) or die(mysql_error());
$numrows = mysql_num_rows($site_con);

if($numrows > 0){
while($row = mysql_fetch_array($site_con))
{

echo "row: ".$row."<br>\n";
echo "first: ".$row['firstname']."<br>\n";
echo "last: ".$row['lastname']."<br>\n";
echo "email: ".$row['email']."<br>\n";
echo "statement: ".$row['statement']."<br>\n";
echo "first: ".$firstname."<br>\n";
echo "last: ".$lastname."<br>\n";
echo "email: ".$email."<br>\n";
echo "statement: ".$statement."<br>\n";
echo "first: ".$_REQUEST['firstname']."<br>\n";
echo "last: ".$_REQUEST['lastname']."<br>\n";
echo "email: ".$_REQUEST['email']."<br>\n";
echo "statement: ".$_REQUEST['statement']."<br>\n";
echo "user: ".$_POST['firstname'].", ".$_POST['lastname'].", email: ".$_POST['email']." already exists!<br>"."\n";
echo "user: ".$_GET['firstname'].", ".$_GET['lastname'].", email: ".$_GET['email']." already exists!<br>"."\n";

//echo "Taking you to the main page..";
//echo "<script>setTimeout('alert(\'Goodbye!\'), document.location = \"./index.html\";', 2000);</script>";

}

}else{

$sql="INSERT INTO $tbl (firstname, lastname, email, statement)
VALUES
('".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['email']."','".$_POST['statement']."')";

echo "You were successfully added to the database, ".$_POST['firstname'].", ".$_POST['lastname']."!<br>";
echo "Returning you to the previous page...";

echo "<script>setTimeout('document.location = \"./index.html\";', 2000);</script>";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

}

function safe($value){

   return mysqli_real_escape_string($con, $value);
} 

function recordExists($id,$idval,$table,$db) {//check for id=idval in table and return TRUE or FALSE
   $result = mysql_query("SELECT * FROM ".$table." WHERE ".$id."='".$idval."'") or die(mysql_error());
if(mysql_num_rows($result) > 0) {//if we found more than 0
      return true;
   }//end if row
   return false;
}

mysql_close($con)
?>

i figured it out.. turns out my javascript needed the name element of the form to be different than the id in order for it to catch ppl not putting anything in to the box, so i had to rename all my $_POST's and it worked!

 

Thanks ALOT for all of your help! :D

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.