0

when I tried to test my regeneration form this massage show up : "The mysql extension is deprecated and will be removed in the future: use mysqli or PDO"

I tried to change my code each time I got a new problem, I'm not so expert in these stuff can any one help me and tell me what exactly I need to change in my code please?!

connection code

    <?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_localhost = "localhost";
$database_localhost = "rsms database";
$username_localhost = "root";
$password_localhost = "";
$localhost = mysql_pconnect($hostname_localhost, $username_localhost, $password_localhost) or trigger_error(mysql_error(),E_USER_ERROR); 
?>

and this is my source code

    <?php require_once('Connections/localhost.php'); ?>
<?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"] == "form")) {
  $insertSQL = sprintf("INSERT INTO users (email, DateOfBirth) VALUES (%s, %s)",
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['DateOfBirth'], "date"));

  mysql_select_db($database_localhost, $localhost);
  $Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error());

  $insertGoTo = "PageAfterLogin.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_localhost, $localhost);
$query_RegesterUsers = "SELECT * FROM users";
$RegesterUsers = mysql_query($query_RegesterUsers, $localhost) or die(mysql_error());
$row_RegesterUsers = mysql_fetch_assoc($RegesterUsers);
$totalRows_RegesterUsers = mysql_num_rows($RegesterUsers);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>


</head>


<body>

<div class="containerDiv" id="containerDiv">

Regesteration Page





<form method="POST" action="<?php echo $editFormAction; ?>" name="form">



    <table width="600" border="0">
  <tbody>
    <tr>
      <td><label for="email">Email:</label>
        <input type="email" name="email" id="email"></td>
      <td><label for="date">Date:</label>
        <input type="date" name="DateOfBirth" id="DateOfBirth"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="submit" id="submit" value="Submit"></td>
    </tr>
  </tbody>
</table>
    <input type="hidden" name="MM_insert" value="form">





</form>



</div>
</body>
</html>
<?php
mysql_free_result($RegesterUsers);
?>
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    It will help you understand better if instead of posting your current code you posted the code you attempted that gives you errors so that we can assist you in fixing those to move your project along faster. – Jhecht Feb 05 '17 at 00:03
  • "what exactly I need to change" - Everything that begins with `mysql_` – Paul Spiegel Feb 05 '17 at 00:21

1 Answers1

-1

Currently in PHP there are three ways of connecting to a MySQL database. Using the mysql_* functions (which you have used), mysqli_* (which is preferred) and PDO.

The mysql_ functions are no longer supported (and removed in PHP 7), you shouldn't use them anymore for PHP scripts and you should use MySQLi as the new and improved standard.

PDO is a universal standard for all database installations such as MySQL, SQLite, MS SQL and PostgreSQL.

The message you have is just a notification, you're not required to use PDO or MySQLI but PHP will tell you each time that you should change your scripts.

ScottSmudger
  • 351
  • 2
  • 8