Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6141857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:18:29+00:00 2026-05-23T18:18:29+00:00

I have a little problem with a PHP code that was supposed to edit

  • 0

I have a little problem with a PHP code that was supposed to edit database table. Instead, it’s giving me ‘person not defined error – pointing to lines 18 and 19. And down the code, it says ‘id’ is undefined as well.

<?php
    $con = mysql_connect("localhost","myuser","mypass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

    mysql_select_db("mydb", $con);
    if(!isset($_POST['submit'])){
    $q = "SELECT * FROM person WHERE id = $_GET[id]";
    $result = mysql_query($q) or die(mysql_error());
    $person = mysql_fetch_array($result);
    }
?>

<h1>You are Modifying A Record</h1>
  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    Name:<input type="text" name="myname" id="myname" value ="<?php echo $person['name']; ?>" /> <br />
    Description: <input type="text" name="mydescription" id="mydescription" value ="<?php echo $person['description']; ?>" /> <br />
    <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" />
    <input type="submit" name="submit" value="Modify" />

</form>

<?php
  if(isset($_POST['submit'])){
    $q = "UPDATE person SET `name`='$_POST[myname]', `description`='$_POST[mydescription]' WHERE id = $_POST[id]";
     mysql_query($q) or die(mysql_error());
     //header('Location: select.php');
     echo 'User has been modified successfully!';
     }else{

     }
?>

Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:18:30+00:00Added an answer on May 23, 2026 at 6:18 pm

    Well, you’re only conditionally defining $person. So, the first time you view the page, PHP should show an error.

    You can fix this by adding an “else” clause:

    if(!isset($_POST['submit'])){
        $q = "SELECT * FROM person WHERE id = $_GET[id]";
        $result = mysql_query($q) or die(mysql_error());
        $person = mysql_fetch_array($result);
    }
    else
    {
        $person = array( 'name'=> '', 'description'=>'' );
    }
    

    As to $_GET[ ‘id’ ], are you going to the page with an ?id=<value> in the url? If not, then $_GET[ ‘id’ ] will be undefined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem with my regular expression, that I use in PHP.
I have this little problem, that I cannot figure out which arguments to pass
I have a little problem about using jQuery (I really do not know jQuery
I have a little php/mysql app I put together that takes an input form
I have a little bookmarklet that opens up a new window, only problem is,
I have a little problem that I can't figure out how to solve. I
I am having a little problem with the following code: <?php class appointments {
I have been given a large PHP project that I am supposed to fix
I have a little problem with my if(isset($_POST['submit'])) code. What I want is some
I have a PHP web application where I've made a little module system, that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.