Avatar billede Morten Professor
29. marts 2015 - 22:25 Der er 23 kommentarer og
1 løsning

mysqli opstarts problemer

Hej

Jeg er ved at komme igang med mysqli "men men"
Jeg prøver at lave en update til min database og kan ikke få det til at virker.
Jeg får denne melding.

Notice: Undefined variable: mysqli in C:\wamp\www\mysqli\index.php on line 10
og
Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in C:\wamp\www\mysqli\index.php on line 10

Her er mine koder:

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("mysqli_real_escape_string") ? mysqli_real_escape_string($theValue, $mysqli) : mysqli_escape_string($theValue, $mysqli);

  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_update"])) && ($_POST["MM_update"] == "oplysninger")) {
  $updateSQL = sprintf("UPDATE test SET navn=%s, efternavn=%s, adresse=%s, postnr=%s, bynavn=%s, nummer=%s, email=%s WHERE id=%s",
                      GetSQLValueString($_POST['navn'], "text"),
                      GetSQLValueString($_POST['efternavn'], "text"),
                      GetSQLValueString($_POST['adresse'], "text"),
                      GetSQLValueString($_POST['postnr'], "int"),
                      GetSQLValueString($_POST['bynavn'], "text"),
                      GetSQLValueString($_POST['nummer'], "int"),
                      GetSQLValueString($_POST['email'], "text"),
                      GetSQLValueString($_POST['id'], "int"));

  mysqli_select_db($database_mysqli, $mysqli);
  $Result1 = mysqli_query($updateSQL, $mysqli) or die(mysql_error());
}
Avatar billede Slater Ekspert
29. marts 2015 - 22:33 #1
Nu står der "Undefined variable: mysqli", så er det jo ret nærliggende at kigge på din variabel $mysqli.

Du sætter den ikke til noget i stedet kode vi kan se, og eftersom du får den fejl, er ret ganske sandsynligt at du slet ikke sætter den.
Det allerførste du skal gøre er at oprette din databaseforbindelse med mysqli_connect() eller new mysqli().


Dernæst bruger du funktionen mysqli_real_escape_string() med omvendt parameterrækkefølge. Det første argument skal være mysqli-linket og nummer to strengen, ikke omvendt som du gør.
Avatar billede olsensweb.dk Ekspert
29. marts 2015 - 22:58 #2
som tillæg til viperine's kommentar, vedr. din connection: du anvender din connection inde i en function, uden at tage den med over i functionen, så connection er ikke i det scope du arbejder i inde i functionen

i denne linje mangler du at overføre din connection
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

alternativt, kan man i nødstilfælde anvende global
men det kræver variablen udenfor functionen og inde i functionen hedder det sammen, og functionen bliver ikke lige så anvendelig / genbrugbar som man kunne ønske sig.

kig godt på http://www.eksperten.dk/spm/1002358 #22
Avatar billede Morten Professor
29. marts 2015 - 23:02 #3
Har fået rettet det med retningen.

Men det er
  $theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($mysqli, $theValue ) : mysqli_escape_string($mysqli, $theValue );

Der er problemet.

Her er koden lige igen med det hele.

<?php require_once('Connections/mysqli.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("mysqli_real_escape_string") ? mysqli_real_escape_string($mysqli, $theValue ) : mysqli_escape_string($mysqli, $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_update"])) && ($_POST["MM_update"] == "oplysninger")) {
  $updateSQL = sprintf("UPDATE test SET navn=%s, efternavn=%s, adresse=%s, postnr=%s, bynavn=%s, nummer=%s, email=%s WHERE id=%s",
                      GetSQLValueString($_POST['navn'], "text"),
                      GetSQLValueString($_POST['efternavn'], "text"),
                      GetSQLValueString($_POST['adresse'], "text"),
                      GetSQLValueString($_POST['postnr'], "int"),
                      GetSQLValueString($_POST['bynavn'], "text"),
                      GetSQLValueString($_POST['nummer'], "int"),
                      GetSQLValueString($_POST['email'], "text"),
                      GetSQLValueString($_POST['id'], "int"));

  mysqli_select_db($mysqli, $database_mysqli );
  $Result1 = mysqli_query($mysqli, $updateSQL) or die(mysql_error());
}

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("mysqli_real_escape_string") ? mysqli_real_escape_string($theValue, $mysqli) : mysqli_escape_string($theValue, $mysqli);

  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;
}
}

