Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Development
[DEV] LinkTheDay
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="BIOS" data-source="post: 371060" data-attributes="member: 15674"><p>Instead of repeatedly escaping every variable and executing queries like you currently are, look into prepared statements. They are one of the few benefits that you have access to when using MySQLi.</p><p></p><p>For example:</p><p>[PHP]</p><p><?php</p><p>if(isset($_POST['btn-update'])) {</p><p></p><p> $updateMyPost = $_POST['updateMyPost'];</p><p> $user_id = $_POST['user_id'];</p><p> $prefix = $_POST['prefix'];</p><p></p><p> if(!is_int($user_id)){</p><p> $error = 'fail!'; // user_id isn't a valid integer</p><p> }</p><p> </p><p> // other checks...</p><p></p><p> if(!$error){</p><p></p><p> $stmt = mysqli_prepare(</p><p> $con,</p><p> "INSERT INTO posts</p><p> (link, user_id, prefix)</p><p> VALUES</p><p> (?, ?, ?)"</p><p> );</p><p></p><p> mysqli_stmt_bind_param($stmt, "s", $updateMyPost);</p><p> mysqli_stmt_bind_param($stmt, "i", $user_id);</p><p> mysqli_stmt_bind_param($stmt, "s", $prefix);</p><p></p><p> mysqli_stmt_execute($stmt);</p><p></p><p> }else{</p><p> echo $error;</p><p> }</p><p></p><p>}</p><p>?></p><p>[/PHP]</p><p></p><p>Good luck <img src="/styles/default/xenforo/smilies/emojione/tongue.png" class="smilie" loading="lazy" alt=":p" title="Stick Out Tongue :p" data-shortname=":p" /></p></blockquote><p></p>
[QUOTE="BIOS, post: 371060, member: 15674"] Instead of repeatedly escaping every variable and executing queries like you currently are, look into prepared statements. They are one of the few benefits that you have access to when using MySQLi. For example: [PHP] <?php if(isset($_POST['btn-update'])) { $updateMyPost = $_POST['updateMyPost']; $user_id = $_POST['user_id']; $prefix = $_POST['prefix']; if(!is_int($user_id)){ $error = 'fail!'; // user_id isn't a valid integer } // other checks... if(!$error){ $stmt = mysqli_prepare( $con, "INSERT INTO posts (link, user_id, prefix) VALUES (?, ?, ?)" ); mysqli_stmt_bind_param($stmt, "s", $updateMyPost); mysqli_stmt_bind_param($stmt, "i", $user_id); mysqli_stmt_bind_param($stmt, "s", $prefix); mysqli_stmt_execute($stmt); }else{ echo $error; } } ?> [/PHP] Good luck :p [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Development
[DEV] LinkTheDay
Top