Miha Miha - 1 year ago 53
SQL Question

otice: Undefined variable: row in ...uredi.php on line 19 Call Stack #TimeMemoryFunctionLocation

I don't know what I am doing wrong...

My code is:


if ( isset($_GET['uredi'])) {
$id = $_GET['uredi'];
$sql = mysqli_query($link, "SELECT * FROM changelog");
$row = mysqli_fetch_array($sql);

<div class="container main">
<div class="row">
<div class="page-header">
<h1>Changelog <small><a href="dodaj" title="dodaj"><div class="btn btn-danger btn-xs">Dodaj</div></a></small></h1>
<form role="form" action="includes/dodaj-changelog.php" method="post" accept-charset="utf-8">
<textarea name="vsebina"><?php echo $row['vsebina']; ?></textarea>
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
<button type="submit" style="margin-top: 20px" class="btn btn-primary">Dodaj</button>

And it always give me error: Notice: Undefined variable: row in C:\wamp\www\ocene\uredi.php on line 19 Call Stack #TimeMemoryFunctionLocation 10.0000142728{main}( )..\uredi.php:0 ">

But $row is defined...

Answer Source

Your problem is that you're only defining $row if $_GET['uredi'] isset - in this case, change line 19 to:

<input type="hidden" name="id" value="<?php echo (isset($row['id'])) ? $row['id'] : ''; ?>">

...and the same for your other variables. If you want a default value for your fields, put them in the '' section of that code.