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 6213867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:46:25+00:00 2026-05-24T06:46:25+00:00

I have done this before and for some reason I just can’t get it

  • 0

I have done this before and for some reason I just can’t get it to work this time!
I’m pulling my hair out over this! Because there is no errors, it just wont update the database.

Basically I Have a Table with student data in….

ID | IMGNU | Firstname | Surname | FBID

Let’s use row 233 for an example.

I can view a specific row by going to view.php?ID=233

Then that works, but now i want to be able to go to edit.php?ID=233
and it should load a form, that already has the info from row 233.
I should then be able to edit the data in the fields and submit the form,
which would change the information in the database.

Here is what i have already.

edit.php

<?php
mysql_connect('localhost', 'admin', 'passw0rd') or die(mysql_error());
echo "Tick <p>";
mysql_select_db("students") or die(mysql_error());
echo "Tick"; 

$UID = $_GET['ID'];

$query = mysql_query("SELECT * FROM stokesley_students WHERE id = '$UID'")
or die(mysql_error());  

while($row = mysql_fetch_array($query)) {
echo "";

$firstname = $row['firstname'];
$surname = $row['surname'];
$FBID = $row['FBID'];
$IMGNU = $row['IMGNU'];


};

?>

<form action="update.php?ID=<?php echo "$UID" ?>" method="post">

IMGNU: <input type="text" name="ud_img" value="<?php echo "$IMGNU" ?>"><br>

First Name: <input type="text" name="ud_firstname" value="<?php echo "$firstname" ?>"><br>

Last Name: <input type="text" name="ud_surname" value="<?php echo "$surname" ?>"><br>

FB: <input type="text" name="ud_FBID" value="<?php echo "$FBID" ?>"><br>

<input type="Submit">
</form>

And here is update.php

<

?php

$ud_ID = $_GET["ID"];

$ud_firstname = $_POST["ud_firstname"];
$ud_surname = $_POST["ud_surname"];
$ud_FBID = $_POST["ud_FBID"];
$ud_IMG = $_POST["ud_IMG"];

mysql_connect('localhost', 'admin', 'passw0rd') or die(mysql_error());
echo "MySQL Connection Established! <br>";

mysql_select_db("students") or die(mysql_error());
echo "Database Found! <br>";


$query="UPDATE * stokesley_students SET firstname = '$ud_firstname', surname = '$ud_surname', 
FBID = '$ud_FBID' WHERE ID ='$ud_IMG'";

mysql_query($query);

echo "<p>Record Updated<p>";

mysql_close();
?>

Any ideas would be much appreciated, maby im just missing something stupid?

Thanks
Alex

  • 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-24T06:46:26+00:00Added an answer on May 24, 2026 at 6:46 am

    edit.php – with some changes

    <?php
    mysql_connect('localhost', 'admin', 'passw0rd') or die(mysql_error());
    mysql_select_db("students") or die(mysql_error());
    
    $UID = (int)$_GET['ID'];
    $query = mysql_query("SELECT * FROM stokesley_students WHERE id = '$UID'") or die(mysql_error());
    
    if(mysql_num_rows($query)>=1){
        while($row = mysql_fetch_array($query)) {
            $firstname = $row['firstname'];
            $surname = $row['surname'];
            $FBID = $row['FBID'];
            $IMGNU = $row['IMGNU'];
        }
    ?>
    <form action="update.php" method="post">
    <input type="hidden" name="ID" value="<?=$UID;?>">
    IMGNU: <input type="text" name="ud_img" value="<?=$IMGNU;?>"><br>
    First Name: <input type="text" name="ud_firstname" value="<?=$firstname?>"><br>
    Last Name: <input type="text" name="ud_surname" value="<?=$surname?>"><br>
    FB: <input type="text" name="ud_FBID" value="<?=$FBID?>"><br>
    <input type="Submit">
    </form>
    <?php
    }else{
        echo 'No entry found. <a href="javascript:history.back()">Go back</a>';
    }
    ?>
    

    update.php (Apart from the asterisk, Your query was also matching ID with the $ud_IMG variable)

        <?php
        mysql_connect('localhost', 'admin', 'passw0rd') or die(mysql_error());
        mysql_select_db("students") or die(mysql_error());
    
        $ud_ID = (int)$_POST["ID"];
    
        $ud_firstname = mysql_real_escape_string($_POST["ud_firstname"]);
        $ud_surname = mysql_real_escape_string($_POST["ud_surname"]);
        $ud_FBID = mysql_real_escape_string($_POST["ud_FBID"]);
        $ud_IMG = mysql_real_escape_string($_POST["ud_IMG"]);
    
    
        $query="UPDATE stokesley_students
                SET firstname = '$ud_firstname', surname = '$ud_surname', FBID = '$ud_FBID' 
                WHERE ID='$ud_ID'";
    
    
    mysql_query($query)or die(mysql_error());
    if(mysql_affected_rows()>=1){
        echo "<p>($ud_ID) Record Updated<p>";
    }else{
        echo "<p>($ud_ID) Not Updated<p>";
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm designing a game server and I have never done anything like this before.
Has anyone done this / have some example code?
Okay i've seen this done somewhere before where you have a function that takes
I have done this: $ z() { echo 'hello world'; } How do I
I could have sworn i have done this somewhere - im using 2.0 right
I need to create a Firebird Database programmatically using DBExpress. I have done this
I want to make a development server for Ruby. (I have done this for
In a previous life, I might have done something like this: <a href=# onclick=f(311);return
I thought this would have done it... $rowfetch = $DBS->{Row}->GetCharValue(meetdays); $rowfetch = /[-]/gi; printline($rowfetch);
I have done a bit of testing on this myself (During the server side

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.