PHP: problema con query mysql.

Lui Bardella

Nuovo Utente
19 Mag 2013
4
0
0
Ciao a tutti ragazzi.
Ho un problema:
Ho creato un tool per l'invio di mail anonime...ma per sicurezza vorrei che l'ip,l'ora e la data,l'oggetto,Il testo,il destinatario e Il mittente venissero inseriti nel database.
Tutto funziona bene ma i dati non vengono inseriti nel database...ho commesso un errore nel PHP ? :fuck:

index.php:
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>...</title>
<?php
include 'config.php';
connect();
$to= $_POST["to"];
$from= "From: ".$_POST["from"];
$subject= $_POST["subject"];
$text= $_POST["text"];
$ip= $_SERVER['REMOTE_ADDR'];
$to_control= strpos("$to","@");
$select_to_db = mysql_query("SELECT * FROM mail_ WHERE ip = '$ip'");
$count = mysql_num_rows($select_to_db);
?>
</head>

<body>
<div id="wrapper">
<form action="#" method="post" name="email">
<input name="to" type="text" onFocus="this.value='';" value="To:" /><br/><br/>
<input name="from" type="text" onFocus="this.value='';" value="From:" /><br/><br/>
<input name="subject" type="text" onFocus="this.value='';" value="Subject:" /><br/><br/>
<textarea name="text" cols="" rows="" onFocus="this.value='';">
</textarea><bR /><br/>
<input name="submit" type="submit" value="submit mail." />
</form>
<?php 
if (isset($_POST["submit"])){
if ($to == '' OR $from == '' OR $subject == '' OR $text == ''){
$result= 'Error n1: "You need to fill in all fields."';
}else if($to_control == 0){
$result= 'Error n2: "You need to enter a valid email address in the field to."';
}else if(count > 3){
$result= 'Error n3: "have exceeded the maximum number of emails a day, to remove this limit
becomes premium."';	
}else{
mysql_query("INSERT INTO mail_   (To,From,Subject,Text,Ip) VALUES ('$to','$from','$subject','$text','$ip');");

$send_mail = mail($to,$subject,$text,$from);
if ($send_mail){
$result= 'e-mail sent successfully.';
}else{
$result= 'Error n4: "server fatal error."';
};

};
echo $result;
};
echo '<br/>Your IP address will be recorded. - ('.$ip.').';

?>
</div>
</body>
</html>


config.php
PHP:
<?php
function connect(){
mysql_connect("localhost","lui199909","password");
mysql_select_db("my_lui199909");
};
?>
dov'è l'errore? :crying:
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.041
146
63
PR
www.borgo-italia.it
ciao
PHP:
//.............
}else{
		//dividi la query e controllala
		$q="INSERT INTO mail_   (To,From,Subject,Text,Ip) VALUES ('$to','$from','$subject','$text','$ip')";//e togli il ; interno a "
		var_dump($q); //qui vedi come viene scritta
		$ris=mysql_query($q):
		var_dump($ris);// se fallita => bool false, se ok => resuorce
		$send_mail = mail($to,$subject,$text,$from);
//..........
 

Lui Bardella

Nuovo Utente
19 Mag 2013
4
0
0
Up

Mi permetto di Uppare il post... :|
Ciao a tutti ragazzi.
Ho un problema:
Ho creato un tool per l'invio di mail anonime...ma per sicurezza vorrei che l'ip,l'ora e la data,l'oggetto,Il testo,il destinatario e Il mittente venissero inseriti nel database.
Tutto funziona bene ma i dati non vengono inseriti nel database...ho commesso un errore nel PHP ? :fuck:

index.php:
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>...</title>
<?php
include 'config.php';
connect();
$to= $_POST["to"];
$from= "From: ".$_POST["from"];
$subject= $_POST["subject"];
$text= $_POST["text"];
$ip= $_SERVER['REMOTE_ADDR'];
$to_control= strpos("$to","@");
$select_to_db = mysql_query("SELECT * FROM mail_ WHERE ip = '$ip'");
$count = mysql_num_rows($select_to_db);
?>
</head>

<body>
<div id="wrapper">
<form action="#" method="post" name="email">
<input name="to" type="text" onFocus="this.value='';" value="To:" /><br/><br/>
<input name="from" type="text" onFocus="this.value='';" value="From:" /><br/><br/>
<input name="subject" type="text" onFocus="this.value='';" value="Subject:" /><br/><br/>
<textarea name="text" cols="" rows="" onFocus="this.value='';">
</textarea><bR /><br/>
<input name="submit" type="submit" value="submit mail." />
</form>
<?php 
if (isset($_POST["submit"])){
if ($to == '' OR $from == '' OR $subject == '' OR $text == ''){
$result= 'Error n1: "You need to fill in all fields."';
}else if($to_control == 0){
$result= 'Error n2: "You need to enter a valid email address in the field to."';
}else if(count > 3){
$result= 'Error n3: "have exceeded the maximum number of emails a day, to remove this limit
becomes premium."';	
}else{
mysql_query("INSERT INTO mail_   (To,From,Subject,Text,Ip) VALUES ('$to','$from','$subject','$text','$ip');");

$send_mail = mail($to,$subject,$text,$from);
if ($send_mail){
$result= 'e-mail sent successfully.';
}else{
$result= 'Error n4: "server fatal error."';
};

};
echo $result;
};
echo '<br/>Your IP address will be recorded. - ('.$ip.').';

?>
</div>
</body>
</html>


config.php
PHP:
<?php
function connect(){
mysql_connect("localhost","lui199909","password");
mysql_select_db("my_lui199909");
};
?>
dov'è l'errore? :crying: