php - Update mysql but only last digit of number -
i updating database number, want last digit of number update. not sure whether in php or mysql.
code: (not full code posted, relevant)
if(isset($_post['update'])) { $n_score = $_post['n_score']; $a_score = $_post['a_score']; $sql = "update scores set n_score = $n_score, a_score = $a_score"; mysql_query($sql) or die(mysql_error()); <form method = "post" action = "<?php $_php_self ?>"> <table width = "400" border =" 0" cellspacing = "1" cellpadding = "2"> <tr> <td width = "10"><?php echo $n_team; ?> score:</td> <td><input name = "n_score" type = "text" id = "n_score" value="<?php echo $n_score; ?>"></td> </tr> <tr> <td width = "10"><?php echo $a_team; ?> score:</td> <td><input name = "a_score" type = "text" id = "a_score" value="<?php echo $a_score; ?>"></td> </tr> so, in form, enter score n_team , a_team so:
n_team: 21 & a_team: 34
i want last digit go in update of sql string, in database so:
n_team: 1 & a_team: 4
try:
$n_score = substr($_post['n_score'], -1); $a_score = substr($_post['a_score'], -1); this assumes values non-zero length, might want error handling.
you may want think protecting sql injection.
Comments
Post a Comment