0

Im still new in PHP, I'd like help in a php example where I click a link, a value gets updated in mysql and redirect the user to a page.

Your will be greatly appreciated.

3
  • Hi, welcome to Stack Overflow. Please read this article befor you ask a question stackoverflow.com/help/how-to-ask Commented Jul 5, 2016 at 8:24
  • Please don't ask a question like this. It's very easy to ask someone help! Commented Jul 5, 2016 at 8:29
  • @Rokas Mikalkėnas gave good solution.many possible ways are there Google it for more solution Commented Jul 5, 2016 at 8:46

1 Answer 1

1
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "UPDATE MyGuests SET lastname='Doe' WHERE id=2";

if ($conn->query($sql) === TRUE) {
    // if all ok, redirecting
    header("Location: http://example.com/myOtherPage.php");
    die();
} else {
    echo "Error updating record: " . $conn->error;
}

$conn->close();
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.