Update fields of a Form using php and mysql

0

I have been writing a small script to update fields in mysql from a form with php.

But I have a problem, when I try to update the field from php using mysqli, there are no changes in the database. The field I try to use as a parameter to update is a type ID int . However, when I try to use a value of type string if you update it. I do not know if there is a problem updating fields of type int from php. I have two pages, they are the following:

This code shows the result of my search and if it works well.

Search.php

$searchValue=$_GET["txtSearch"]; 

$connection=mysqli_connect($db_host, $db_user, $db_password, $db_name);
$query="select UserID, LastName, FirstName, UserName, Phone from User where UserID='$searchValue'";
$recordset=mysqli_query($connection, $query);

while($row=mysqli_fetch_array($recordset, MYSQLI_ASSOC)) 
{       
    $UserID=$row['UserID'];
    $LastName = $row['LastName'];
    $FirstName = $row['FirstName'];
    $UserName = $row['UserName'];
    $Phone=$row['Phone'];

    echo "<form action='Update.php' method='get'>";

    echo "<input type='text' name='txtUserID' value='$UserID' disabled> <br/> <br/>";
    echo "<input type='text' name='txtLastName' value='$LastName'> <br/> <br/>";
    echo "<input type='text' name='txtFirstName' value='$FirstName'> <br/> <br/>";
    echo "<input type='text' name='txtUserName' value='$UserName'> <br/> <br/>";
    echo "<input type='text' name='txtPhone' value='$Phone'> <br/> <br/>";

    echo "<input type='submit' name='btnUpdate' value='Update Values' />";

    echo "</form>";     

}

The problem is here, when I execute the query. I have been trying and not counting the solution of the problem. Is the query incorrect? Is there any other way to update values type int from php?

This is the code of the other page that the update should do.

Update.php

$userID=$_GET["txtUserID"];
$lastName=$_GET["txtLastName"];
$firstName=$_GET["txtFirstName"];
$userName=$_GET["txtUserName"];
$phone=$_GET["txtPhone"];

$connection=mysqli_connect($db_host, $db_user, $db_password, $db_name);

$query="UPDATE User SET LastName='$lastName', FirstName='$firstName', UserName='$userName', Phone=$phone
        WHERE UserID=$userID";

$recordset=mysqli_query($connection, $query);

echo "<h1> Succesfull Operation.  </h1>";

If instead of using WHERE UserID=$userID I use WHERE LastName=$lastName if the update is fine.

    
asked by krlosfgx 31.01.2017 в 15:16
source

1 answer

3

The value of idUsuario is not reaching you I recommend that the field instead of putting it as disabled you place it as hidden :

<input type='hidden' name='txtUserID' value='$UserID'>

The problem is not the data type int but the value of txtUserID does not reach it.

    
answered by 31.01.2017 в 15:32