[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

Need help figuring out why this isn't working (php - mysql related)

<?php

// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "e-mail address here";
$Subject = "Hello";
$FirstName = Trim(stripslashes($_POST['FirstName']));
$LastName = Trim(stripslashes($_POST['LastName']));
$TeamName = Trim(stripslashes($_POST['TeamName']));
$UserName = Trim(stripslashes($_POST['UserName']));
$PassWord = Trim(stripslashes($_POST['PassWord']));
$GoalKeeper = Trim(stripslashes($_POST['GoalKeeper']));
$Defender1 = Trim(stripslashes($_POST['Defender1']));
$Defender2 = Trim(stripslashes($_POST['Defender2']));
$Defender3 = Trim(stripslashes($_POST['Defender3']));
$Defender4 = Trim(stripslashes($_POST['Defender4']));
$Midfielder1 = Trim(stripslashes($_POST['Midfielder1']));
$Midfielder2 = Trim(stripslashes($_POST['Midfielder2']));
$Midfielder3 = Trim(stripslashes($_POST['Midfielder3']));
$MidStr = Trim(stripslashes($_POST['MidStr']));
$Striker1 = Trim(stripslashes($_POST['Striker1']));
$Striker2 = Trim(stripslashes($_POST['Striker2']));

// prepare email body text
$Body = "";
$Body .= "First Name: ";
$Body .= $FirstName;
$Body .= "\n";
$Body .= "Last Name: ";
$Body .= $LastName;
$Body .= "\n";
$Body .= "E-Mail Address: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "Username: ";
$Body .= $UserName;
$Body .= "\n";
$Body .= "Password: ";
$Body .= $PassWord;
$Body .= "\n";
$Body .= "Team Name: ";
$Body .= $TeamName;
$Body .= "\n";
$Body .= "Goalkeeper: ";
$Body .= $GoalKeeper;
$Body .= "\n";
$Body .= "Defender (1): ";
$Body .= $Defender1;
$Body .= "\n";
$Body .= "Defender (2): ";
$Body .= $Defender2;
$Body .= "\n";
$Body .= "Defender (3): ";
$Body .= $Defender3;
$Body .= "\n";
$Body .= "Defender (4): ";
$Body .= $Defender4;
$Body .= "\n";
$Body .= "Midfielder (1): ";
$Body .= $Midfielder1;
$Body .= "\n";
$Body .= "Midfielder (2): ";
$Body .= $Midfielder2;
$Body .= "\n";
$Body .= "Midfielder (3): ";
$Body .= $Midfielder3;
$Body .= "\n";
$Body .= "Midfielder (4/Striker): ";
$Body .= $MidStr;
$Body .= "\n";
$Body .= "Striker (1): ";
$Body .= $Striker1;
$Body .= "\n";
$Body .= "Striker (2): ";
$Body .= $Striker2;
$Body .= "\n";

// Make a MySQL Connection
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("databasename") or die(mysql_error());

// create sql statement
$sql = "INSERT INTO tablename (First_name) VALUES('$FirstName')"
or die(mysql_error());

// execute sql statement
$result = mysql_query($sql,$conn) or die(mysql_error);

// send email
$success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom>");

// redirect to success page
if ($success){
print " meta http-equiv=\"refresh\" content=\"0;URL=success.htm\">";
}
else{
print " meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

That's my code i am using, with all the right things entered i am getting 'mysql_error' displayed in web browser. Any help would be great so that hopefully i can get this working.

Thanks.
0
james130c
Asked:
james130c
  • 12
  • 11
  • 7
  • +2
4 Solutions
 
Cornelia YoderArtistCommented:
$sql = "INSERT INTO tablename (First_name) VALUES('$FirstName')" ;

// execute sql statement
$result = mysql_query($sql,$conn) or die(mysql_error);


You don't want the "or die" part on the assignment statement, only on the query itself.
0
 
LordOfPortsCommented:
Try changing the following statement:

// execute sql statement
$result = mysql_query($sql,$conn) or die(mysql_error);

to

// execute sql statement
$result = mysql_query($sql) or die(mysql_error());
0
 
hieloCommented:
Try this:
<?php 
 
// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); 
$EmailTo = "e-mail address here";
$Subject = "Hello";
$FirstName = Trim(stripslashes($_POST['FirstName'])); 
$LastName = Trim(stripslashes($_POST['LastName'])); 
$TeamName = Trim(stripslashes($_POST['TeamName'])); 
$UserName = Trim(stripslashes($_POST['UserName'])); 
$PassWord = Trim(stripslashes($_POST['PassWord'])); 
$GoalKeeper = Trim(stripslashes($_POST['GoalKeeper'])); 
$Defender1 = Trim(stripslashes($_POST['Defender1'])); 
$Defender2 = Trim(stripslashes($_POST['Defender2']));
$Defender3 = Trim(stripslashes($_POST['Defender3'])); 
$Defender4 = Trim(stripslashes($_POST['Defender4']));
$Midfielder1 = Trim(stripslashes($_POST['Midfielder1']));
$Midfielder2 = Trim(stripslashes($_POST['Midfielder2']));
$Midfielder3 = Trim(stripslashes($_POST['Midfielder3']));
$MidStr = Trim(stripslashes($_POST['MidStr']));
$Striker1 = Trim(stripslashes($_POST['Striker1']));
$Striker2 = Trim(stripslashes($_POST['Striker2']));
 
// prepare email body text
$Body = "";
$Body .= "First Name: ";
$Body .= $FirstName;
$Body .= "\n";
$Body .= "Last Name: ";
$Body .= $LastName;
$Body .= "\n";
$Body .= "E-Mail Address: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "Username: ";
$Body .= $UserName;
$Body .= "\n";
$Body .= "Password: ";
$Body .= $PassWord;
$Body .= "\n";
$Body .= "Team Name: ";
$Body .= $TeamName;
$Body .= "\n";
$Body .= "Goalkeeper: ";
$Body .= $GoalKeeper;
$Body .= "\n";
$Body .= "Defender (1): ";
$Body .= $Defender1;
$Body .= "\n";
$Body .= "Defender (2): ";
$Body .= $Defender2;
$Body .= "\n";
$Body .= "Defender (3): ";
$Body .= $Defender3;
$Body .= "\n";
$Body .= "Defender (4): ";
$Body .= $Defender4;
$Body .= "\n";
$Body .= "Midfielder (1): ";
$Body .= $Midfielder1;
$Body .= "\n";
$Body .= "Midfielder (2): ";
$Body .= $Midfielder2;
$Body .= "\n";
$Body .= "Midfielder (3): ";
$Body .= $Midfielder3;
$Body .= "\n";
$Body .= "Midfielder (4/Striker): ";
$Body .= $MidStr;
$Body .= "\n";
$Body .= "Striker (1): ";
$Body .= $Striker1;
$Body .= "\n";
$Body .= "Striker (2): ";
$Body .= $Striker2;
$Body .= "\n";
 
// Make a MySQL Connection
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("databasename") or die(mysql_error());
 
// create sql statement
$sql = "INSERT INTO tablename (First_name) VALUES('$FirstName')";
// You do not need this here => or die(mysql_error());
// since you are only "storing" a string onto $sql variable 
 
// execute sql statement
if( !($result = mysql_query($sql,$conn)) )
{
 die(mysql_error());
}
// send email 
// On your posted code you had:  "From: $EmailFrom>" Notice that you either enclose
// the email address in <> or you don't, but you cannot user only one. You had
// only > at the end.
$success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom");
 
// redirect to success page. USE header function
if ($success){
	//print " meta http-equiv=\"refresh\" content=\"0;URL=success.htm\">";
	header("Location: success.htm");
}
else{
	//print " meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
	header("Location: error.htm");
}
?>

Open in new window

0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
james130cAuthor Commented:
Yodercm -
upon trying your suggested comment i get taken to a blank white page (no errors displaying) But no database is inserted into the database and nothing sent to my e-mail address.

Lordofports -
Upon trying your suggested comment when i send the filled out form i get a (Duplicate entry " for key 1) error.

Hielo -
Upon trying your comment i currently still have the code you provided but with my own details on it, after filling out the form and sending it i get a blank white page, but the information i have entered shows up in the top of the title bar bit in explorer... nothing is entered into the database or sent to my e-mail though. (Page title before sending form is (form) after sending form the page title is (form name i entered emailaddress username password, ect.

Any ideas?
0
 
james130cAuthor Commented:
sorry title is same as above but the php file is displayed first, so for example config.php?FirstName=Jim&LastName=Bob&EmailFrom=eaddress@domain.com&TeamName=myteam, ect.. (after sending the form)
0
 
Cornelia YoderArtistCommented:
The error of putting "or die" on the assignment statement may not be the only one.  After you have fixed that, put some echo statements through your code, such as

echo "Debug 1<br>";
echo "Debug 2<br>";

and track down exactly what is happening and at what point you go to the blank screen.
0
 
james130cAuthor Commented:
Hi, so what exactly do i need to do? if you use the first lot of code in this post, but take away the 'or die' can you show me where i should add these echo statements? as im quite new to all this.

i tried to do this...

<?php

// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "e-mail address here";
$Subject = "Hello";
$FirstName = Trim(stripslashes($_POST['FirstName']));
$LastName = Trim(stripslashes($_POST['LastName']));
$TeamName = Trim(stripslashes($_POST['TeamName']));
$UserName = Trim(stripslashes($_POST['UserName']));
$PassWord = Trim(stripslashes($_POST['PassWord']));
$GoalKeeper = Trim(stripslashes($_POST['GoalKeeper']));
$Defender1 = Trim(stripslashes($_POST['Defender1']));
$Defender2 = Trim(stripslashes($_POST['Defender2']));
$Defender3 = Trim(stripslashes($_POST['Defender3']));
$Defender4 = Trim(stripslashes($_POST['Defender4']));
$Midfielder1 = Trim(stripslashes($_POST['Midfielder1']));
$Midfielder2 = Trim(stripslashes($_POST['Midfielder2']));
$Midfielder3 = Trim(stripslashes($_POST['Midfielder3']));
$MidStr = Trim(stripslashes($_POST['MidStr']));
$Striker1 = Trim(stripslashes($_POST['Striker1']));
$Striker2 = Trim(stripslashes($_POST['Striker2']));

// prepare email body text
$Body = "";
$Body .= "First Name: ";
$Body .= $FirstName;
$Body .= "\n";
$Body .= "Last Name: ";
$Body .= $LastName;
$Body .= "\n";
$Body .= "E-Mail Address: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "Username: ";
$Body .= $UserName;
$Body .= "\n";
$Body .= "Password: ";
$Body .= $PassWord;
$Body .= "\n";
$Body .= "Team Name: ";
$Body .= $TeamName;
$Body .= "\n";
$Body .= "Goalkeeper: ";
$Body .= $GoalKeeper;
$Body .= "\n";
$Body .= "Defender (1): ";
$Body .= $Defender1;
$Body .= "\n";
$Body .= "Defender (2): ";
$Body .= $Defender2;
$Body .= "\n";
$Body .= "Defender (3): ";
$Body .= $Defender3;
$Body .= "\n";
$Body .= "Defender (4): ";
$Body .= $Defender4;
$Body .= "\n";
$Body .= "Midfielder (1): ";
$Body .= $Midfielder1;
$Body .= "\n";
$Body .= "Midfielder (2): ";
$Body .= $Midfielder2;
$Body .= "\n";
$Body .= "Midfielder (3): ";
$Body .= $Midfielder3;
$Body .= "\n";
$Body .= "Midfielder (4/Striker): ";
$Body .= $MidStr;
$Body .= "\n";
$Body .= "Striker (1): ";
$Body .= $Striker1;
$Body .= "\n";
$Body .= "Striker (2): ";
$Body .= $Striker2;
$Body .= "\n";

// Make a MySQL Connection
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("databasename") or die(mysql_error());

// create sql statement
$sql = "INSERT INTO tablename (First_name) VALUES('$FirstName')"

echo "Debug 1<br>";
echo "Debug 2<br>";

// execute sql statement
$result = mysql_query($sql,$conn) or die(mysql_error);

// send email
$success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom>");

// redirect to success page
if ($success){
print " meta http-equiv=\"refresh\" content=\"0;URL=success.htm\">";
}
else{
print " meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

and got same blank white page, i must be doing something wrong...
0
 
Cornelia YoderArtistCommented:
OK, here is your code with some echo statements in it.  I also had to add a missing semicolon on the line

$sql = "INSERT INTO tablename (First_name) VALUES('$FirstName')";

which may be part of the problem.

If this still doesn't work, post the echo results here.  If it does, just remove all the echo statements and check it again.
<?php 
 
// get posted data into local variables
echo "Debug 1 at start<br>";
 
$EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); 
$EmailTo = "e-mail address here";
$Subject = "Hello";
$FirstName = Trim(stripslashes($_POST['FirstName'])); 
$LastName = Trim(stripslashes($_POST['LastName'])); 
$TeamName = Trim(stripslashes($_POST['TeamName'])); 
$UserName = Trim(stripslashes($_POST['UserName'])); 
$PassWord = Trim(stripslashes($_POST['PassWord'])); 
$GoalKeeper = Trim(stripslashes($_POST['GoalKeeper'])); 
$Defender1 = Trim(stripslashes($_POST['Defender1'])); 
$Defender2 = Trim(stripslashes($_POST['Defender2']));
$Defender3 = Trim(stripslashes($_POST['Defender3'])); 
$Defender4 = Trim(stripslashes($_POST['Defender4']));
$Midfielder1 = Trim(stripslashes($_POST['Midfielder1']));
$Midfielder2 = Trim(stripslashes($_POST['Midfielder2']));
$Midfielder3 = Trim(stripslashes($_POST['Midfielder3']));
$MidStr = Trim(stripslashes($_POST['MidStr']));
$Striker1 = Trim(stripslashes($_POST['Striker1']));
$Striker2 = Trim(stripslashes($_POST['Striker2']));
 
// prepare email body text
$Body = "";
$Body .= "First Name: ";
$Body .= $FirstName;
$Body .= "\n";
$Body .= "Last Name: ";
$Body .= $LastName;
$Body .= "\n";
$Body .= "E-Mail Address: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "Username: ";
$Body .= $UserName;
$Body .= "\n";
$Body .= "Password: ";
$Body .= $PassWord;
$Body .= "\n";
$Body .= "Team Name: ";
$Body .= $TeamName;
$Body .= "\n";
$Body .= "Goalkeeper: ";
$Body .= $GoalKeeper;
$Body .= "\n";
$Body .= "Defender (1): ";
$Body .= $Defender1;
$Body .= "\n";
$Body .= "Defender (2): ";
$Body .= $Defender2;
$Body .= "\n";
$Body .= "Defender (3): ";
$Body .= $Defender3;
$Body .= "\n";
$Body .= "Defender (4): ";
$Body .= $Defender4;
$Body .= "\n";
$Body .= "Midfielder (1): ";
$Body .= $Midfielder1;
$Body .= "\n";
$Body .= "Midfielder (2): ";
$Body .= $Midfielder2;
$Body .= "\n";
$Body .= "Midfielder (3): ";
$Body .= $Midfielder3;
$Body .= "\n";
$Body .= "Midfielder (4/Striker): ";
$Body .= $MidStr;
$Body .= "\n";
$Body .= "Striker (1): ";
$Body .= $Striker1;
$Body .= "\n";
$Body .= "Striker (2): ";
$Body .= $Striker2;
$Body .= "\n";
 
echo "Debug 2 before connection<br>";
 
 
// Make a MySQL Connection
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("databasename") or die(mysql_error());
 
echo "Debug 3 after connection<br>";
 
 
// create sql statement
$sql = "INSERT INTO tablename (First_name) VALUES('$FirstName')";
 
// execute sql statement
$result = mysql_query($sql,$conn) or die(mysql_error);
 
echo "Debug 4 after query<br>";
 
 
// send email 
$success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom>");
 
echo "Debug 5 after email<br>";
 
 
// redirect to success page 
if ($success){
 
echo "Debug 6 if success<br>";
 
print " meta http-equiv=\"refresh\" content=\"0;URL=success.htm\">";
}
else{
 
echo "Debug 7 not success<br>";
 
print " meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
 
echo "Debug 8 at end<br>";
 
?>

Open in new window

0
 
james130cAuthor Commented:
Ok, using that code after submitting the form i get taken to these:

Debug 1 at start
Debug 2 before connection
Debug 3 after connection
mysql_error

This is why is displayed on the page it takes me too using the above code.
0
 
Cornelia YoderArtistCommented:
OK, I missed something that someone else had told you to enter ... fix this statement

$result = mysql_query($sql,$conn) or die(mysql_error());

Run it again, and post the results.
0
 
Cornelia YoderArtistCommented:
In fact, fix BOTH things that LordofPorts told you....

Try changing the following statement:

// execute sql statement
$result = mysql_query($sql,$conn) or die(mysql_error);

to

// execute sql statement
$result = mysql_query($sql) or die(mysql_error());
0
 
ChorchCommented:
Try using this:
$sql = "INSERT INTO tablename (`First_name`) VALUES ('".$FirstName."')";

Open in new window

0
 
james130cAuthor Commented:
Ok think i might be getting somewhere, using this code it seems to be ok and it sends me to the success page.. and also my e-mail address gets the e-mail, problem is though, nothing is actually entered into the database and the e-mail is blank. The e-mail has the headers for each part but no input even though the form was filled out. And the database = nothing is different, nothing entered into it no changes what so ever.

<?php
 
// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "Email address";
$Subject = "Hello";
$FirstName = Trim(stripslashes($_POST['FirstName']));
$LastName = Trim(stripslashes($_POST['LastName']));
$TeamName = Trim(stripslashes($_POST['TeamName']));
$UserName = Trim(stripslashes($_POST['UserName']));
$PassWord = Trim(stripslashes($_POST['PassWord']));
$GoalKeeper = Trim(stripslashes($_POST['GoalKeeper']));
$Defender1 = Trim(stripslashes($_POST['Defender1']));
$Defender2 = Trim(stripslashes($_POST['Defender2']));
$Defender3 = Trim(stripslashes($_POST['Defender3']));
$Defender4 = Trim(stripslashes($_POST['Defender4']));
$Midfielder1 = Trim(stripslashes($_POST['Midfielder1']));
$Midfielder2 = Trim(stripslashes($_POST['Midfielder2']));
$Midfielder3 = Trim(stripslashes($_POST['Midfielder3']));
$MidStr = Trim(stripslashes($_POST['MidStr']));
$Striker1 = Trim(stripslashes($_POST['Striker1']));
$Striker2 = Trim(stripslashes($_POST['Striker2']));
 
// prepare email body text
$Body = "";
$Body .= "First Name: ";
$Body .= $FirstName;
$Body .= "\n";
$Body .= "Last Name: ";
$Body .= $LastName;
$Body .= "\n";
$Body .= "E-Mail Address: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "Username: ";
$Body .= $UserName;
$Body .= "\n";
$Body .= "Password: ";
$Body .= $PassWord;
$Body .= "\n";
$Body .= "Team Name: ";
$Body .= $TeamName;
$Body .= "\n";
$Body .= "Goalkeeper: ";
$Body .= $GoalKeeper;
$Body .= "\n";
$Body .= "Defender (1): ";
$Body .= $Defender1;
$Body .= "\n";
$Body .= "Defender (2): ";
$Body .= $Defender2;
$Body .= "\n";
$Body .= "Defender (3): ";
$Body .= $Defender3;
$Body .= "\n";
$Body .= "Defender (4): ";
$Body .= $Defender4;
$Body .= "\n";
$Body .= "Midfielder (1): ";
$Body .= $Midfielder1;
$Body .= "\n";
$Body .= "Midfielder (2): ";
$Body .= $Midfielder2;
$Body .= "\n";
$Body .= "Midfielder (3): ";
$Body .= $Midfielder3;
$Body .= "\n";
$Body .= "Midfielder (4/Striker): ";
$Body .= $MidStr;
$Body .= "\n";
$Body .= "Striker (1): ";
$Body .= $Striker1;
$Body .= "\n";
$Body .= "Striker (2): ";
$Body .= $Striker2;
$Body .= "\n";
 
// Make a MySQL Connection
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("databasename") or die(mysql_error());
 
// create sql statement
$sql = "INSERT INTO User_accounts (First_name, Last_name, Email_address, Username, Password, Team_name) VALUES('$FirstName','$LastName','$EmailFrom','$UserName','$PassWord','$TeamName')";
// You do not need this here => or die(mysql_error());
// since you are only "storing" a string onto $sql variable
 
// execute sql statement
$result = mysql_query($sql,$conn) ;

// send email
// On your posted code you had:  "From: $EmailFrom>" Notice that you either enclose
// the email address in <> or you don't, but you cannot user only one. You had
// only > at the end.
$success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom");

// redirect to success page. USE header function
if ($success){
      //print " meta http-equiv=\"refresh\" content=\"0;URL=success.htm\">";
      header("Location: success.htm");
}
else{
      //print " meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      header("Location: error.htm");
}
?>
0
 
ChorchCommented:
Can you also post the form code?
0
 
Cornelia YoderArtistCommented:
You need to see the mysql error!

$result = mysql_query($sql,$conn);
echo mysql_error();
0
 
james130cAuthor Commented:
Ok, using the above

$result = mysql_query($sql,$conn);
echo mysql_error();

instead of:
$result = mysql_query($sql,$conn);

I am still getting taken to the success page after submitting the form, not showing or telling any errors, database is unchanged though, and the email i have still received but with no input.
0
 
james130cAuthor Commented:
Chorch, tried using
$sql = "INSERT INTO table (`First_name`) VALUES ('".$FirstName."')";

gave the same results, took me to success page like everything was fine, but nothing entered into the database and the e-mail had no input either.

Thanks.
0
 
james130cAuthor Commented:
Here is the form code i am using:

<form action="config.php">
 
	  <input type="text" size="30" name="FirstName" maxlength="16" onKeyUp="this.value=this.value.replace(/[\W_]/,'');" />
 
	  <input type="text" size="30" name="LastName" maxlength="25" onKeyUp="this.value=this.value.replace(/[\W_]/,'');" />
 
	  <input type="text" size="30" name="EmailFrom" maxlength="45" style="in_Border" />
 
	  <input type="text" size="30" name="TeamName" maxlength="25" onKeyUp="this.value=this.value.replace(/[\W_]/,'');" />
 
	  <input type="text" size="30" name="UserName" maxlength="14" onKeyUp="this.value=this.value.replace(/[\W_]/,'');" />
 
	  <input type="password" size="30" name="PassWord" maxlength="8" onKeyUp="this.value=this.value.replace(/[\W_]/,'');" />
 
</form>

Open in new window

0
 
Cornelia YoderArtistCommented:
Following this statement, add an echo

$sql = "INSERT INTO User_accounts (First_name, Last_name, Email_address, Username, Password, Team_name) VALUES('$FirstName','$LastName','$EmailFrom','$UserName','$PassWord','$TeamName')";

echo "sql=$sql<br>";
0
 
ChorchCommented:
<form action="config.php" method="post">
0
 
james130cAuthor Commented:
Ok - Chorch having used <form action="config.php" method="post"> The email does contain the right input. However the database still does no enter the input.

Yodercm added the echo after that statement and got this upon sending form
sql=INSERT INTO User_accounts (First_name, Last_name, Email_address, Username, Password, Team_name) VALUES('simon','Manning','simonmann@domain.com','simon01','64646644','simonsays')

Open in new window

0
 
ChorchCommented:
Glad to hear that.

Now use this:

$result = mysql_query($sql);

instead of:

$result = mysql_query($sql,$conn);
0
 
Cornelia YoderArtistCommented:
OK, good, it looks like your data is getting to the query correctly.

Now ...

$result = mysql_query($sql,$conn) ;
echo "error = ".mysql_error();

What does that give?
0
 
ChorchCommented:
This will give:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource

as $conn is not defined anywhere (also is not necessary).
0
 
Cornelia YoderArtistCommented:
Yes, chorch, I know, that error has already been told to him by LordofPorts.  I need him to see it for himself, so he understands.
0
 
ChorchCommented:
Oh... sorry, didn't read that post.
0
 
james130cAuthor Commented:
Chroch -
$result = mysql_query($sql);

instead of:

$result = mysql_query($sql,$conn);

Seems to be working i can see data entered into the database and the e-mail seems to be ok. Thank you.

yodercm -

I know you mentioned to try lordofports suggestions of which one of them was to try

$result = mysql_query($sql);

instead of:

$result = mysql_query($sql,$conn);

we didn't add that into the new code we been testing though it seems as Chroch pointed out. But all seems to be working right.

The only problem i have now is if i send the form with nothing filled in, i't should go to the error page but it's not working properly here is the code i have for that.
if (empty($FirstName) || empty($LastName) || empty($EmailFrom) || empty($TeamName) || empty($UserName) || empty($PassWord)) {
   header( "Location: error.htm" );
   exit ;
}
 
Firstly where should i put this sort of code? after getting posted data into variables? or does it not matter and secondly is the code right?
 
Thanks for all your helps guys

Open in new window

0
 
Cornelia YoderArtistCommented:
I'm a firm believer in the motto "Give a man a fish and you've fed him for a day.  Teach him to fish and you've fed him for a lifetime."

By going through these steps of tracking down each error using echo statements to see what is happening, james130c will know how to do this kind of debug next time.
0
 
Cornelia YoderArtistCommented:
if ($FirstName=='') || ($LastName=='') || etc........

This should be put immediately after the values are retrieved from the _$_POST's.
0
 
ChorchCommented:
I would place this before:

// prepare email body text

after getting posted data into variables, then code is right.

If at top of you php file, you should use:

if (empty($_POST['FirstName']) ...
0
 
Cornelia YoderArtistCommented:
James, you were told several times to make changes that you didn't, so I was trying to lead you to each of the errors, one at a time.  Chorch jumped the gun by pointing them out (again).  Anyway, it appears you have the problem sorted out now.  Good luck.
0
 
james130cAuthor Commented:
Thanks to you all, hope i have fairly awarded points i decided to accepted multiple because there was users who said the same things but just explained them differently untill i was able to understand and fix these. Thank you too all.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 12
  • 11
  • 7
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now