Jump to content

Manhag

Members
  • Posts

    27
  • Joined

  • Last visited

Everything posted by Manhag

  1. i wana use select box to update database // I get id from url and get "city data stored in database //intialize form create select box depending on array <?php echo "<select name=\"choose_city\">\n"; $choose_city = array('0' => 'Please choose user group', 'eg_cairo' => 'cairo', 'eg_alex' => 'alex', 'eg_giza' => 'giza'); foreach($choose_city as $city_key => $city_realname) { echo "<option value=\"$city_key\" name=\"$city_key\" id=\"$city_key\" "; if($city_key == $city_db) { echo " selected"; } echo ">$city_realname</option>\n"; } echo "</select><p />"; ?> //end form code <input type="submit" name="submit" value="Submit"> <br> <br> </form> </div> //check database connection and update selected value to database <?php } else { die(mysqli_error($link)); } if (isset($_POST['submit'])) { echo $_POST['city']; echo "||"; //get value of selected box $location = $_POST['city_key']; $query ="UPDATE `salaty_fb`.`users` SET `city`='$location' WHERE `id`='$id'"; //if data updated ...use java script pop up to inform user that update was done if ($result = mysqli_query($link, $query)) { printf("update done"); echo '<script language="javascript"> <!-- setTimeout("self.close();",1000) //--> </script> '; /* free result set */ // $result->close(); $link->close(); } else { die(mysqli_error($link)); } } ?>
  2. hello i am trying to update database using select box value i failed to do that <?php include('lib/db.php'); $id = htmlspecialchars($_GET["fid"]); $query1 = "SELECT `city` FROM `salaty_fb`.`users` WHERE `id`='$id'"; if ($result1 = mysqli_query($link, $query1)) { while($result = mysqli_fetch_array($result1)) { $city_db = $result['city']; } //$link->close(); ?> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <div style="<? if (isset($_POST['submit'])) {echo "display:none";} ?>;direction:rtl;" > <form method="post" action="updatesql.php?fid=<? echo $facebook_id; ?>" target="POPUPW" onsubmit="POPUPW = window.open('about:blank','POPUPW', 'width=200,height=100');"> <?php echo "<select name=\"choose_city\">\n"; $choose_city = array('0' => 'Please choose user group', 'eg_cairo' => 'cairo', 'eg_alex' => 'alex', 'eg_giza' => 'giza'); foreach($choose_city as $city_key => $city_realname) { echo "<option value=\"$city_key\" name=\"$city_key\" id=\"$city_key\" "; if($city_key == $city_db) { echo " selected"; } echo ">$city_realname</option>\n"; } echo "</select><p />"; ?> <input type="submit" name="submit" value="Submit"> <br> <br> </form> </div> <?php } else { die(mysqli_error($link)); } if (isset($_POST['submit'])) { echo $_POST['city']; echo "||"; //get value of selected box $location = $_POST['city_key']; $query ="UPDATE `salaty_fb`.`users` SET `city`='$location' WHERE `id`='$id'"; if ($result = mysqli_query($link, $query)) { printf("تم حفظ التحديثات"); echo '<script language="javascript"> <!-- setTimeout("self.close();",1000) //--> </script> '; /* free result set */ // $result->close(); $link->close(); } else { die(mysqli_error($link)); } } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.