Jump to content

GetSQLValueString problem


MarcWagner

Recommended Posts

Hello there,

 

I'm having an issue with GetSQLValueString.

It worked before (PHP 5) but now in PHP7 it doesn't. Maybe it is deprecated? (i couldn't find any infos on that).

 

I'm trying to update a record. Some of the code follows:

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form")) {
  $updateSQL = sprintf("UPDATE t_cliente SET tipo_client=%s, nome=%s, morada=%s, nif=%s, cod_postal=%s, telemovel=%s, email=%s WHERE ID=%s",
                       GetSQLValueString($_POST['tipo'], "int"),
                       GetSQLValueString($_POST['nome'], "text"),
                       GetSQLValueString($_POST['morada'], "text"),
                       GetSQLValueString($_POST['nif'], "int"),
                       GetSQLValueString($_POST['cod'], "text"),
                       GetSQLValueString($_POST['telefone'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['ID'], "int"));

$Result1 = mysqli_query($con, $updateSQL) or die(mysqli_error());

GetSQLValueString seems to always output NULL and thus the update fails.

 

Thanks for the help!

Note: I updated some functions, like mysql_query to mysqli_query.

Link to comment
Share on other sites

Do yourself a favor and get rid of the ancient Dreamweaver garbage code. Since ~10 years, we use prepared statements:

$customer_stmt = $database_connection->prepare('
    UPDATE
        t_cliente
    SET
        tipo_client = ?,
        nome = ?,
        morada = ?,
        nif = ?,
        cod_postal = ?,
        telemovel = ?,
        email = ?
    WHERE
        id = ?
');
$customer_stmt->bind_param(
    'ississsi',
    $_POST['tipo'],
    $_POST['nome'],
    $_POST['morada'],
    $_POST['nif'],
    $_POST['cod'],
    $_POST['telefone'],
    $_POST['email'],
    $_POST['ID']
);
$customer_stmt->execute();
Link to comment
Share on other sites

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.