Can't pass form data to PHP to update Database

Benjamin

Thanks to all who responded. I got it to update with a combination of ideas from you. I've amended the code to show what's working.

To implement LIKE functionality by passing the LIKE button value to php so as to update the DB.

This displays the table, complete with a LIKE button per row:

echo '<table>
           <tr>
            <th>Word ID</th>
            <th>User ID</th>
            <th>User Name</th>
            <th>Word</th>
            <th>Meaning</th>
            <th>Example</th>
           </tr>';

    foreach ($data as $row) 
      { 
        echo '<tr>';
            foreach ($row as $value)
                  { 
                echo '<td>';
                    echo $value;
                echo '</td>';
              } 


    echo '<td>
 <form method="POST" action="'.$_SERVER["PHP_SELF"].'">
<input type="hidden" name="LIKE" value="'.$row['wordID'].'">
<input type="submit" class="btn btn-success" value="Submit">
</form>

                 </td>';

            echo '</tr>';
          }
        echo '</table>';

The code to process the form submit is:

    if($_POST['submit']) 
 {
$sql = "UPDATE vocab SET likes = likes+1 where wordID = '{$row['wordID']}'"; 

$stmt = $db->prepare($sql);

/* Execute */
            $stmt->execute();

}
Neil
<form method="post" action="<?php echo $_SERVER["PHP_SELF"]?>

is a sytax you use when you are NOT already in a <?php tag. Here, you already are writing in PHP and in an echo and you just apen again a <?php, and another echo in it, this makes no sense.

echo '...  <form method="post" action="'.$_SERVER["PHP_SELF"].'">  ...';

is the way you want to include your php_self value.

also

<input type="submit" value="LIKE" name="<?php echo $row["wordID"]; ?></form>

should be

<input type="submit" value="LIKE" name="'.$row['wordID'].'"></form>

but you cant the search for $_POST['wordID'], search for $_POST[$row['wordID']] in a for loop.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Can't send data from a user form to a database in PHP

From Dev

Update data from form to database using php

From Dev

Database won't update values with php form

From Dev

Can't pass hidden form value from database to PHP if-statement

From Dev

PHP form MySql EDIT / UPDATE - Can't get form to populate with data

From Dev

PHP & MySql: can't update database

From Dev

can't update postgres database using PHP

From Dev

I can't UPDATE database mysqli PHP

From Dev

Can't update data from MySQL database

From Dev

Pass Data from HTML Form to MySQL Database using PHP

From Dev

Pass Data from HTML Form to MySQL Database using PHP

From Dev

Mysql UPDATE using PHP and AJAX, can't update database

From Dev

How to update an SQL database with form data using PHP?

From Dev

Can't update database entry from form fields

From Dev

Database doesn't Update - PHP Form through MySQLi

From Dev

Can't update data in mysql from php

From Dev

Can't put data into database,PHP

From Dev

mysql - can't insert data into database with php

From Dev

Can't update the database

From Dev

Why can't I get HTML form to pass values to PHP?

From Dev

can't pass value from form to php page

From Dev

Can't update data using class based view and django form

From Dev

HTML/PHP form doesn't insert data to MySQL Database

From Dev

Can't update SQL database with quotes using PHP

From Dev

Android - I can't update data from SQLite Database

From Dev

PHP - Form Data to localhost Database

From Dev

PHP Form Not Sending Data To Database

From Dev

Can I pass HTML form data to PHP and have PHP "post" the data?

From Dev

can not update Data in Kinvey Database

Related Related

HotTag

Archive