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

  • Home
  • SEARCH
  • 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 6151829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:49:27+00:00 2026-05-23T19:49:27+00:00

I’m retrieving information about resources from a MySQL database using PHP. The information about

  • 0

I’m retrieving information about “resources” from a MySQL database using PHP. The information about each resource is output as HTML in a format like the following:

Title
Description
Etc.

Each resource then has an “edit” link which runs JavaScript onclick. This JS inserts a form containing the selected resource’s information, to be edited and updated in the database. If JavaScript is disabled, the user is brought to a separate page which has only the form to edit that particular resource. So, my question: How do I manage an arbitrary number of forms on the same page that all have the same function, just pertain to different rows of a MySQL database (different “resources”)? Particularly, how would I identify the particular resource to be edited in the form inserted by Javascript?

Right now I’m using a hidden input to carry the resource id (erid), but what would the PHP script look like which actually handles the form action? This problem arises because every name for input type=”submit” currently carries the erid, e.g. name=”update1″, name=”update2″, etc.

To retrieve resources from database:

require('inc/db_connect_info.config');

$mysqli = new mysqli($host, $mysqlilogin, $mysqlipassword, $databaseName);

if ( mysqli_connect_error() ) {
    die("Can't connect to database: " . mysqli_connect_error() );
}

else{
    $testQuery = "SELECT * FROM eresources NATURAL JOIN subjects";
    $testResult = $mysqli->query($testQuery);

    if($testResult && $testResult->num_rows >= 1) {


        while($testArray = $testResult->fetch_assoc() ) {

        $testArray['stitle'] = htmlentities($testArray['stitle']);


    // START er div

        print("<div id=\"er".$testArray['erid']."\" class=\"grey\">");          print("\n\n\t");

    // erid, link, title, descr
    print("<p>".$testArray['erid'].": <a id=\"link".$testArray['erid']."\" href=\"".$testArray['link']."\">".$testArray['ertitle']."</a> - <span id=\"descr".$testArray['erid']."\">".$testArray['descr']."</span></p>");
        print("\n\t");


    // edit "link"
    print("<a href=\"edit.php?erid=".$testArray['erid']."\" onclick=\"return showEdit(".$testArray['erid'].")\">Edit</a>");
    print("&nbsp;&nbsp;&nbsp;&nbsp;");


    // END er div
    print("</div>");
    print("\n\n");
        }
}

    // If there was a problem retrieving resources, print an error message //
    else{
        print("<p>No e-resources found!</p>");
    }

    $mysqli->close();
}

JavaScript function to insert update form right there on page if “edit” link is clicked
(assuming JavaScript is enabled):

function showEdit(erid) {

//get page url for form submission
var url = document.location.href;

//current title
var erTitle = document.getElementById("link" + erid).innerHTML;

//current link
var erLink = document.getElementById("link" + erid).getAttribute("href");

//current description
var erDescr = document.getElementById("descr" + erid).innerHTML;

//current subject under which electronic resource is filed
var erSubject = document.getElementById("subject" + erid).innerHTML;

//clear the er div
document.getElementById("er" + erid).innerHTML = "";

//then fill it with a form for new values, to be submitted to the same page
//the form is prepopulated with the current values from the database

    document.getElementById("er" + erid).innerHTML = 
"<form action=\"" + url + "\" method=\"post\">" + 
"Title<br /><input type=\"text\" name=\"updated_er_title"+erid+"\" value=\"" + erTitle + "\"  size=\"100\" /><br /><br />" + 
"Link<br /><input type=\"text\" name=\"updated_er_link"+erid+"\" value=\"" + erLink + "\" size=\"100\" /><br /><br />" + 
"Description<br /><textarea name=\"updated_er_descr"+erid+"\" cols=\"75\" rows=\"10\">" + erDescr + "</textarea><br /><br />" + 
"Free Status<br />" + erFree + "<br /><br />" + 
"Subject<br /><input type=\"text\" name=\"updated_er_subject"+erid+"\" value=\"" + erSubject + "\" size=\"100\" /><br /><br />" + 
"<input type=\"hidden\" name=\"erid\" value=\""+erid+"\" />" +
"<input type=\"submit\" name=\"update" + erid + "\" value=\"Update\" />" +
"</form>";

// return false so the link is not followed if javascript is enabled
// if javascript is disabled, link provides same form on separate page
return false;
}
  • 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-23T19:49:29+00:00Added an answer on May 23, 2026 at 7:49 pm

    Do you really need to have a separate form for each resource? Why not have one form, set inside a div. When the user clicks “edit”, the onclick handler would then populate the fields in the form with the data for the selected resource, place the div in the location where it needs to be for the selected resource and set its css display to ‘block’. The form can contain a hidden input, which would be set to the resource ID. When the form is submitted, the server-side PHP would have the resource’s ID to do the DB update. If the form is submitted using AJAX, then onsubmit handler can take the data from the input fields and modify the non-editable display for the selected resource, then set the form div’s css display to ‘none’.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

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.