Remember me - Lost password?
fdicarlo : about 1 year ago
domanda #php, non conosco questo linguaggio ma purtroppo devo usarlo in questo caso, ora ho un file così:
code


require "includes/connect.php";

$msg = '';

if($_POST['email']){

// Requested with AJAX:
$ajax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest');

try{
if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){
throw new Exception('Invalid Email!');
}

$mysqli->query("INSERT INTO coming_soon_emails
SET email='".$mysqli->real_escape_string($_POST['email'])."'");

if($mysqli->affected_rows != 1){
throw new Exception('This email already exists in the database.');
}

if($ajax){
die('{"status":1}');
}

$msg = "Thank you!";

}
catch (Exception $e){

if($ajax){
die(json_encode(array('error'=>$e->getMessage())));
}

$msg = $e->getMessage();
}
}


dove il connect.php è
code

<?php

error_reporting(E_ALL ^ E_NOTICE);

$db_host = '';
$db_user = '';
$db_pass = '';
$db_name = '';

@$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);

if (mysqli_connect_errno()) {
die('<h1>Could not connect to the database</h1><h2>Please try again after a few moments.</h2>');
}

$mysqli->set_charset("utf8");


?>


Ora se non volessi usare un db mysql, perchè troppo impegnativo per quello che devo fare, cosa devo cambiare per scrivere in un file txt?
from Latina in php 7 replies -
Nemuriko : about 1 year ago
Scusa, non ho capito. La domanda è: come fare a scrvere su un file?
from sospesa tra Bergamo e Brescia detail
m3c__ : about 1 year ago
eh devi cambiare tutto... la connect.php puoi buttarla via, ma devi cambiare tutto il codice per salvare e leggere dal file. Dai un occhio a funzioni come fclose(), fread() e fwrite()...
from nato a Locarno - vivo a Pantelleria detail
fdicarlo : about 1 year ago
si @Nemuriko se io dovessi riutilizzare il codice della pagina, ma non scrivendo su un db ma su un txt, cosa dovrei usare? non conosco php quindi chiedo a voi guru
from Latina detail
Nemuriko : about 1 year ago
Come ti diceva m3c connect.php non ti serve.
Non ti serve neanche query.
Al posto di quello devi dare un fwrite.
Il resto è tutra gestione degli errori.
Scegli tu come farla.

Guarda la documentazione di fopen, fwrite, fread e fcose.
from sospesa tra Bergamo e Brescia detail
Nemuriko : about 1 year ago
Scusa ma sono sul tablet e favvio un po' fatica a scrivere. ^_^'
from sospesa tra Bergamo e Brescia detail
fdicarlo : about 1 year ago
@nemuriko sei stata gentilissima così grazie anche a @m3c
from Latina detail
Nemuriko : about 1 year ago
In pratica devi solo cambiare 2 righe
from sospesa tra Bergamo e Brescia detail
New to meemi?
Join now to quickly and easily way

Problem? Rigenerate new code
By clicking the button, you agree all terms of service