shone83
Poštovan
- Učlanjen(a)
- 04.11.2015
- Poruke
- 49
- Poena
- 54
Postavicu uproscen kod (bez sql injection, pdo i slicno) da bi lakse razumeli sta mi treba...
Imam na jednoj stranici pretragu koja prikazuje red iz mysql baze i ona radi i jos jedan submit gde me redirektuje na drugu stranicu, gde bi trebalo da pokupim podatke iz pretrage i dalje da ih obradjujem. Izgleda ovako:
search.php
i to me redirektuje na sledecu stranicu:
add.php
Medjutim tu umesto da mi u formi izbaci ono iz tabele na prvoj stranici, izbacuje mi ovo:
Notice: Undefined index: ime in C:\xampp\htdocs\test\add.php on line 23
Notice: Undefined index: prezime in C:\xampp\htdocs\test\add.php on line 24
Notice: Undefined index: jmbg in C:\xampp\htdocs\test\add.php on line 25
Notice: Undefined index: ulica in C:\xampp\htdocs\test\add.php on line 26
i u formi:
<br /><b>Notice</b>: Undefined variable: name_b in <b>C:\xampp\htdocs\test\add.php</b> on line <b>57</b><br />
<br /><b>Notice</b>: Undefined variable: lname_b in <b>C:\xampp\htdocs\test\add.php</b> on line <b>63</b><br />
<br /><b>Notice</b>: Undefined variable: number_b in <b>C:\xampp\htdocs\test\add.php</b> on line <b>69</b><br />
<br /><b>Notice</b>: Undefined variable: street_b in <b>C:\xampp\htdocs\test\add.php</b> on line <b>74</b><br />
Znam da je greska u drugoj stranici gde nisam lepo variable odradio ali ne mogu da ukapiram kako...?
Imam na jednoj stranici pretragu koja prikazuje red iz mysql baze i ona radi i jos jedan submit gde me redirektuje na drugu stranicu, gde bi trebalo da pokupim podatke iz pretrage i dalje da ih obradjujem. Izgleda ovako:
search.php
Kod:
<form action="" method="post">
<label for=""><h4>Insert number</h4></label>
<div>
<input name="search_number" type="number">
<button name="submit" type="submit" value="Find">Submit</button>
<hr>
</div>
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>LName</th>
<th>Number</th>
<th>Street</th>
</tr>
</thead>
<tbody>
</tbody>
<?php
if(isset($_POST['search_number'])) {
$number = $_POST['search_number'];
mysqli_set_charset($connection, "utf8");
$query = "SELECT * FROM b_spisak WHERE jmbg = '$number' LIMIT 1";
$search_number_query = mysqli_query($connection, $query);
if(!$search_number_query) {
die("Query Failed" . mysqli_error($connection));
}
if(mysqli_num_rows($search_number_query) > 0) {
while($row = mysqli_fetch_assoc($search_number_query)) {
$b_id = $row['id'];
$b_name = $row['ime'];
$b_lname = $row['prezime'];
$b_number = $row['jmbg'];
$b_street = $row['ulica'];
echo "<tr>";
echo "<td>{$b_id}</td>";
echo "<td>{$b_name}</td>";
echo "<td>{$b_lname}</td>";
echo "<td>{$b_number}</td>";
echo "<td>{$b_street}</td>";
}
} else {
echo "Number does not exist!";
}
}
?>
</table>
<button type="submit" name="add" formaction="add.php" >Add</button>
<hr>
</form>
i to me redirektuje na sledecu stranicu:
add.php
Kod:
<?php
if(isset($_POST['add'])) {
$b_id = $_POST['add'];
$b_name = $_POST['ime'];
$b_lname = $_POST['prezime'];
$b_number = $_POST['jmbg'];
$b_street = $_POST['ulica'];
$query = mysqli_query($connection, "set names utf8");
$query = "SELECT * FROM b_spisak WHERE id = '$b_id'";
$add_query = mysqli_query($connection, $query);
if(!$add_query) {
die("QueryFailed" . mysqli_error($connection));
}
while($row = mysqli_fetch_assoc($add_query)) {
$id_b = $row['id'];
$name_b = $row['ime'];
$lname_b = $row['prezime'];
$number_b = $row['jmbg'];
$street_b = $row['ulica'];
}
}
?>
<form action="" method="post">
<div>
<div>
<input type="text" name="name" placeholder="Name" value="<?php echo $name_b; ?>">
</div>
</div>
<div>
<div>
<input type="text" name="lname" placeholder="LName" value="<?php echo $lname_b; ?>">
</div>
</div>
<div>
<div>
<input type="text" name="jmbg" placeholder="JMBG" value="<?php echo $number_b; ?>">
</div>
</div>
<div>
<div>
<input type="text" name="name" placeholder="Name" value="<?php echo $street_b; ?>">
</div>
</div>
<button type="submit" name="submit2">Add</button>
</form>
Medjutim tu umesto da mi u formi izbaci ono iz tabele na prvoj stranici, izbacuje mi ovo:
Notice: Undefined index: ime in C:\xampp\htdocs\test\add.php on line 23
Notice: Undefined index: prezime in C:\xampp\htdocs\test\add.php on line 24
Notice: Undefined index: jmbg in C:\xampp\htdocs\test\add.php on line 25
Notice: Undefined index: ulica in C:\xampp\htdocs\test\add.php on line 26
i u formi:
<br /><b>Notice</b>: Undefined variable: name_b in <b>C:\xampp\htdocs\test\add.php</b> on line <b>57</b><br />
<br /><b>Notice</b>: Undefined variable: lname_b in <b>C:\xampp\htdocs\test\add.php</b> on line <b>63</b><br />
<br /><b>Notice</b>: Undefined variable: number_b in <b>C:\xampp\htdocs\test\add.php</b> on line <b>69</b><br />
<br /><b>Notice</b>: Undefined variable: street_b in <b>C:\xampp\htdocs\test\add.php</b> on line <b>74</b><br />
Znam da je greska u drugoj stranici gde nisam lepo variable odradio ali ne mogu da ukapiram kako...?