Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Looking for PHP snippet for updating MYSQL data

Featured Replies

Setting up a dynamic signature and know literally no PHP, was wondering if somebody had a php file that is correctly formatted and will

automatically add new entered data, etc.

 

E.g. Fish Caught was 30, next session person catches 3000 fish so it will add 3000 to 30, rather than just putting the new value there.

 

I've already got the signature making set up, just looking for this part now.

 

Any help is appreciated, thanks

//Simple insert-into database via mysqli by Kosti Wessman
<?php
//Connection details
$servername = "hostlelocal";
$username = "nameleuser";
$password = "wordlepass";
$dbname = "baseledata";

//Variable conn is used to determine the new mysql connection for above data
$conn = new mysqli($servername, $username, $password, $dbname);
//Checking if the connection is valid, if not, killing the process and throwing a error message
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
//Query for inserting the wanted data into the mysql - Where DynSig is the table name
$sql = "INSERT INTO DynSig (xp_gained, time_run, fish_caught)
VALUES ('value1', 'value2', 'value3')"; 
//Values 1, 2 and 3 are in order where xp_gained, time_run, fish_caught

//Closing the connection.. :P
$conn->close();
?>

This should do the trick. Just create variables for the value1, value2 and value3 to make it autoupdate from your script.

//Query for inserting the wanted data into the mysql - Where DynSig is the table name
$sql = "UPDATE DynSig SET value_name='valuehere' WHERE id='userid'";
//For the update you requested. misread first time

Edited by Finland

  • Author

Oh sweet man, thanks for this!

 

Doesnt UPDATE do the same as insert? Like you cant have 2 of the same primary key right?

 

Also, wouldnt I need to include 

query($sql)

 

Somewhere?

Edited by Tom

Oh sweet man, thanks for this!

 

Doesnt UPDATE do the same as insert? Like you cant have 2 of the same primary key right?

 

Also, wouldnt I need to include 

query($sql)

Somewhere?

 

Sorry :D I was too fuzzy but here you go. Add this before the mysqli_close

if (mysqli_query($conn, $sql)) {
    echo "Record added to the Database";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
  • Author

 

Sorry biggrin.png I was too fuzzy but here you go. Add this before the mysqli_close

if (mysqli_query($conn, $sql)) {
    echo "Record added to the Database";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

 

As for calculating and adding differences e.g. fish caught will need to be incremented, that isnt automatic I'm assuming.

 

Would I have to read the database fields into variables, do the math then update?

As for calculating and adding differences e.g. fish caught will need to be incremented, that isnt automatic I'm assuming.

 

Would I have to read the database fields into variables, do the math then update?

 

You could do something like this

 

  • View what $current value is
  • Inject $new_value
  • Sum up $current and $new_value
  • Insert $result in to the database

Let me know how this goes. 

<?php
$current = "30";
$new_value = "3000";
$result = $current + $new_value;

$sql = "INSERT INTO DynSig ('$result')
?>

Something like this would do the trick. Injecting the variables from your script will be left up to you.

  • Author

You could do something like this

 

  • View what $current value is
  • Inject $new_value
  • Sum up $current and $new_value
  • Insert $result in to the database

Let me know how this goes. 

<?php
$current = "30";
$new_value = "3000";
$result = $current + $new_value;

$sql = "INSERT INTO DynSig ('$result')
?>

Something like this would do the trick. Injecting the variables from your script will be left up to you.

 

The only problem I'm coming across now is actually getting the currrent value from the database, setting it shouldnt be an issue

 

Was thinking something like $current = SELECT xpgained IN Data WHERE id='user' obviously I don't know all the queries, and thats probably wrong.

The only problem I'm coming across now is actually getting the currrent value from the database, setting it shouldnt be an issue

 

Was thinking something like $current = SELECT xpgained IN Data WHERE id='user' obviously I don't know all the queries, and thats probably wrong.

"SELECT * FROM table_name WHERE column_name=' value in column '"; 
  • Author

 

The only problem I'm coming across now is actually getting the currrent value from the database, setting it shouldnt be an issue

 

Was thinking something like $current = SELECT xpgained IN Data WHERE id='user' obviously I don't know all the queries, and thats probably wrong.

"SELECT * FROM table_name WHERE column_name=' value in column '"; 

 

 

Isnt *  the wildcard for ALL in SQL?

 

I still need to get the value from a field based on the users ID,

So would to assign it to a value, id have to run the query right

 

Something like

hGVmI.png

Edited by Tom

I'll create a script later for everyone to use that will correctly insert/update and view data from a NoSQL or MySQL database using an API.

 

Doing it right; do it once.

  • Author

Tom I found this

 

Found wat

 

Im stuck trying to return an int from a column, been like 6 hours

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.