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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:39:34+00:00 2026-06-02T20:39:34+00:00

this is my latest problem. I’ve got the layout and everything working, but now

  • 0

this is my latest problem. I’ve got the layout and everything working, but now i am trying to figure out the php side of this part. what i want to do is how do i specifically say which radio button is checked using php? i tried using $_POST[‘ins’] (where ‘ins’ is the id for the insert button) but that didn’t work. i want it to work out as when the insert button is checked, do whatever steps, but i don’t know how to get it so say that the insert button is being selected/checked.

here is my code

<html>
<head><title></title>
<script type="text/javascript">

function show()
{
if (document.getElementById('ins').checked){
document.getElementById("p1").style.display = "block"
document.getElementById("zn").style.display = "block";
document.getElementById("p2").style.display = "block"
document.getElementById("gpa").style.display = "block";
document.getElementById("p3").style.display = "none"
document.getElementById("ngpa").style.display = "none";
}
else if (document.getElementById('upd').checked){
document.getElementById("p1").style.display = "block"
document.getElementById("zn").style.display = "block";
document.getElementById("p2").style.display = "none"
document.getElementById("gpa").style.display = "none";
document.getElementById("p3").style.display = "block"
document.getElementById("ngpa").style.display = "block";
}
else {
document.getElementById("p1").style.display = "block"
document.getElementById("zn").style.display = "block";
document.getElementById("p2").style.display = "none"
document.getElementById("gpa").style.display = "none";
document.getElementById("p3").style.display = "none"
document.getElementById("ngpa").style.display = "none";
}
}

function check()
{
    if((document.getElementById("zn").value == "") ||   (document.getElementById("gpa").value == "") ||
    (isNaN(parseFloat(document.getElementById("gpa").value))))
    {
        alert("Please complete both fields and check to see if the GPA entered is a number!");
        return false;
    }
    return true;

}
</script>



</head>
<body>
<form action = "index.php" onsubmit="return check();">
<input type="radio" name="group" id = "ins" onclick ="show()"/> Insert Student <br />
<input type="radio" name="group" id = "upd" onclick ="show()"/> Update Student <br />
<input type="radio" name="group" id = "del" onclick ="show()"/> Delete Student <br />
<p id="p1" style="display:none">Enter Z-number: <br /></p>
<input type='text' name = 'z' id ="zn" maxlength='9' style="display:none"/>
<p id="p2" style="display:none"><br />Enter GPA: <br /></p>
<input type='text' name='gpa' id ="gpa" style="display:none"/>
<p id="p3" style="display:none"><br /> Enter new GPA: <br /></p>
<input type="text" name ="ngpa" id ="ngpa" style="display:none"/>
<br /><input type='submit' value='Submit request' name='submit'/>
</form>
<?php
if (isset($_POST['z'])) {
$con = mysql_connect('localhost', '*****', '***********');
if ($con) {
mysql_select_db('ghamzal', $con);

$a = $_POST['z'];
$b = $_POST['gpa'];
$sql = "INSERT INTO Students VALUES (' $a ' ,  '$b')";

if (mysql_query($sql, $con)) echo 'Operation succeeded';
else echo 'Not succeeded ' .mysql_error();




if (isset($_POST['ins'])) {
$sql = "SELECT * FROM Students";
$res = mysql_query($sql, $con);

echo "<table border ='1'>";
echo "<tr><th>Znum</th><th>GPA</th></tr>";
while ($r = mysql_fetch_array($res)) {
echo "<tr><td>".$r['Znum']."</td><td>".$r['gpa']. "</td></tr>";
}
echo "</table>";
}
mysql_close($con);
}
else {
echo 'Insertion failed'. 'Could not connect to DB.';}

}

?>
</body>
</html>
  • 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-06-02T20:39:37+00:00Added an answer on June 2, 2026 at 8:39 pm

    There are a couple of different problems here. The first one is that your form is being submitted using the GET method, but you’re trying to retrieve your values in PHP as if it had been submitted with the POST method. Since you’re updating values in a database, the POST method is preferable, so your form opening tag should be changed to this:

    <form method="post" action="index.php" onsubmit="return check();">
    

    The “name” field of an input is what ends up in your $_POST variable, and the value of that variable is the value of whichever input was selected.

    So you should change your inputs to look like this:

    <input type="radio" name="selection" value="ins" id="ins" onclick="show()"/><label for="ins">Insert Student</label><br />
    <input type="radio" name="selection" value="upd" id="upd" onclick="show()"/><label for="upd">Update Student</label><br />
    <input type="radio" name="selection" value="del" id="del" onclick="show()"/><label for="del">Delete Student</label><br />
    

    (I added the <label> markup because it’s a good practice to include that. It helps with accessibility, and if people click on the label of your radio button, it will treat it as having clicked the radio button itself.)

    Now in your PHP code:

    $selection = $_POST['selection'];
    

    Now $selection will contain the value representing which radio button was selected, and you can perform the appropriate logic:

    if ($selection == "ins") {
         // do work here
    } elseif ($selection == "upd") {
         // do work here
    }
    // etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone got this configuration working? Latest Netbeans, latest Glassfish, I created an EJB
I've been working on this problem for 7 hours now, and I still have
This is what i want to do: I want /summary.php to include 5 latest
Started working on a new application this week that is running the latest rails
I successfully installed the latest QuantumGrid from DevExpress, but I've never worked with this
I have a problem regarding this query. I want to get the applicant latest
This is a problem I encounter frequently in working with more complex systems and
WORKING UPDATE to solve this problem, I simply dragged the tasks/facebooker folder into lib
I have been struggling with this problem for a few days now and I
So my latest app runs into this problem where it complains in the logcat

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.