简体   繁体   中英

PHP Submitting wrong information on a MySQL database (PHP+MySQL)

I've been having this weird bug, basically what happens is that I have this App on Android and whenever I try to add a new "user" one of it's values (Called "Contacto") sometimes is wrong, the weird part is that it happens in a completely random way, here is my .php

<?PHP
$con=mysqli_connect("localhost","root","","proyecto");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

if(isset($_POST['txtNombre']) && isset($_POST['txtcontactousuarionuevo']) && 
   isset($_POST['txtPass']) && isset($_POST['txtprograma'])){

$nombreestudiante = $_POST['txtNombre'];
$contactoestudiante = $_POST['txtcontactousuarionuevo'];
$passestudiante = $_POST['txtPass'];
$programa = $_POST['txtprograma'];

$query = "INSERT INTO estudiante(Nombre, Contacto,  Id_Periodo_FK, Pass)
VALUES ('$nombreestudiante', $contactoestudiante, 4, '$passestudiante');"; 

$query .= "INSERT INTO estudiante_programa(EstudianteE_P_FK, ProgramaE_P_FK)
VALUES(LAST_INSERT_ID(), $programa)";


$result =mysqli_multi_query($con,$query);

if($result > 0){

    if(isset($_POST['mobile']) && $_POST['mobile'] == "android"){
        echo "success";
        exit;
    }
    echo "Insert Successfully";   
}
else{
    if(isset($_POST['mobile']) && $_POST['mobile'] == "android"){
        echo "failed";
        exit;
    }
    echo "Something Error";   
}
}

?>
<html>
<head><title>Insert | ProyectoBD</title></head>
   <body>
       <h1>Insert ProyectoBD| <a>Santiago Troitiño C - 201421697</a></h1>
       <form action="<?PHP $_PHP_SELF ?>" method="post">
        Nombre <input type="text" name="txtNombre" value=""/><br/>
        Contacto <input type="text" name="txtcontactousuarionuevo" value=""/><br/>
        Pass <input type="text" name="txtPass" value=""/><br/>
        <input type="submit" name="btnSubmit" value="Insert"/>
    </form>
</body>

My app has a Login Screen and a button that takes it to a register form, the .php executed on that page (Login page) looks like this:

<?PHP
include_once("connection.php"); 
if(isset($_POST['txtUsername']) && isset($_POST['txtPassword'])){

$username = $_POST['txtUsername'];
$password = $_POST['txtPassword'];
$query = "SELECT * FROM estudiante WHERE Nombre = '$username' 
    AND Pass = '$password'";

$result = mysqli_query($conn, $query);
if($result->num_rows > 0){ //has record. correct username and password
    echo "success";
    while($row = $result->fetch_assoc()) {
     echo " ". $row["Id_Estudiante"]. "";
     exit;
 }
    exit;
}
else{
    echo "Wrong username and password"; 
    exit;
    }
    exit;
}
?>


<html>
<head><title>Login | ProyectoBD</title></head>
<body>
    <h1>Login ProyectoBD | <a>Santiago Troitiño C - 201421697</a></h1>
    <form action="<?PHP $_PHP_SELF ?>" method="post">
        Nombre <input type="text" name="txtUsername" value="" placeholder="Ingresar Nombre" /><br/>
        Password <input type="password" name="txtPassword" value="" placeholder="Ingresar Pass" /><br/>
        <input type="submit" name="btnSubmit" value="Login"/>
    </form>
</body>
</html>

Those are the only .php excuted on this part of the app... As you can see on this image the number "2147483647" keeps appearing at complete random times, I used that number for a register once but kkeps appearing

Any ideas of how may I solve this? Thanks!

What is the data type of Contacto in your database? Does the issue present itself when you include Non-Numeric characters. For example, if you have your data type in your database for a phone number as a numeric type (BIGINT, INT) and your users attempt to enter VARCHAR characters like hyphens ie "111-111-1111" it can cause the database to save the entry as the highest number the data type can hold. If this issue occurs when you use non-numeric characters, change your data type for Contacto to VARCHAR.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM