PHP Code Help

Forumas skirtas klausimams/pamokoms susijusioms su PHP, SQL (MySQL), web technologijomis, HTML, CSS, javascript, turinio valdymo sistemomis ir kita.
Post Reply
Kenzy
Jau po truputį tampa savu
Posts: 106
Joined: 2017 Jan 22 20:41

PHP Code Help

Post by Kenzy »

Hello everybody:

i have this php code that access the database directly and add ammos to specific player wich i can use a form using steamID and amount of ammos to edit it directly from database.
please look on this code if something wrong and help me for fix it and for be working 100% :)
thanks.

Code: Select all

<!DOCTYPE HTML>  <html><head><style>.error {color: #FF0000;}</style></head><body>   <?php// define variables and set to empty values$steamidErr = $ammos = "";$steamid = $ammos = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") {  if (empty($_POST["steamid"])) {    $steamidErr = "SteamID is required";  } else {    $steamid = test_input($_POST["steamid"]);    }  }   if (empty($_POST["ammos"])) {    $emailErr = "Ammos are required";  } else {    $email = test_input($_POST["ammos"]);  }} function test_input($data) {  $data = trim($data);  $data = stripslashes($data);  $data = htmlspecialchars($data);  return $data;}?> <h2>Enter SteamID and ammount to add :</h2><p><span class="error">* required field</span></p><form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">    SteamID: <input type="text" name="steamid" value="<?php echo $steamid;?>">  <span class="error">* <?php echo $steamidErr;?></span>  <br><br>  Ammos: <input type="text" name="ammos" value="<?php echo $ammos;?>">  <span class="error">* <?php echo $ammosErr;?></span>  <br><br>  <input type="submit" name="submit" value="Add Ammos"></form> <?php$servername = "localhost";$username = "username";$password = "password";$dbname = "myDB"; // Create connection$conn = mysqli_connect($servername, $username, $password, $dbname);// Check connectionif (!$conn) {    die("Connection failed: " . mysqli_connect_error());} $sql = "UPDATE Table SET ammos+='$ammos' WHERE steamid='$steamid'; if (mysqli_query($conn, $sql)) {   echo "Record updated successfully";} else {   echo "Error updating record: " . mysqli_error($conn);} mysqli_close($conn);?> </body></html>  

Code: Select all

    <?php    $user = $_POST['user'];    $pass = $_POST['pass'];         if($user == "admin"    && $pass == "admin")    {            include("secure.html");    }    else    {        if(isset($_POST))        {?>                     <form method="POST" action="secure.php">                User <input type="text" name="user"></input><br/>                Pass <input type="password" name="pass"></input><br/>                <input type="submit" name="submit" value="Go"></input>                </form>        <?}    }    ?>
Attachments
unknown.png

User avatar
psychical
Viršininkas
Posts: 2094
Joined: 2011 Mar 12 22:19
Skype: tautvydas11
Location: Linksmakalnis
Contact:

Re: PHP Code Help

Post by psychical »

Both files should be .php not .html/.php just .php

Also change all <? without php to <?php

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests