Jump to content

Update data in database


Sigmahokies

Recommended Posts

Hi everyone,

I need a help...I don't understand why it is not work. I'm trying to "update" data in database, but it couldn't do that. Maybe there is wrong script in PHP. Can you find what did I do wrong?

	//Edit data from database
if(isset($_GET['edit'])) {
    $edit = $_GET['edit'];
    $update = "select * FROM sampleDB where ID = '$edit';";
    $updated = mysqli_query($GaryDB, $update);
    
    $change = mysqli_fetch_assoc($updated);
    if($change) {
        $editted = "<tr><td colspan='4'><input type='text' name='update' value='".$change['ID']."' readonly></td></tr>
        <tr><td colspan='5'><input type='text' name='update1' value='".$change['FirstName']."'></td></tr>
        <tr><td colspan='5'><input type='text' name='update2' value='".$change['LastName']."'></td></tr>
        <tr><td colspan='5'><input type='text' name='update3' value='".$change['City']."'></td></tr>
        <tr><td colspan='5'><input type='text' name='update4' value='".$change['State']."'></td></tr>
        <tr><td><input type='radio' name='update5' value='EST'>EST</td><td><input type='radio' name='update5' value='CST'> CST</td><td><input type='radio' name='update5' value='MST'> MST</td><td><input type='radio' name='update5' value='PST'> PST</td></tr>
        <tr><td colspan='5'><input type='submit' name='updateddata' value='Update data'></td><tr>";
    
        if(isset($_POST['updateddata'])) {
            $updateFirst = $_POST['update1'];
            $updateLast = $_POST['update2'];
            $updateCity = $_POST['update3'];
            $updateState = $_POST['update4'];
            $updateTime = $_POST['update5'];
            
        
            $updated = "UPDATE `sampleDB` SET `FirstName`='$updateFirst', `LastName`='$updateLast', `City`='$updateCity', `State`='$updateState', `TimeZone`='$updateTime' WHERE `ID` = '$edit';";
            $up_date = mysqli_query($GaryDB, $update);
        
            if(isset($up_date)) {
                header('location: sampleDB.php');
                
            } else {
                $updated2 = "Could not updated data";
            }
        }
                    
    }
}
	

Anyone can help will be very appreciate

Thanks,

Gary

Link to comment
Share on other sites

 

$updated = "UPDATE `sampleDB` SET `FirstName`='$updateFirst', `LastName`='$updateLast', `City`='$updateCity', `State`='$updateState', `TimeZone`='$updateTime' WHERE `ID` = '$edit';";            

$up_date = mysqli_query($GaryDB, $update);

See the difference, it still picking up the select statement variable.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...