User input to database

I have given up all hope. Let me start with that.Goal:User inputs data into a form (preferable one that looks clean and

I have given up all hope. Let me start with that.

Goal:

  • User inputs data into a form (preferable one that looks clean and is scalable across platforms)
  • User presses submit and the information is processed through a basic math formula
  • That info is the updated in that users database table record (database is already made and working)
  • The page refreshes to update the generated table on the page

Why I am struggling:

Other then I have less brain cells then a kiwi (bird or fruit), I can seem to find a plugin that lets you take user information and enter it into a database... I have Elementor pro, but it's forms don't let you do anything with database updating that I have seen/found. No other form plugin I have tried can save to a database for whatever reason.

Am I wrong to think that this should be an extremely basic idea and should be well documented and easy to achieve as a creator?

Specific Use Case:

Keeping track of users weights lifted for specific exercises.

Basic table fields: ustats_id (primary key auto_increment), user_id (ties the user to the table), squat int, deadlift int, etc.

  • User selects from a dropdown what exercise to update
  • User enters weight lifted
  • User enters reps completed
  • User submits information
  • Fancy formula spits out a number based on this
  • That users exercise number is updated

To pull the information I have had to use the custom php with the $wpdb class, but I don't even know how to begin using the same to update the information (I have tried and failed miserably for about 30 hours now).

Is there an easier way? Am I stuck with having to make forms and shortcode in the php? I don't even know where to begin...

<?php

global $wpdb;

echo <<<EOF

<form action="I don't actually understand what goes here" method="post">
 <p> <select id="exercise" name="exercise">
       <option value="squat">Squat</option>
       <option value="deadlift">Deadlift</option>
       <option value="cry">Cry</option>
     </select></p>
 <p>Weight Lifted: <input type="number" name="weight" /></p>
 <p>Reps Completed: <input type="number" name="reps" /></p>
 <p><input type="submit" /></p>
</form>

EOF;

$current_user = wp_get_current_user();

if(the form submit is triggered){
$stat=weight*reps;
$wpdb->update( "UPDATE xxxxxx_userstats SET exercise=$stat WHERE user_id=$current_user->user_id");

}

?>

Or something, but I also know I have to care about SQL injection, but I can't even get this to work, let alone the data validation that I would have to do on top of it. If anyone has any ideas, or suggestions I would very much appreciate it.

I'm so lost.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742351458a4427600.html

相关推荐

  • User input to database

    I have given up all hope. Let me start with that.Goal:User inputs data into a form (preferable one that looks clean and

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信