$mysqli = mysqli_connect("localhost","root","","mysqli");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$query_rsOplysninger = "SELECT * FROM test";
$rsOplysninger = mysqli_query($mysqli, $query_rsOplysninger) or die(mysql_error());
$row_rsOplysninger = mysqli_fetch_assoc($rsOplysninger);
$totalRows_rsOplysninger = mysqli_num_rows($rsOplysninger);
?>
Avatar billede Morten Professor
29. marts 2015 - 23:33 #4
har prøvet med
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($mysqli, $theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue =  mysqli_real_escape_string($mysqli,$theValue);

men så kommer den med denne fejl + den anden.
Warning: Missing argument 3 for GetSQLValueString(), called in C:\wamp\www\mysqli\index.php on line 43 and defined in C:\wamp\www\mysqli\index.php on line 4
Avatar billede Morten Professor
29. marts 2015 - 23:50 #5
Det virkede med global.

Takker :)

Her er svaret, hvis andre skulle for brug for det:

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
    global $mysqli;
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue =  mysqli_real_escape_string($mysqli,$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_update"])) && ($_POST["MM_update"] == "oplysninger")) {
  $updateSQL = sprintf("UPDATE test SET navn=%s, efternavn=%s, adresse=%s, postnr=%s, bynavn=%s, nummer=%s, email=%s WHERE id=%s",
                      GetSQLValueString($_POST['navn'], "text"),
                      GetSQLValueString($_POST['efternavn'], "text"),
                      GetSQLValueString($_POST['adresse'], "text"),
                      GetSQLValueString($_POST['postnr'], "int"),
                      GetSQLValueString($_POST['bynavn'], "text"),
                      GetSQLValueString($_POST['nummer'], "int"),
                      GetSQLValueString($_POST['email'], "text"),
                      GetSQLValueString($_POST['id'], "int"));

  mysqli_select_db($mysqli, $database_mysqli );
  $Result1 = mysqli_query($mysqli, $updateSQL) or die(mysql_error());
}

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("mysqli_real_escape_string") ? mysqli_real_escape_string($theValue, $mysqli) : mysqli_escape_string($theValue, $mysqli);

  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;
}
}

$mysqli = mysqli_connect("localhost","root","","mysqli");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$query_rsOplysninger = "SELECT * FROM test";
$rsOplysninger = mysqli_query($mysqli, $query_rsOplysninger) or die(mysql_error());
$row_rsOplysninger = mysqli_fetch_assoc($rsOplysninger);
$totalRows_rsOplysninger = mysqli_num_rows($rsOplysninger)
Avatar billede Morten Professor
29. marts 2015 - 23:52 #6
Hej ronols

Vil du gøre så jeg kan give dig point.

Og tak for hjælpen i to.

Med venlig hilsen
Morten
Avatar billede arne_v Ekspert
29. marts 2015 - 23:58 #7
Var det ikke en ide at bruge prepare????
Avatar billede Morten Professor
30. marts 2015 - 00:02 #8
Skøno så kunne jeg også finde ud af at lave min insert :-)
Avatar billede Morten Professor
30. marts 2015 - 00:03 #9
Hej arne_v

Hvordan skal det strikkes sammen?
Avatar billede olsensweb.dk Ekspert
30. marts 2015 - 00:04 #10
du kan godt få et svar, men jeg vil fraråde dig at anvende global.
da du ikke har styr på hvor din variabel bliver ændret, og du er bundet at variabel navnet udenfor functionen, skal hedde det sammen som inde i functionen.

det er ikke særligt flexibelt.
hvis du tager den over som parameter bliver functionen mere anvendelig


>$mysqli = mysqli_connect("localhost","root","","mysqli");
ref ("localhost","root","","mysqli")
hedder din database mysqli ?? mærkeligt navn til en database.

$mysqli er din connection, hvilke giver mening.

jeg mener viperine kom med en stor del af svaret, så det være en deler.

@viperine: smider du et svar også.
Avatar billede olsensweb.dk Ekspert
30. marts 2015 - 00:09 #11
#9
kig på olebole's guide http://www.eksperten.dk/guide/1480
Prepare Statement skal man lige vende sig til.

