Creating an "Upvote" button using simple HTML form and PHP -
i'm trying create simple upvote button in html form uses php update mysql database. know there better implementations ajax etc i'm looking use simple html , php.
i've been able update database using input type="number"
form element can't update when try changing input type="submit"
value=1
.
html
<form action="send_formdata.php" method="post"> <label>digs</label> <input type="submit" name="digs" id="digs" value=1> </form>
php (in send_formdata.php)
<?php $link = mysqli_connect("mysql.xxxxxx.com","xxxxx","xxxx","xxxxxx") or die("failed connect server !!"); mysqli_select_db($link,"xxxxxx"); if(isset($_request['submit'])){ $errormessage = ""; $digs=$_post['digs']; if ($errormessage != "" ) { echo "<p class='message'>" .$errormessage. "</p>" ; }else{ $insqdbtb="update `xxxxxxxx`.`coffee` set digs = digs + '$digs' name = 'africa'"; mysqli_query($link,$insqdbtb) or die(mysqli_error($link)); } } ?>
mysql database info:
table name coffee
column type id int(10) unsigned auto increment name varchar(255) roaster varchar(255) digs int(10) unsigned
community wiki because question answered in comments.
you said code worked when had input type="number"
. suspect had submit button name="submit"
later removed.
as result, statement false.
if(isset($_request['submit'])){
this because submit button has name="digs"
. when submit it, there no $_request['submit']
. instead there $_request['digs']
.
- your present code open sql injection. use
mysqli
prepared statements, or pdo prepared statements, they're safer.
Comments
Post a Comment