Jump to content
Sigmahokies

Update data in database

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

Share this post


Link to post
Share on other sites

Where's it breaking and what error messages are you getting?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Oh, I missed that part, I just changed that $updated from $update. Seem it doesn't work with update in database, it's result same. It haven't update...I think something is missing, I tried to use PHP tester, test showed it's fine. Very odd.

 

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...