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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:48:54+00:00 2026-06-08T14:48:54+00:00

I’m building a website that allows users to edit a business info. There is

  • 0

I’m building a website that allows users to edit a business info. There is 6 selects, 3 for categories and 3 for subcategories. I’m using hidden fields to get the value of what each category and subcategory was before, and then if the select isset, then insert the select/dropdown’s value.
Here’s my code:
for the MYSQL Update:

<? 
include('../config.php'); 
if (isset($_GET['id']) ) { 
   $id = (int) $_GET['id']; 
   if (isset($_POST['submitted'])) { 
       foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); }

       if(isset($_REQUEST['cselect1'])){
       $cselect1 = $_REQUEST['cselect1'];



       $query="SELECT cat FROM cat WHERE id='$cselect1'";
       $result = mysql_query ($query);
       while($catselect=mysql_fetch_array($result)){
      $catselect1 = $catselect['cat'];
       }
       } else {
       $catselect1 = $_REQUEST['beforecat1'];
       }
       if(isset($_REQUEST['cselect2'])){
       $cselect2 = $_REQUEST['cselect2'];

       $query="SELECT cat FROM cat WHERE id='$cselect2'";
       $result = mysql_query ($query);
       while($catselect=mysql_fetch_array($result)){
          $catselect2 = $catselect['cat'];
       }
       } else {
       $catselect2 = $_REQUEST['beforecat2'];
       }
       if(isset($_REQUEST['cselect3'])){
       $cselect1 = $_REQUEST['cselect3'];

       $query="SELECT cat FROM cat WHERE id='$cselect3'";
       $result = mysql_query ($query);
       while($catselect=mysql_fetch_array($result)){
       $catselect1 = $catselect['cat'];
       }
       } else {
       $catselect3 = $_REQUEST['beforecat3'];
       }

   $sql = "UPDATE `company` SET  `name` =  '{$_POST['name']}' ,  `phone` =  '{$_POST['phone']}' ,  `cat1` =  '$catselect1' ,  `cat2` =  '$catselect2' ,  `cat3` =  '$cselect3' ,  `zipcode` =  '{$_POST['zipcode']}' ,  `city` =  '{$_POST['city']}' ,  `address` =  '{$_POST['address']}' ,  `address2` =  '{$_POST['address2']}' ,  `website` =  '{$_POST['website']}' ,  `product1` =  '{$_POST['product1']}' ,  `product2` =  '{$_POST['product2']}' ,  `product3` =  '{$_POST['product3']}' ,  `product4` =  '{$_POST['product4']}' ,  `product5` =  '{$_POST['product5']}' ,  `product6` =  '{$_POST['product6']}' ,  `product7` =  '{$_POST['product7']}' ,  `subcat1` =  '{$_POST['sselect1']}' ,  `subcat2` =  '{$_POST['sselect2']}' ,  `subcat3` =  '{$_POST['sselect3']}'   WHERE `id` = '$id' "; 
   mysql_query($sql) or die(mysql_error());
   $sql = "UPDATE `company_secondary` SET  `company_description` =  '{$_POST['description']}' ,  `since` =  '{$_POST['since']}' ,  `smoking` =  '{$_POST['select3']}' ,  `delivery` =  '{$_POST['select5']}' ,  `alcohol` =  '{$_POST['select6']}' ,  `kids` =  '{$_POST['select1']}' ,  `wheelchair` =  '{$_POST['select2']}' ,  `twitter` =  '{$_POST['twitter']}' ,  `facebook` =  '{$_POST['facebook']}' ,  `youtube` =  '{$_POST['youtube']}' ,  `premium` =  '{$_POST['premium']}' ,  `creditcards` =  '{$_POST['select4']}' ,  `outdoor` =  '{$_POST['select7']}' ,  `featured` =  '{$_POST['featured']}' ,  `shortdesc` =  '{$_POST['shortdesc']}' WHERE company_id = '$id' "; 
   mysql_query($sql) or die(mysql_error());
   echo "Edited Row<br/>";
   echo "<a href='allbiz.php'>Back To Listing</a>"; 
  } 

  $row = mysql_fetch_array ( mysql_query("SELECT * FROM `company` WHERE `id` = '$id' "));

?>

and here is the form that has the hidden inputs( only posted a portion of it, can post more if needed!)

