Update value in mysql database column with checkbox in php

Adrian

I have the following code in php

$countryiso = mysql_query("SELECT distinct name as name FROM location_country where code NOT IN('A1','A2','AP','EU') order by name");
echo '<table>';
echo '<th>Country</th><th> Add/Remove </th>';
while ($row = mysql_fetch_assoc($countryiso)) {
 echo '<tr>';
 echo '<td>'. $row['name'] . '</td>';
 echo '<td><form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"><input type="hidden" name="id" value="<?php echo $id; ?>" /><input type="checkbox" name="checkinsat" value="1"<?php if($data['checkinsat'] == '1') echo 'checked'; ?>/><input type="submit" ></form></td>';
 echo '</tr>';
}
 echo '</table>';

And i get the error

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in don't know where i am mistaking.

Jeemusu

The problem is your echo on line 7. Your doing <?php echo ... ?> inside of an echo. You should instead concatenate the values into the string.

Instead of:

 echo '<td><form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"><input type="hidden" name="id" value="<?php echo $id; ?>" /><input type="checkbox" name="checkinsat" value="1"<?php if($data['checkinsat'] == '1') echo 'checked'; ?>/><input type="submit" ></form></td>';

Try this:

$checked = ($data['checkinsat'] == '1') ? 'checked' : '';
echo '<td><form method="post" action="'.$_SERVER['PHP_SELF'].'"><input type="hidden" name="id" value="'. $id.'" /><input type="checkbox" name="checkinsat" value="1" '.$checked.'/><input type="submit" ></form></td>';

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Update value in mysql database column with checkbox in php

From Dev

Update MySQL Value with checkbox

From Dev

Checkbox and MySQL database with PHP

From Dev

PHP code for insert checkbox value into spesific column on mysql with select form

From Dev

Update first header column based on checkbox value

From Dev

Datagrid checkbox column that sends update mysql command

From Dev

MYSQL and PHP database update wont update database

From Dev

How to retrieve checkbox value from database in PHP

From Dev

checkbox is checked if value is in database in php using jquery

From Dev

Check checkbox if MYSQL column value true

From Dev

PHP MySql Database Array update

From Dev

Update MySQL database with PHP and AJAX

From Dev

Insert and update database with php mysql

From Dev

Update database using MySQL and PHP

From Dev

MySQL PHP Column Update Query

From Dev

MySQL update column which is a value in another column

From Dev

MySQL update column which is a value in another column

From Dev

How To Add Value To A Column And Update Database

From Dev

How To Add Value To A Column And Update Database

From Dev

update database with checkbox

From Dev

Picking checkbox from database in table and update it back using PHP

From Dev

PHP & MySQL Search Column for value

From Dev

how to insert multiple checkbox values in single column in database using php

From Dev

Update checkbox and textarea value in mysql db using Jquery

From Dev

Update value from 0 to 1 in mysql table with checkbox

From Dev

PHP MYSQL compare database value to POST value

From Dev

PHP MYSQL compare database value to POST value

From Dev

Mysql and PHP - Update database from a different server

From Dev

php mysql update database on button click

Related Related

  1. 1

    Update value in mysql database column with checkbox in php

  2. 2

    Update MySQL Value with checkbox

  3. 3

    Checkbox and MySQL database with PHP

  4. 4

    PHP code for insert checkbox value into spesific column on mysql with select form

  5. 5

    Update first header column based on checkbox value

  6. 6

    Datagrid checkbox column that sends update mysql command

  7. 7

    MYSQL and PHP database update wont update database

  8. 8

    How to retrieve checkbox value from database in PHP

  9. 9

    checkbox is checked if value is in database in php using jquery

  10. 10

    Check checkbox if MYSQL column value true

  11. 11

    PHP MySql Database Array update

  12. 12

    Update MySQL database with PHP and AJAX

  13. 13

    Insert and update database with php mysql

  14. 14

    Update database using MySQL and PHP

  15. 15

    MySQL PHP Column Update Query

  16. 16

    MySQL update column which is a value in another column

  17. 17

    MySQL update column which is a value in another column

  18. 18

    How To Add Value To A Column And Update Database

  19. 19

    How To Add Value To A Column And Update Database

  20. 20

    update database with checkbox

  21. 21

    Picking checkbox from database in table and update it back using PHP

  22. 22

    PHP & MySQL Search Column for value

  23. 23

    how to insert multiple checkbox values in single column in database using php

  24. 24

    Update checkbox and textarea value in mysql db using Jquery

  25. 25

    Update value from 0 to 1 in mysql table with checkbox

  26. 26

    PHP MYSQL compare database value to POST value

  27. 27

    PHP MYSQL compare database value to POST value

  28. 28

    Mysql and PHP - Update database from a different server

  29. 29

    php mysql update database on button click

HotTag

Archive