Pheonix Posted February 5, 2020 Share Posted February 5, 2020 I want to give a user experience if they defeat the monster. I want to use mysqli. I would appreciate your help. Please checkout my current fight.php I am new so my code is sloppy. fight.php 1 Quote Link to comment Share on other sites More sharing options...
ags_cs4 Posted February 5, 2020 Share Posted February 5, 2020 what engine you using??? Quote Link to comment Share on other sites More sharing options...
Pheonix Posted February 5, 2020 Author Share Posted February 5, 2020 I used a registration tutorial and, there maybe some mcCodes mixed into it? Quote Link to comment Share on other sites More sharing options...
Magictallguy Posted February 5, 2020 Share Posted February 5, 2020 Looks like MCCv1 to me. Have you updated your mysql.php to initiate a MySQLi connection? Quote Link to comment Share on other sites More sharing options...
Pheonix Posted February 6, 2020 Author Share Posted February 6, 2020 That is my problem I think. Updating the old mysql to mysqli. I tried the free mccodes but, it did not install all the way. Quote Link to comment Share on other sites More sharing options...
Curt Posted February 6, 2020 Share Posted February 6, 2020 What type of error message do you get ? Upon first glance the script you posted looks like it should work. I think Magictallguy is on the right track and the problem lies in the connection. Quote Link to comment Share on other sites More sharing options...
Magictallguy Posted February 6, 2020 Share Posted February 6, 2020 On 2/6/2020 at 12:17 AM, Pheonix said: That is my problem I think. Updating the old mysql to mysqli. I tried the free mccodes but, it did not install all the way. MCC Lite (and v1) are hard-coded to MySQL. So you've got quite the task ahead of you. Not only would you need to initialise the MySQLi connection, you'd then need to update every file that runs a query. Basic instantiation (OOP): // Begin connection $db = new mysqli('host', 'user', 'pass', 'dbname'); // Verify connection if($db->connect_error) { exit('Connect Error (' . $db->connect_errno . ') ' . $db->connect_error); } Basic instantiation (procedural): // Begin connection $db = mysqli_connect('host', 'user', 'pass', 'dbname'); // Verify connection if(mysqli_connect_error()) { exit('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } Assume variables have values: $id, $name Queries (OOP - non-prepared): (assume $name is escaped) // Select $select = $db->query('SELECT userid, username FROM users WHERE userid = '.$id) or exit($db->error); // Insert $db->query('INSERT INTO users (userid, username) VALUES ('.$id.', "'.$name.'")') or exit($db->error); // Update $db->query('UPDATE users SET username = "'.$name.'" WHERE userid = '.$id) or exit($db->error); // Delete $db->query('DELETE FROM users WHERE userid = '.$id) or exit($db->error); Queries (procedural - non-prepared): (assume $name is escaped) // Select $select = mysqli_query($db, 'SELECT userid, username FROM users WHERE userid = '.$id) or exit(mysqli_error($db)); // Insert mysqli_query($db, 'INSERT INTO users (userid, username) VALUES ('.$id.', "'.$name.'")') or exit(mysqli_error($db)); // Update mysqli_query($db, 'UPDATE users SET username = "'.$name.'" WHERE userid = '.$id) or exit(mysqli_error($db)); // Delete mysqli_query($db, 'DELETE FROM users WHERE userid = '.$id) or exit(mysqli_error($db)); Queries (OOP - prepared): // Select (with parameters) $statement = $db->prepare('SELECT userid, username FROM users WHERE userid = :id'); $statement->bind(':id', $id); $statement->execute(); // Select (without parameters) $statement = $db->query('SELECT userid, username FROM users'); $statement->execute(); // ------- // Insert (with parameters) $statement = $db->prepare('INSERT INTO users (userid, username) VALUES (:id, :name)'); $statement->bind(':id', $id); $statement->bind(':name', $name); $statement->execute(); // Insert (without parameters) $statement = $db->query('INSERT INTO settings (name, content) VALUES ("demonstrative_name", "some value")'); $statement->execute(); Returning data (OOP - non-prepared): (assume $name is escaped) // 1 result expected, assume matching data exists $select = $db->query('SELECT userid, username FROM users WHERE username = "'.$name.'" LIMIT 1'); $row = $db->fetch_assoc($select); echo $row['username']; // multiple results expected, assume matching data exists $select = $db->query('SELECT userid, username FROM users WHERE userid BETWEEN 1 AND 100'); while($row = $db->fetch_assoc($select)) { echo $row['username'].'<br>'; } Returning data (procedural): (assume $name is escaped) // 1 result expected, assume matching data exists $select = mysqli_query($db, 'SELECT userid, username FROM users WHERE username = "'.$name.'" LIMIT 1'); $row = mysqli_fetch_assoc($select); echo $row['username']; // multiple results expected, assume matching data exists $select = mysqli_query($db, 'SELECT userid, username FROM users WHERE userid BETWEEN 1 AND 100'); while($row = mysqli_fetch_assoc($select)) { echo $row['username'].'<br>'; } Returning data (OOP - prepared): // 1 result expected, assume matching data exists $stmt = $db->prepare('SELECT userid, username FROM users WHERE username = :name LIMIT 1'); $stmt->bind(':name', $name); $stmt->execute(); $row = $stmt->fetch_assoc(); echo $row['username']; // multiple results expected, assume matching data exists $stmt = $db->query('SELECT userid, username FROM users WHERE userid BETWEEN 1 AND 100'); $rows = $stmt->fetch_assoc(); foreach($rows as $row) { echo $row['username'].'<br>'; } Recommendation: Throw your MySQLi into a wrapping class. Doing this means you'd be able to change your connection type in one file without having to edit absolutely everything that relies on it. Recommendation: Update your code to use Prepared Statements. Recommendation: OOP vs Procedural: It's entirely up to you which method you use. However, you're working on a project that re-uses variables/functions quite often, so I'd advise OOP Note: Prepared Statements are not available in procedural-style MySQLi. 3 Quote Link to comment Share on other sites More sharing options...
Pheonix Posted February 6, 2020 Author Share Posted February 6, 2020 My game is Dawnspell.com You can check it out with [email protected] and password demo. You will notice that nothing updates when you kill the monster. Quote Link to comment Share on other sites More sharing options...
BeNiiiBoiii Posted February 7, 2020 Share Posted February 7, 2020 Links not working for me.. Quote Link to comment Share on other sites More sharing options...
Pheonix Posted February 13, 2020 Author Share Posted February 13, 2020 (edited) I am sorry. It should work now. Thank you for all your help Magic. I am thinking of releasing my files for help with my game problem. I left out dbconnect.php because It contains my password and such. I will modify it later. error_log gametable.sql register.php logout.php index.php home.php Edited February 21, 2020 by Pheonix Added error Logs 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.