php - DELETE row entry from database -


good day! totally new php , appreciate coming you.

i want delete row in database got error:

warning: illegal string offset 'text' in c:\xampp\htdocs\php\deletejoke\jokes.php on line 14

the code seem okay don't know why i'm getting error.please guide me this, lot! please see below code reference:

if (isset($_get['deletejoke'])) {     try {         $sql = 'delete joke id = :id';         $s = $pdo->prepare($sql);         $s->bindvalue(':id', $_post['id']);         $s->execute();     } catch (pdoexception $e) {         $error = 'error deleting joke' . $e->getmessage();         include 'error.php';         exit();     }         header('location: .');         exit(); }  try {     $sql = 'select id, joketext joke';     $result = $pdo->query($sql); } catch (pdoexception $e) {     $error = 'error fetching jokes' . $e->getmessage();     include 'error.php';     exit(); }     foreach ($result $row) {         $jokes = array('id' => $row['id'], 'text' => $row['joketext']);     }     include 'jokes.php'; ?>    <!doctype html> <html lang="en"> <head>     <title>exercise #3: display contents database</title>     <meta charset="utf-8"/> </head> <body>     <a href="?addjoke">add own joke!</a>     <p>here jokes in database:</p>     <?php foreach($jokes $joke): ?>     <form action="?deletejoke" method="post">         <blockquote>             <p>                 <?php echo htmlspecialchars($joke['text'], ent_quotes, 'utf-8'); ?>                 <input type="hidden" name="id" value="<?php echo $joke['id']; ?>">                 <input type="submit" value="delete">             </p>         </blockquote>     </form>          <?php endforeach; ?>     </body> </html> 

the warning telling treating $jokes, , therefore $joke string , not array.

try building $jokes array this

// initialize array $jokes = array();  foreach ($result $row) {      // add array using $jokes[]     $jokes[] = array('id' => $row['id'], 'text' => $row['joketext']);  } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -