Jump to content

Am I doing this the best way ?


cloudll

Recommended Posts

At the moment, if i want to update my database, im using an external page with the sql query, say its called update.php, and im including it in an invisible css box with something like this /index.php?site=homepage&hiddenbox=update.

 

That seems to be working fine, however I have a lot of things which constantly get updated in my database so i have lots of pages to update various things.

 

Is there a way to update from within the index.php page, maybe with an if statement if the update is dependant on say a number being less than 10?

 

Any opinions on the best way to go about updating database would be greatly appreciated

 

thanks.

Link to comment
Share on other sites

Sure.

 

Its for a game, so I have a compass. Say i want to go east. I click east on my compass (the url is : index.php?hiddenbox=compass_east)

 

and my compass_east.php contains.

 

<?php

    $sql = "UPDATE game_character SET pos_y = (pos_y+25) WHERE id=1";
    $statement = $dbh->prepare($sql); 
    $statement->execute();
       
?>

 

and a lot of it is like that, when you click an attack you want to perform it loads an attack_name.php page which updates in the same way.

 

I have about 50 pages now which all only have them 3 lines of code in, so wondered if there was another way.

Link to comment
Share on other sites

What makes you think you need to put the code within an invisible css box? You can have code that executes without having an output element.

 

For example, let's say you have a form to add a record that POSTs back to the main page (this is not a working script, just a POC)

<?php

if(isset($_POST['name'])
{
    $name = mysql_real_escape_string(trim($_POST['name']));
    $query = "INSERT INTO users (name) VALUES('$name')";
    $result = mysql_query($query);
}

?>
<html>
<body>

Welcome to the home page
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.