Помощ с един код мисля че подредбата е неправилна!

goshkoy

Registered
PHP:
<?php
	session_start();
	include("config.php");

	if(isset($_SESSION['logged']) == true) {
		$sql = "SELECT * FROM `oborot` WHERE `magazin_id`='" . $_SESSION['userinfo']['magazin_id'] . "'";
		$rs = mysql_query($sql);
		$data = mysql_fetch_assoc($rs);
		$antispam1 = rand(1,20);
		$antispam2 = rand(1,10);
		$antispamrs = $antispam1 + $antispam2;
		$obshto = "";
		$obshto2 = "";
?>
	<html>
	<head>
		<title><?php echo $title; ?></title>
	</head>
	<body>
		<div align="right"><a href="logout.php">[X]</a></div>
		<table border="1" cellpadding="3" cellspacing="10">
			<tr>
				<th>Име</th>
				<th>Статус</th>
				<th>Попълнете желания брой</th>
				<th>Единична цена</th>
				<th>Общо</th>
			</tr>
			<tr>
				<td><?php echo $_SESSION['userinfo']['firstname']; ?></td>
				<td><br>Номер:<?php echo $_SESSION['userinfo']['nomer']; ?></br>
					<br>Магазин:<?php echo $_SESSION['userinfo']['magazin_id']; ?></br></td>
				<td><input type="text" name="broi" size="5"></td>
				<td><input type="text" name="cena" size="5"></td>
				<td><?php echo $obshto; ?></td>
				
			</tr>
			<tr>
				<td><?php echo $_SESSION['userinfo']['firstname']; ?></td>
				<td><br>Номер:<?php echo $_SESSION['userinfo']['nomer']; ?></br>
					<br>Магазин:<?php echo $_SESSION['userinfo']['magazin_id']; ?></br></td>
				<td><input type="text" name="broi2" size="5"></td>
				<td><input type="text" name="cena2" size="5"></td>
				<td><?php echo $obshto2; ?></td>
			</tr>
		</table>
		<div align="center">
			<?php
				echo $antispam1; 
				echo "+"; 
				echo $antispam2;
				echo "=";
			?>
			<form action="" method="POST">
				<input type="text" name="rstest" size="6">
				<br><input type="submit" name="update" value="Обнови"></br>
			</form>
			<?php
				if($_SESSION['userinfo']['nivo'] == 1) { 
			?>
				Оборот общо:<input type="text" name="oborot" value=<?php echo $data['oborot']; ?>>
			<?php
				}
				else {
					echo "Оборот общо:";
					echo $data['oborot']; 
				}
				if(isset($_POST['update'])) {
					$broi = trim($_POST['broi']);
					$broi2 = trim($_POST['broi2']);
					$cena = trim($_POST['cena']);
					$cena2 = trim($_POST['cena2']);
					$antispamrs2 = trim($_POST['rstest']);
					$oborot = trim($_POST['oborot']); 
					$obshto = $broi * $cena;
					$obshto2 = $broi2 * $cena2;
					$obshto3 = $obshto + obshto2;
					$oborotobshto = $data['oborot'] + $obshto;
					if(!is_numeric($broi)) {
						$error = 1;
						echo "Желания брой който сте попълнили съдържа непозволени символи, моля използвайте само цифри";
					}
					
					elseif ($antispamrs != $antispamrs2) {
						$error = 1;
						echo '<font color="red">Кодът който сте въвели за защита е грешен</font>';
					}
					else {
						$error = 0;
					}
					if($error == 0) {
						$sql = "UPDATE `oborot` SET `oborot` = '" . $oborotobshto . "' WHERE `magazin_id` = '" . $data['magazin_id'] . "'";
						$rs = mysql_query($sql) or die(mysql_error());
						if($_SESSION['userinfo']['nivo'] == 1) {
							$sql = "UPDATE `oborot` SET `oborot`='" . $oborot . "' WHERE `magazin_id`='" . $data['magazin_id'] . "'";
							$rs = mysql_query($sql);
						}
					}
			?>
		</div>
		
<?php
		}
	}
	else {
		echo "Моля влезте в системата!";
		include("login.php");
	
}
?>
	</body>
</html>

Грешката
Код:
Notice: Undefined index: broi in D:\xampp\htdocs\zadacha\index.php on line 68

Notice: Undefined index: broi2 in D:\xampp\htdocs\zadacha\index.php on line 69

Notice: Undefined index: cena in D:\xampp\htdocs\zadacha\index.php on line 70

Notice: Undefined index: cena2 in D:\xampp\htdocs\zadacha\index.php on line 71

Notice: Undefined index: rstest in D:\xampp\htdocs\zadacha\index.php on line 72

Notice: Undefined index: oborot in D:\xampp\htdocs\zadacha\index.php on line 73
 

nom3r1

Registered
Използвай isset(); Показва дали дадена променлива е използвана, ако не е връща "FALSE". Ето ти кода..

