Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Query was empty - just added if statements?

Engaged ,
Apr 06, 2012 Apr 06, 2012

i have added two if stat

TOPICS
Server side applications
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Apr 06, 2012 Apr 06, 2012

OK, please post the entire page code. You're probably just missing curly braces or a line terminator.

Translate
Engaged ,
Apr 06, 2012 Apr 06, 2012

sorry posted by mistake..

ok i added two if statements to check if a password is correct

if($POST['password'] == $_POST['password2'])

          if($_POST['email'] == $_POST['email2'])

and when i add the above it return a query is empty.

the full code is below

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

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

{

          if($POST['password'] == $_POST['password2'])

          if($_POST['email'] == $_POST['email2'])

 

  $insertSQL = sprintf("INSERT INTO think_signup (FirstName, Surname, password, email, ContactMethod, TeleNumber, SalaryReq, PositionReq, skills_offered, cv, location) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",

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

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

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

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

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

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

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

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

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

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

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

and the inputs are here

              <td nowrap="nowrap" align="right">Password:</td>

              <td><input type="text" name="password" value="" size="30" /></td>

            </tr>

            <tr valign="baseline">

              <td nowrap="nowrap" align="right">Confirm Password</td>

              <td><input type="text" name="password2" value="" size="30" /></td>

            </tr>

            <tr valign="baseline">

              <td nowrap="nowrap" align="right">Email:</td>

              <td><input type="text" name="email" value="" size="30" /></td>

            </tr>

            <tr valign="baseline">

              <td nowrap="nowrap" align="right">Confirm Email</td>

              <td><input type="text" name="email2" value="" size="30" /></td>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 06, 2012 Apr 06, 2012

Typo in your POST variable.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 06, 2012 Apr 06, 2012

tried this


if($POST['password'] == $_POST['password2'] && $POST['email'] == $_POST['email2'])

but returned the same query is empty

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 06, 2012 Apr 06, 2012

You still have the same typo. There is no $POST variable assigned on your page. You need to use $_POST.

This is why I hate loosely typed languages.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 06, 2012 Apr 06, 2012

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

{

          if($_POST['password'] == $_POST['password2'] && $_POST['email'] == $_POST['email2'])

still same error?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 06, 2012 Apr 06, 2012

>still same error?

You're getting an error?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 06, 2012 Apr 06, 2012
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 06, 2012 Apr 06, 2012

OK, please post the entire page code. You're probably just missing curly braces or a line terminator.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 06, 2012 Apr 06, 2012

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;   

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

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

{

          if($_POST['password'] == $_POST['password2'] && $_POST['email'] == $_POST['email2'])

 

  $insertSQL = sprintf("INSERT INTO think_signup (FirstName, Surname, password, email, ContactMethod, TeleNumber, SalaryReq, PositionReq, skills_offered, cv, needCV, otherComments, location) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",

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

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

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

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

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

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

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

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

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

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

                                                     GetSQLValueString(isset($_POST['needCV']) ? "true" : "", "defined","'Y'","'N'"),

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

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

  mysql_select_db($database_hostprop, $hostprop);

  $Result1 = mysql_query($insertSQL, $hostprop) or die(mysql_error());

  $insertGoTo = "signup-complete.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

    $insertGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $insertGoTo));

}

mysql_select_db($database_hostprop, $hostprop);

$query_rsReg = "SELECT * FROM think_signup";

$rsReg = mysql_query($query_rsReg, $hostprop) or die(mysql_error());

$row_rsReg = mysql_fetch_assoc($rsReg);

$totalRows_rsReg = mysql_num_rows($rsReg);

?>

        <form action="<?php echo $editFormAction; ?>" method="post" name="form4" id="form4">

          <table width="500" align="center">

            <tr valign="baseline">

              <td nowrap="nowrap" align="left"><p>FirstName:

                </p>

                <p>

                  <input type="text" name="FirstName" value="" size="30" />

              </p></td>

              <td><p>

                <input type="text" name="cv" value="" size="32" />

              </p>

              <p>                Cv </p></td>

            </tr>

            <tr valign="baseline">

              <td nowrap="nowrap" align="left"><p>Surname

                </p>

                <p>

                  <input type="text" name="Surname" value="" size="30" />

              </p></td>

              <td><p>

                <input type="checkbox" name="needCV"/>

              </p>

              <p>need cv </p></td>

            </tr>

            <tr valign="baseline">

              <td nowrap="nowrap" align="left"><p>Password

                </p>

                <p>

                  <input type="text" name="password" value="" size="30" />

              </p></td>

              <td rowspan="2">

                <p>

                  <textarea name="otherComments"cols="20" rows="5"></textarea>

                </p>

                <p>other comments</p>

              <p>  </p></td>

            </tr>

            <tr valign="baseline">

              <td nowrap="nowrap" align="left"><p>Confirm Password

                </p>

                <p>

                  <input type="text" name="password2" value="" size="30" />

              </p></td>

            </tr>

            <tr valign="baseline">

              <td nowrap="nowrap" align="left"><p>Email

                </p>

                <p>

                  <input type="text" name="email" value="" size="30" />

              </p></td>

              <td> </td>

            </tr>

            <tr valign="baseline">

              <td nowrap="nowrap" align="left"><p>Confirm Email

                </p>

                <p>

                  <input type="text" name="email2" value="" size="30" />

              </p></td>

              <td> </td>

            </tr>

            <tr valign="baseline">

              <td nowrap="nowrap" align="left"><p>ContactMethod

                </p>

                <p>

                  <input type="text" name="ContactMethod" value="" size="30" />

              :</p></td>

              <td> </td>

            </tr>

            <tr valign="baseline">

              <td nowrap="nowrap" align="left"><p>TeleNumber

                </p>

                <p>

                  <input type="text" name="TeleNumber" value="" size="30" />

              :</p></td>

              <td> </td>

            </tr>

            <tr valign="baseline">

              <td nowrap="nowrap" align="left"><p>SalaryReq

                </p>

                <p>

                  <input type="text" name="SalaryReq" value="" size="30" />

              :</p></td>

              <td> </td>

            </tr>

            <tr valign="baseline">

              <td nowrap="nowrap" align="left"><p>PositionReq

                </p>

                <p>

                  <input type="text" name="PositionReq" value="" size="32" />

              :</p></td>

              <td> </td>

            </tr>

            <tr valign="baseline">

              <td nowrap="nowrap" align="left"><p>Skills_offered

                </p>

                <p>

                  <input type="text" name="skills_offered" value="" size="32" />

              :</p></td>

              <td> </td>

            </tr>

            <tr valign="baseline">

              <td nowrap="nowrap" align="left"><p> </p>

                <p>

            :</p></td>

              <td> </td>

            </tr>

            <tr valign="baseline">

              <td nowrap="nowrap" align="left">Location

                <input type="text" name="location" value="" size="32" />

              :</td>

              <td> </td>

            </tr>

            <tr valign="baseline">

              <td nowrap="nowrap" align="left"> </td>

              <td><input type="submit" value="Insert record" /></td>

            </tr>

          </table>

          <input type="hidden" name="MM_insert" value="form4" />

        </form>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 06, 2012 Apr 06, 2012

Your new IF statement is missing curly braces. Add them and see what happens.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 06, 2012 Apr 06, 2012
LATEST

its working now,. thanks for your help

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines