Skip to main content
Inspiring
September 8, 2011
Answered

Combining two fields to make a third then insert into DB

  • September 8, 2011
  • 1 reply
  • 507 views

I have this script:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {

  $insertSQL = sprintf("INSERT INTO members (Firstname, Surname, `Section`, Login, Password, DefaultPassword, Email) VALUES (%s, %s, %s, %s, %s, %s, %s)",

                       GetSQLValueString($_POST['Firstname'], "text"),

                       GetSQLValueString($_POST['Surname'], "text"),

                       GetSQLValueString($_POST['Section'], "text"),

                       GetSQLValueString($_POST['Login'], "text"),

                       GetSQLValueString($_POST['Password'], "text"),

                       GetSQLValueString($_POST['DefaultPassword'], "text"),

                       GetSQLValueString($_POST['Email'], "text"));

But I want to the value for the Login to be the Firstname + Surname all in lowercase.

I have tried this, but it doesn't work...

$Login = strtolower($_POST['Firstname'] . $_POST['Surname']);

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {

  $insertSQL = sprintf("INSERT INTO members (Firstname, Surname, `Section`, Login, Password, DefaultPassword, Email) VALUES (%s, %s, %s, %s, %s, %s, %s)",

                       GetSQLValueString($_POST['Firstname'], "text"),

                       GetSQLValueString($_POST['Surname'], "text"),

                       GetSQLValueString($_POST['Section'], "text"),

                       $Login, "text",

                       GetSQLValueString($_POST['Password'], "text"),

                       GetSQLValueString($_POST['DefaultPassword'], "text"),

                       GetSQLValueString($_POST['Email'], "text"));

Any ideas what I am doing wrong?

This topic has been closed for replies.
Correct answer Ben M

Your login line should be:

GetSQLValueString($Login, "text"),

There is only one statement there and you wrote "$Login, "text") which is actually 2 statements.  The ( ) around the $Login text executes it as one statement like the DW code is looking for.

Outside of that it should work.

1 reply

Ben MCommunity ExpertCorrect answer
Community Expert
September 8, 2011

Your login line should be:

GetSQLValueString($Login, "text"),

There is only one statement there and you wrote "$Login, "text") which is actually 2 statements.  The ( ) around the $Login text executes it as one statement like the DW code is looking for.

Outside of that it should work.

Inspiring
September 8, 2011

Perfect thanks!