Abhaya Singh Pandey
Abhaya Singh Pandey

Reputation: 67

Unable to delete mysql data from php

I have successfully connected to database and published mysql data on web and manually added joke on it.Screenshot of what output looks like is provided here. enter image description here

When i manually enter the corresponding id of joke inside the textbox and press delete button, it deletes the joke corresponding to that it. But when i click on the delete button directly, that joke isn't deleted. How to update value of that textbox ? For the time being, i have made input type of textbox as text so to see whats going inside it. I am using PHP version: 7.1.1 and Apache/2.4.25 (Win32.

<p><a href="?addjoke">Add your own joke</a></p>
<p>Here are all the jokes in the database:</p>
<?php foreach ($jokes as $joke) : ?>
  <form action ="?deletejoke" method='post'>
  <blockquote>
    <p><?php echo htmlspecialchars($joke['text'], ENT_QUOTES, 'UTF-8');?>
    <input type = "text" name = "id" value = "<? php echo $joke['id']; ?>">
    <input type = 'submit' value = 'Delete'>
    </p>
  </blockquote>
</form>

Screenshot of Mysql database is provided here. enter image description here

Upvotes: 0

Views: 74

Answers (3)

modsfabio
modsfabio

Reputation: 1147

Change

<input type = "text" name = "id" value = "<? php echo $joke['id']; ?>">

to

<input type = "text" name = "id" value = "<?php echo $joke['id']; ?>">

Upvotes: 1

Simon M&#252;ller
Simon M&#252;ller

Reputation: 451

<input type="text" name="id" value="<?php echo $joke['id'];?> ">

you should remove the spaces (not just in this line)

Upvotes: 1

Victor Radu
Victor Radu

Reputation: 2292

there is a space between <? and php on the input value it should be <?php; then it should work.

<input type = "text" name = "id" value = "<? php echo $joke['id']; ?>">

Upvotes: 2

Related Questions