hvis du vil anvende Prepare statement vil jeg anbefale dig at droppe mysqli og skifte til PDO istedet, der er Prepare Statement mere udviklet.
Avatar billede Morten Professor
30. marts 2015 - 00:14 #12
Ja gør meget gerne det dejligt i hjalp mig
Avatar billede Morten Professor
30. marts 2015 - 00:16 #13
Hvordan for jeg den til at være i parameter.
Jeg forstår det ikke helt.
Er global ikke sikker nok?
Avatar billede Morten Professor
30. marts 2015 - 09:38 #14
if ($stmt = mysqli_prepare($mysqli, "GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
   
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($mysqli, $theValue) : mysqli_escape_string($mysqli, $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;
}
}


Og det virkede, men er det rigtigt.
Avatar billede Morten Professor
30. marts 2015 - 10:01 #15
Behøver jeg enlig

if ($mysqli_stmt = mysqli_prepare($mysqli, "GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

Når det er mysqli?
Avatar billede Morten Professor
30. marts 2015 - 10:04 #16
Ja det gør jeg vist
Avatar billede olsensweb.dk Ekspert
30. marts 2015 - 11:10 #17
#13
jeg vil starte med at ændre parameter rækkefølgen, der giver mere mening, og ligge functionen ud i en seperat fil da den skal bruges i flere filer.

jeg vil have min connection som FØRSTE parameter, da den altid SKAL med over i functionen, da jeg anvender en sql funktion (mysqli_real_escape_string) og en connection KAN ikke have default værdi

derefter giver det mening at have typen som anden parameter, da denne også altid skal angives, og så værdien, der kan have en default værdi

mysqli_toolbox.php

<?php
function GetSQLValueString($conn, $theType, $theValue="") {   
    // http://php.net/manual/en/function.get-magic-quotes-gpc.php
    // 5.4.0     Always returns FALSE because the magic quotes feature was removed from PHP.        
    if (PHP_VERSION < "5.4.0") {                       
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    }   
   
    switch ($theType) {
        case "date":           
        case "text":
            $theValue = mysqli_real_escape_string($conn, $theValue);       
            $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
            break;
        case "long":
        case "int":
            $theValue = ($theValue != "") ? intval($theValue) : "NULL";
            break;
        case "double": // doubleval er et alias for floatval
        case "float":       
            $theValue = ($theValue != "") ? floatval($theValue) : "NULL";
            break;               
        default: $theValue="NULL"; break;   
    }
    return $theValue;
}
?>



ændringen af parameter rækkefølgen i GetSQLValueString, afspejler sig i kaldet af functionen

index.php (eller hvad du nu kalder din php fil)
(utested)

require_once("mysqli_toolbox.php"); // GetSQLValueString

$mysqli = mysqli_connect("localhost","root","","mysqli");
// Check connection
if (mysqli_connect_errno())
{
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// mysqli_select_db($mysqli, $database_mysqli ); // gøres i mysqli_connect


$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "oplysninger")) {
  $updateSQL = sprintf("UPDATE test SET navn=%s, efternavn=%s, adresse=%s, postnr=%s, bynavn=%s, nummer=%s, email=%s WHERE id=%s",
                      GetSQLValueString($mysqli, "text"$_POST['navn']),
                      GetSQLValueString($mysqli, "text"$_POST['efternavn']),
                      GetSQLValueString($mysqli, "text"$_POST['adresse']),
                      GetSQLValueString($mysqli, "int"$_POST['postnr']),
                      GetSQLValueString($mysqli, "text"$_POST['bynavn']),
                      GetSQLValueString($mysqli, "int"$_POST['nummer']),
                      GetSQLValueString($mysqli, "text"$_POST['email']),
                      GetSQLValueString($mysqli, "int"$_POST['id']));
 
  $Result1 = mysqli_query($mysqli, $updateSQL) or die(mysqli_error($mysqli));
}



vedr Prepare Statementm hvis du er til video:
prøv at kigge på disse (har ikke selv set dem)
mysqli
(har jeg hørt godt om)
http://www.nemprogrammering.dk/Tutorials/MySQL/MySQLi-OOP/5-prepared-statements.php

pdo
http://www.nemprogrammering.dk/Tutorials/PDO/4-prepared-statements.php

#14
i Prepare Statement skal du slet ikke anvende GetSQLValueString, alt det sker i
/* Bind parametre */
$stmt->bind_param('i', $id);
Avatar billede olsensweb.dk Ekspert
30. marts 2015 - 11:31 #18
med Prepare Statement i mysqli vil det se ca sådan ud
index.php (eller hvad du nu kalder din php fil)
(utested)

$mysqli = mysqli_connect("localhost","root","","mysqli");
// Check connection
if (mysqli_connect_errno())
{
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// mysqli_select_db($mysqli, $database_mysqli ); // gøres i mysqli_connect


$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "oplysninger")) {

    $updateSQL = "UPDATE test SET navn=?, efternavn=?, adresse=?, postnr=?, bynavn=?, nummer=?, email=? WHERE id=?";
    /* Opret et prepared statement */
    if ($stmt = $mysqli->prepare($updateSQL)) {
        /* Bind parametre */
        $stmt->bind_param('sssisisi',$navn,$efternavn,$adresse,$postnr,$bynavn,$nummer,$email,$id);

        /* Sæt værdier på parametrene */
        $navn = $_POST['navn'];   
        $efternavn = $_POST['efternavn'];   
        $adresse = $_POST['adresse'];   
        $postnr = $_POST['postnr'];
        $bynavn = $_POST['bynavn'];
        $nummer = $_POST['nummer'];   
        $email = $_POST['email'];
        $id = $_POST['id'];

        /* Eksekver forespørgslen */
        $stmt->execute();

        /* Luk statement */
        $stmt->close();
    }
    else {
        /* Der er opstået en fejl */
        echo 'Der opstod en fejl i erklæringen: ' . $mysqli->error;
    }
}
Avatar billede Morten Professor
30. marts 2015 - 12:12 #19
Må jeg gøre sådan?

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $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;
}
}
?>

For så virker det upåklageligt.
Og så kan jeg bruge toolbox.php
Avatar billede olsensweb.dk Ekspert
30. marts 2015 - 14:03 #20
#19
>Må jeg gøre sådan?
det må du godt.

der har du så fjernet mysqli_real_escape_string() og dermed behovet for at bruge en db connection.
du har dermed også fjernet en stor del af beskyttelsen, og dermed også noget af berettigelsen af functionen.

Q: hvad sker der hvis programmæren skriver en datatype der ikke existerer ?? (programmører begår også fejl)
A: værdien bliver hverken sat i plinger eller på nogle måder sikret
løsning: lav en default i din switch


nb: jeg vil foreslå dig at lave din connection som en function, som du meget passende kan placerer i mysqli_toolbox.php

(har selv tidligere brugt disse)

<?php
// overvej function MySqlIConnProceduralStyle($db = "", $username = "", $password = "", $hostname = "") {
function MySqlIConnProceduralStyle($db = "") {
    $db = ($db == "") ? "test" : $db;
    $conn = mysqli_connect("localhost", "root", "", $db);
    if (!$conn) {
        echo 'Der opstod en fejl.';
        exit();
    }
    mysqli_set_charset($conn, "utf8");
    return $conn;
}

// overvej function MySqlIConnOOP($db = "", $username = "", $password = "", $hostname = "") {
function MySqlIConnOOP($db = "") {
    $db = ($db == "") ? "test" : $db;
    $conn = new mysqli('localhost', 'root', '', $db);
    /* check connection */
    if (!$conn) {
        echo 'Der opstod en fejl.';
        exit();
    }
    $conn->set_charset("utf8");
    return $conn;
}
?>
Avatar billede Morten Professor
30. marts 2015 - 14:41 #21
Jeg kan bare ikke få den her til at virke, prøver alt muligt.

  $theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($mysqli, $theValue) : mysqli_escape_string($mysqli, $theValue);
Avatar billede olsensweb.dk Ekspert
30. marts 2015 - 15:02 #22
har du prøvet
$theValue = mysqli_real_escape_string($mysqli, $theValue); 

og selvføgelig gjort din mysqli variabelen tilgøngelig enten via en parameter eller ved brug af global
Avatar billede Morten Professor
30. marts 2015 - 15:51 #23
Ja det har jeg.
Det der med parameter hvordan gør jeg det?
Avatar billede olsensweb.dk Ekspert
30. marts 2015 - 16:53 #24
>Det der med parameter hvordan gør jeg det?
prøv at se i #17, hvor jeg kalder den $conn
function GetSQLValueString($conn,

og kaldet af functionen
GetSQLValueString($mysqli,
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester