Poštovanje!
Ima li netko kompletan - ispravan kod za rad s podacima da si mogu pronaći malu grešku. Kod search upisa ne pokazuje mi dole link, a daje slijedeću geršku:Not Found
The requested URL was not found on this server.
Apache/2.4.54 (Win64) PHP/8.0.26 mod_fcgid/2.3.10-dev Server at localhost Port 80 / u brow,,,http://localhost/php%20kurs/data_novo/carInfo.php%20method=?search=9000&subBtn=
Unaprijed zahvaljujem
jedino je jos trebalo da se doradi da ne vraca gresku kad se nista ne unese. resio sam to na sledeci nacin: na stranici carInfo sam dodao jos jedan elseif
elseif (empty($_GET['search'])) {
header('location:index.php?empty');
}
i to docekao na index php sa jos jedan elseif u placeholderu search-a
elseif (isset($_GET['empty'])) {
echo "Search is empty!! ";
}
i to je to. Cisto ako nekom pomogne.
(4) Pitanja i odgovori
Josko
Poštovanje! Ima li netko kompletan - ispravan kod za rad s podacima da si mogu pronaći malu grešku. Kod search upisa ne pokazuje mi dole link, a daje slijedeću geršku:Not Found The requested URL was not found on this server. Apache/2.4.54 (Win64) PHP/8.0.26 mod_fcgid/2.3.10-dev Server at localhost Port 80 / u brow,,,http://localhost/php%20kurs/data_novo/carInfo.php%20method=?search=9000&subBtn= Unaprijed zahvaljujem
Josko
Poštovani ! ponavljam isto pitanje s kodovima:<?php require'db.php'; ?> <doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script> </head> <body> <nav class="navbar navbar - expand navbar-light"> <a href="index.php" class="navbar-brand"> Cars</a> </nav> <div class="container-fluid"> <div class="row"> <div class="col-8 offset-2"> <h3 class="display-4">Search cars</h3> <form action="carInfo.php method="get"> <div class="input-group"> <input type="text" name="search" class="form-control" placeholder="<?php if(isset($_GET['error'])){ echo "No match found";} else { echo "Search";}?>"> <div class="input-group-append"> <button type"submit" name="subBtn" class="btn btn-info"> Search </button> </div> </div> </form> </div> </div> <br><br> <div class="row"> <div class="col-8 offset-2"> <div class="row"> <?php foreach ($db as $car):?> <div class="col-3"> <a href="carInfo.php?id=<?php echo $car['id']; ?>"> <div class="card text="center"> <div class="card-header"><?php echo $car['brend'] ?></div> <div class="card-body"><?php echo $car['name'] ?></div> <div class="card-footer"> <button class="btn btn-primary btn-sm"><?php echo $car['price']. "$"; ?> </button> <button class="btn btn-<?php if($car['used']){ echo "warning";}else{echo "success";} ?> btn-sm"><?php if($car['used']){ echo "Used";}else{echo "New";} ?></button> </div> </div> </a> </div> <?php endforeach;?> </div> </div> </div> </div> </div> </body> </html> --------------- <?php require 'db.php'; if (isset($_GET['id'])){ $id=$_GET['id']; $cars = array_filter($db,function ($el) //zbog ovog $db morat će mo u vrhu pozvati require db.php { global $id; return $el['id']==$id; // vrati mi element unutar ovih carsa I tu imamo problem jer function ne može vidjeti varijablu iznad nje; tako da će mo reći iznad global $id }); //var_dump($cars); } elseif($_GET['search']){ $search=$_GET['search']; $cars = array_filter($db, function ($el) { global $search; return $el['brend'] == $search || $el['name'] == $search || $el['price'] == $search; }); if (count($cars)==0){ header("Location:index.php?error=1"); } ?> <doctype html> <html> <head> <meta charset="utf-8"> <title>Car Info</title> <link rel=“stylesheet“ hreff=https://stackpath.bootstrapedn.com/bootstrap/4.3.1/css/bootstrap.min.css integrity =“sha384-ggoyR0iXCbMQv3xipma34MD+dH/1f784/jbcY/iJTQUOhcWr7x9JvoRxT2MZw1T“ crossorigin=“anonyimus“> </head> <body> <nav class="navbar navbar - expand navbar-light"> <a href="index.php" class="navbar-brand"> Cars</a> </nav> <div class="jumbotron text="center"> <h2><?php foreach($cars as $car): ?> <span> <?php echo $car['brend']; ?> </span> <?php endforeach; ?> </h2> </div> <div class="container-fluid"> <div class="row"> <div class="col-8 offset-2" > <div class="row"> <?php foreach($cars as $car):?> <div class="col-6" style="outline:1px solid #ddd"> <h3 class="display=4"> <?php echo $car['name']; ?> <hr> <p> <?php echo $car['info']; ?></p> <hr> <p> <?php echo $car['price']; ?></p> </div> <?php endforeach;?> </div> </div> </div> </div> </body> </html> Ako netko može pomoći?? Hvala unaprijed.
Miroslav
Druze sve radi perfektno, uradeo iz prve tako da proveri kod jos jednom ili uradi iz pocetka da pronadjes gresku. pozz
Miroslav
jedino je jos trebalo da se doradi da ne vraca gresku kad se nista ne unese. resio sam to na sledeci nacin: na stranici carInfo sam dodao jos jedan elseif elseif (empty($_GET['search'])) { header('location:index.php?empty'); } i to docekao na index php sa jos jedan elseif u placeholderu search-a elseif (isset($_GET['empty'])) { echo "Search is empty!! "; } i to je to. Cisto ako nekom pomogne.
Kako bi ste bili u mogućnosti da postavljate pitanja, morate biti ulogovani.