<form action='' method='POST'> 
    <p><b>Name:</b><br /><input type='text' name='name' value='<?= $row['name'] ?>' /> 
    <p><b>Phone:</b><br /><input type='text' name='phone' value='<?= stripslashes($row['phone']) ?>' />
    <?php
        $cat1 = stripslashes($row['cat1']);
        $cat2 = stripslashes($row['cat2']);
        $cat3 = stripslashes($row['cat3']);
        $subcat1 = stripslashes($row['subcat1']);
        $subcat2 = stripslashes($row['subcat2']);
        $subcat3 = stripslashes($row['subcat3']);
    ?>
    <input type='hidden' value='<?php echo $cat1;?> name='beforecat1'/>
    <input type='hidden' value='<?php echo $cat2;?> name='beforecat2'/>
    <input type='hidden' value='<?php echo $cat3;?> name='beforecat3'/>
    <input type='hidden' value='<?php echo $subcat1;?> name='beforesubcat1'/>
    <input type='hidden' value='<?php echo $subcat2;?> name='beforesubcat2'/>
    <input type='hidden' value='<?php echo $subcat3;?> name='beforesubcat3'/>
    <p><b>Cat1:</b><br />
   <?php
       $query="SELECT * FROM cat";
       $result = mysql_query ($query);
       echo"<select name='cselect1' id='cat1'><option value='0'>Please Select A Category</option>";
       // printing the list box select command
       while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt
            echo "<option value=\"".htmlspecialchars($catinfo['number'])."\">".$catinfo['cat']."</option>";

       }
       echo"</select>";
   ?>
   <?php
       $query="SELECT * FROM subcat";
       $result = mysql_query ($query);
   echo"<select name='sselect1' id='subcat1'><option value=''>Sub Category</option>";
   echo $subcat1;
   echo"'>$sucat1</option>";
       // printing the list box select command
       while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt
           echo "<option value='".htmlspecialchars($catinfo['subcat'])."' class='".$catinfo['catnumber']."'>".$catinfo['subcat']."</option>";
       }

       echo"</select>";
  ?>

  <p><b>Cat2:</b><br />
  <?php
      $query="SELECT * FROM cat";
      $result = mysql_query ($query);
  echo"<select name='cselect2' id='cat2'><option value='0'>Please Select A Category</option>";
      // printing the list box select command
      while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt
          echo "<option value=\"".htmlspecialchars($catinfo['number'])."\">".$catinfo['cat']."</option>";

      }
     echo"</select>";
   ?>
   <?php
     $query="SELECT * FROM subcat";
     $result = mysql_query ($query);
 echo"<select name='sselect2' id='subcat2'><option value=''>Sub Category</option>";
 echo $subcat1;
 echo"'>$sucat1</option>";
     // printing the list box select command
     while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt
         echo "<option value='".htmlspecialchars($catinfo['subcat'])."' class='".$catinfo['catnumber']."'>".$catinfo['subcat']."</option>";
     }

     echo"</select>";
  ?>
  <p><b>Cat3:</b><br />
  <?php
     $query="SELECT * FROM cat";
     $result = mysql_query ($query);
 echo"<select name='cselect3' id='cat3'><option value='0'>Please Select A Category</option>";
     // printing the list box select command
     while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt
         echo "<option value=\"".htmlspecialchars($catinfo['number'])."\">".$catinfo['cat']."</option>";

     }
     echo"</select>";
  ?>
  <?php
     $query="SELECT * FROM subcat";
     $result = mysql_query ($query);
 echo"<select name='sselect3' id='subcat3'><option value=''>Sub Category</option>";
     // printing the list box select command
     while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt
     echo "<option value='".htmlspecialchars($catinfo['subcat'])."' class='".$catinfo['catnumber']."'>".$catinfo['subcat']."</option>";
     }

     echo"</select>";
  ?>

My hope was that if a user changes the Cat and Subcat select/dropdowns then that will be updated in the mysql query. Otherwise, if they are left untouched, then the hidden inputs selected from the database will be updated in the mysql table just like before. But something isn’t working, when you submit the form without touching the selects/dropdowns, then the cats and subcats are wiped clean. How do I fix this?

Thanks for all 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-06-08T14:48:58+00:00Added an answer on June 8, 2026 at 2:48 pm

    I think looking for client-side solution for your form, such as Jquery will solve your problem.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into

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.