Jump to content
php.lv forumi

Undefined index


Recommended Posts

Posted (edited)

<?php
require ($_SERVER["DOCUMENT_ROOT"]."/folder/config.php");
$connection = @mysql_connect($db_host, $db_user, $db_password) or die ("error connecting");
mysql_select_db($db_name, $connection);

$name = $_POST["txt_name"];
$len = strlen ($name);
//Only write to database if there's a name
if ($len > 0)
{
	$email = $_POST["txt_email"];
	$comment = $_POST["txt_comment"];
	$date = time();

	$query = "INSERT INTO guestbook (autoID, name, email, comment, date_auto) VALUES (NULL, '$name', '$email', '$comment', '$date')";
	mysql_query($query, $connection) or die (mysql_error());
}
?>

 

Problema: Notice: Undefined index: txt_name in E:\webroot\guestbook.php on line 5

($name = $_POST["txt_name"];)

 

kur kluda?

Edited by didy
Posted

Nuja nav nopostēta forma, tad loģiski, ka notice.

 

Vajag ar isset vai empty vispirms pārbaudīt vai mainīgais eksistē un tad tikai kaut ko darīt ar to.

Posted

Forma ir noposteta!

Ta ka esmu iesacejs php, nevareju isti saprast ka parbaudiit ar isset vai empty! Varbut var lugt isu uzmetumu!

Posted (edited)

Foruma vieta varetu ielikt saiti uz php.net un google.lv un varbuut uz wiki! Tas pats vien butu! Vareji jau njemt vera kad teicu

"nevareju isti saprast ka parbaudiit ar isset vai empty"

Meginaju ka paradiits isset() - nekada rezultata! Tadel jau nacu uz forumu pec palidzibas! Bet paldies! Gan jau tiku gala!

Edited by didy
Posted

Pateicos! Izradas ka biju darijis pareizi tikai nepamanijis, ka Undefined index problema parlekusi uz nakamo $var

Izlaboju kludas! Paldies!

×
×
  • Create New...