PHP:
<?php
        session_start();
        include("config.php");

        if(isset($_SESSION['logged']) == true) {
                $sql = "SELECT * FROM `oborot` WHERE `magazin_id`='" . $_SESSION['userinfo']['magazin_id'] . "'";
                $rs = mysql_query($sql);
                $data = mysql_fetch_assoc($rs);
                $antispam1 = rand(1,20);
                $antispam2 = rand(1,10);
                $antispamrs = $antispam1 + $antispam2;
                $obshto = "";
                $obshto2 = "";
?>
        <html>
        <head>
                <title><?php echo $title; ?></title>
        </head>
        <body>
                <div align="right"><a href="logout.php">[X]</a></div>
                <table border="1" cellpadding="3" cellspacing="10">
                        <tr>
                                <th>Име</th>
                                <th>Статус</th>
                                <th>Попълнете желания брой</th>
                                <th>Единична цена</th>
                                <th>Общо</th>
                        </tr>
                        <tr>
                                <td><?php echo $_SESSION['userinfo']['firstname']; ?></td>
                                <td><br>Номер:<?php echo $_SESSION['userinfo']['nomer']; ?></br>
                                        <br>Магазин:<?php echo $_SESSION['userinfo']['magazin_id']; ?></br></td>
                                <td><input type="text" name="broi" size="5"></td>
                                <td><input type="text" name="cena" size="5"></td>
                                <td><?php echo $obshto; ?></td>
                                
                        </tr>
                        <tr>
                                <td><?php echo $_SESSION['userinfo']['firstname']; ?></td>
                                <td><br>Номер:<?php echo $_SESSION['userinfo']['nomer']; ?></br>
                                        <br>Магазин:<?php echo $_SESSION['userinfo']['magazin_id']; ?></br></td>
                                <td><input type="text" name="broi2" size="5"></td>
                                <td><input type="text" name="cena2" size="5"></td>
                                <td><?php echo $obshto2; ?></td>
                        </tr>
                </table>
                <div align="center">
                        <?php
                                echo $antispam1; 
                                echo "+"; 
                                echo $antispam2;
                                echo "=";
                        ?>
                        <form action="" method="POST">
                                <input type="text" name="rstest" size="6">
                                <br><input type="submit" name="update" value="Обнови"></br>
                        </form>
                        <?php
                                if($_SESSION['userinfo']['nivo'] == 1) { 
                        ?>
                                Оборот общо:<input type="text" name="oborot" value=<?php echo $data['oborot']; ?>>
                        <?php
                                }
                                else {
                                        echo "Оборот общо:";
                                        echo $data['oborot']; 
                                }
                                if(isset($_POST['update'])) {
									if(isSet($_POST['broi'])) {
										$broi = trim($_POST['broi']);
									} else {
										$broi = "";
									}
									if(isSet($_POST['broi2'])) {
										$broi2 = trim($_POST['broi2']);
									} else {
										$broi2 = "";
									}
									if(isSet($_POST['cena'])) {
										$cena = trim($_POST['cena']);
									} else {
										$cena = "";
									}
									if(isSet($_POST['cena2'])) {
										$cena2 = trim($_POST['cena2']);
									} else {
										$cena2 = "";
									}
									if(isSet($_POST['rstest'])) {
										$rstest = trim($_POST['rstest']);
									} else {
										$rstest = "";
									}
									if(isSet($_POST['oborot'])) {
										$oborot = trim($_POST['oborot']);
									} else {
										$oborot = "";
									}
                                        $obshto = $broi * $cena;
                                        $obshto2 = $broi2 * $cena2;
                                        $obshto3 = $obshto + obshto2;
                                        $oborotobshto = $data['oborot'] + $obshto;
                                        if(!is_numeric($broi)) {
                                                $error = 1;
                                                echo "Желания брой който сте попълнили съдържа непозволени символи, моля използвайте само цифри";
                                        }
                                        
                                        elseif ($antispamrs != $antispamrs2) {
                                                $error = 1;
                                                echo '<font color="red">Кодът който сте въвели за защита е грешен</font>';
                                        }
                                        else {
                                                $error = 0;
                                        }
                                        if($error == 0) {
                                                $sql = "UPDATE `oborot` SET `oborot` = '" . $oborotobshto . "' WHERE `magazin_id` = '" . $data['magazin_id'] . "'";
                                                $rs = mysql_query($sql) or die(mysql_error());
                                                if($_SESSION['userinfo']['nivo'] == 1) {
                                                        $sql = "UPDATE `oborot` SET `oborot`='" . $oborot . "' WHERE `magazin_id`='" . $data['magazin_id'] . "'";
                                                        $rs = mysql_query($sql);
                                                }
                                        }
                        ?>
                </div>
                
<?php
                }
        }
        else {
                echo "Моля влезте в системата!";
                include("login.php");
        
}
?>
        </body>
</html>
 

Горе