Jump to content

farahZ

Members
  • Posts

    80
  • Joined

  • Last visited

Profile Information

  • Gender
    Female

farahZ's Achievements

Member

Member (2/5)

2

Reputation

  1. hey there i dont know whats wrong with my code.. form not sent to the database when clicking "save" the first part of the code is about uploading a picture, url saved to $path the second part is about sending the data of the form filled (student info) if(isset($_REQUEST['save'])) { if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; $path="pic/".date("ymdHis")."_". $_FILES["file"]["name"]; if(move_uploaded_file($_FILES["file"]["tmp_name"], $path) ) { echo "تمت اضافة الصورة"; } } } else { echo "لم تتم اضافة الصورة<br>"; } if($sql=$db->query("INSERT INTO `kafala`.`std_basic` ( `id` ,`fname` ,`sname` ,`lname` ,`mname` ,`std_num` ,`acc_family` ,`home_phone` ,`mobile_phone` ,`email` ,`std_type` ,`sex` ,`nas` ,`mazhab` ,`dob` ,`sec_lan` ,`pic`,`std_siblings`,`std_mo3arrif`) VALUES (NULL , '".es("fname")."', '".es("sname")."', '".es("lname")."', '".es("mname")."', '".es("std_num")."', '".es("acc_family")."', '".es("home_phone")."', '".es("mobile_phone")."', '".es("email")."', '".es("std_type")."', '".es("sex")."', '".es("nas")."', '".es("mazhab")."', '".es("dob")."','".es("sec_lan")."', '".$path."', '".es("std_siblings")."', '".es("std_mo3arrif")."', '".es("std_activity")."')")) { echo "تمت اضافة الطالب<br>"; if( $_POST['std_type']=="ابتدائي") header("Location: newstd_elementary.php"); else if( $_POST['std_type']=="متوسط") header("Location: newstd_middle.php"); else if( $_POST['std_type']=="ثانوي") header("Location: newstd_secondary.php"); else if( $_POST['std_type']=="جامعي") header("Location: newstd_university.php"); else if( $_POST['std_type']=="دراسات عليا") header("Location: newstd_highLevel.php"); } else { echo 'student not added'; } }
  2. i am not able to figure out why my data isnt sent to the database! it was working fine before.. any help? var_dump isn't outputting if ( ! empty( $_POST ) ) { if(isset($_REQUEST['save'])) { if($sql=$db->query("INSERT INTO `kafala`.`std_basic` ( `fname` ,`sname` ,`lname` ,`mname` ,`std_num` ,`acc_family` ,`home_phone` ,`mobile_phone` ,`email` ,`std_type` ,`sex` ,`nas` ,`mazhab` ,`dob` ,`sec_lan` ,`pic`,`std_siblings`,`std_mo3arrif`) VALUES (NULL , '".es("fname")."', '".es("sname")."', '".es("lname")."', '".es("mname")."', '".es("std_num")."', '".es("acc_family")."', '".es("home_phone")."', '".es("mobile_phone")."', '".es("email")."', '".es("std_type")."', '".es("sex")."', '".es("nas")."', '".es("mazhab")."', '".es("dob")."','".es("sec_lan")."', '".$path."', '".es("std_siblings")."', '".es("std_mo3arrif")."')")); var_dump($sql); { echo "تمت اضافة الطالب<br>"; header("Location: newstd1.php"); } } }
  3. this form works fine, but am trying to change the 'other' value into some word in arabic, then as a result the form doesnt work properly! any encoding issues for arabic letters? <form name="myform"> <table> <tr> <td> <select name="one" onchange="if (this.value=='other'){this.form['other'].style.visibility='visible'}else {this.form['other'].style.visibility='hidden'};"> <option value="" selected="selected">Select...</option> <option value="1">1</option> <option value="2">3</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="other">Other</option> </select> <input type="textbox" name="other" style="visibility:hidden;"/> </td> </tr> </table> </form>
  4. hello i am trying to let the user choose from a drop-down list his educational level, and according to the level chosen, attributes are shown on the browser in the same page what is the fastest way? should i do i do it using php or javascript? any link for assistance??
  5. and how can i print them and submit it? i.e. how can i extract their values??? using a for loop or foreach??
  6. as u have said before, the problem is with $c .. its not being changed or saved!
  7. i think i got your idea but how will be able to call them afterwards for printing? because each foodtype has its own type, quantity and unit.. thats the neat code.. i really dont know if i'm able to make myself clear if (isset($_POST['add'])) { // check if an option has been selected if (empty($_POST['foodType'])) { echo 'You need to select some food!'; } else { if (!isset($_SESSION['foodTypes']) || !isset($_SESSION['Quantity']) || !isset($_SESSION['Unit'])) { // if the session is not yet created, create it now $_SESSION['foodTypes'] = array(); $_SESSION['Quantity']= array (); $_SESSION['Unit']=array(); $c=0; } // check to see if the newly added food type is not already in the array if (in_array($_POST['foodType'], $_SESSION['foodTypes']) === false) { // The selected food item is not in the array // add the selected food item to total food array $_SESSION['foodTypes'][$c] = $_POST['foodType']; $_SESSION['Quantity'][$c]= $_POST['fooDquantity']; $_SESSION['Unit'][$c]=$_POST['quantityValue']; $c++; } } } if (isset($_POST['submit'])) { // check if the session exists, or if its empty if (!isset($_SESSION['foodTypes']) || empty($_SESSION['foodTypes'])) { echo 'No food in the list to submit!'; } else { $con=mysqli_connect("localhost","root","","inshapewebsite"); if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $date=date("Y-m-d"); for ($i =0; $i <=$c; $i++) { $cal=getCalories($_SESSION['foodTypes'][i], $_SESSION['Quantity'][i], $_SESSION['Unit'][i]); $sql=""; $clid=$_SESSION['views'][0]; $q= $_SESSION['Quantity'][i]. ' ' . $_SESSION['Unit'][i]; $food=$_SESSION['foodTypes'][i]; $sql = "INSERT INTO fooddiary (ID, Date, DayTime, Food, Quantity, Calories) VALUES ('$clid', '$date', 'Lunch', '$food', '$q', $cal)"; var_dump($sql); $result = mysqli_query($con, $sql) or die(mysqli_error()); } $total= calculate($_SESSION['foodTypes'], $_SESSION['Quantity'], $_SESSION['Unit']); echo 'The total calories submitted is ' . $total, "\n"; unset($_SESSION['foodTypes']); mysqli_close($con); } function calculate($foodTypes, $Quantity, $Unit){ $calories = 0; for ($i =0; $i <=$c; $i++) { $fcal=getCalories($_SESSION['foodTypes'][i], $_SESSION['Quantity'][i], $_SESSION['Unit'][i]); $calories= $calories + $fcal; } return $calories; } function getCalories($food, $foodQuan, $foodVal) { // Create connection $con=mysqli_connect("localhost","root","","inshapewebsite"); // Check connection if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $query = "SELECT Size, Calories FROM food where Food='$food' "; $result = mysqli_query($con,$query); $row = mysqli_fetch_array($result); if($foodVal=='Portion') { $fcal=$foodQuan*$row['Calories']; } else if($foodVal=='Grams') { $fcal=($foodQuan*$row['Calories'])/$row['Size']; } else $fcal=$row['Calories']; return $fcal; }
  8. Saving the value of $c?? What do u mean? Any quick example
  9. Hey Its not working and I have no clue why Problem with the counter cz I tried echoing it.. no value nothing
  10. hey,i dont know if my work is correct or no ! I am trying to create several session arrays, and fill them with user inputs the common between the session arrays will be the counter ($c) then using the counter, with the help of a for loop, i want to print the arrays !! here is the code.. please have a look, any mistake or notice please inform me <?php if (isset($_POST['add'])) { // check if an option has been selected if (empty($_POST['foodType'])) { echo 'You need to select some food!'; } else { if (!isset($_SESSION['foodTypes']) || !isset($_SESSION['Quantity']) || !isset($_SESSION['Calories']) || !isset($_SESSION['Unit'])) { // if the session is not yet created, create it now $_SESSION['foodTypes'] = array(); $_SESSION['Quantity']= array (); $_SESSION['Calories']=array(); $_SESSION['Unit']=array(); $c=0; } // check to see if the newly added food type is not already in the array if (in_array($_POST['foodType'], $_SESSION['foodTypes']) === false) { // The selected food item is not in the array // add the selected food item to total food array $_SESSION['foodTypes'][$c] = $_POST['foodType']; $_SESSION['Quantity'][$c]= $_POST['fooDquantity']; $_SESSION['Unit'][$c]=$_POST['quantityValue']; echo $c; $c++; //$foodQuan = $_POST['fooDquantity']; // $foodVal=$_POST['quantityValue']; // $_SESSION['Quantity'][$c]= $foodQuan ." ". $foodVal; } } } function print_array(){ if(!empty($_SESSION['foodTypes'])){ echo '<br>'. '<br>'. "Food Added:" . '<br>'; // display the current food list for ($i =0; $i <=$c; $i++) { $fcal=getCalories($_SESSION['foodTypes'][i], $_SESSION['Quantity'][i], $_SESSION['Unit'][i]); echo $_SESSION['foodTypes'][i] . ' ' . $fcal . ' calories' .'<br>'; $calories= $calories + $fcal; } /* $_SESSION['Calories']=$fcal; foreach ($_SESSION['foodTypes'] as $food) { $fcal=getCalories($food, $foodQuan, $foodVal); echo $food . ' ' . $fcal . ' calories' .'<br>'; $calories= $calories + $fcal; //$calories= calculate($_SESSION['foodTypes']); } */ echo 'The amount of Calories is now: ' . $calories, "\n"; createDropdown($_SESSION['foodTypes']); } ?> }
  11. Hey ginerjm, I tried that.. The problem is in the first section.. quantity isnt being registered and I dont know the reason for this
  12. i can't figure out where my problem is!! I'm trying to input the quantity (text box) of each food chosen (drop down list) by the user.. food inputs working fine but quantity is storing the first item in the array only! if (!isset($_SESSION['foodTypes'])) { // if the session is not yet created, create it now $_SESSION['foodTypes'] = array(); $_SESSION['Quantity']= array (); $c=0; } // check to see if the newly added food type is not already in the array if (in_array($_POST['foodType'], $_SESSION['foodTypes']) === false) { // The selected food item is not in the array // add the selected food item to total food array $_SESSION['foodTypes'][] = $_POST['foodType']; $foodQuan = $_POST['fooDquantity']; $foodVal=$_POST['quantityValue']; //only first item of quantity is added $_SESSION['Quantity'][$c]= $foodQuan ." ". $foodVal; echo $_SESSION['Quantity'][$c]; echo $c++; } //submitting the food to the database (first item of quantity is sent only) // user presses submit, after he is done adding all food he wants $c=0; (starting from ) to pass by all quantity registered) foreach ($_SESSION['foodTypes'] as $food) { $cal=0; $sql=""; $clid=$_SESSION['views'][0]; $q=$_SESSION['Quantity'][$c]; echo $q; $sql = "INSERT INTO fooddiary (ID, Date, DayTime, Food, Quantity, Calories) VALUES ('$clid', '$date', 'Lunch', '$food', '$q', $cal)"; $c++; $result = mysqli_query($con, $sql) or die(mysqli_error()); }
  13. ya i found thanks for your help!!!
  14. the table in mysql has: FID---Food---Size---Calories in the dropdown list.. each option has: Food--Size--Calories
  15. hey guys!!! i was working on extractinng value from MySql and inserting them in a drop-down list but suddenly i realized i had duplicates in the list!! but no duplicates in the table when i open mysql thats the whole code please help ( <select name="foodType" onChange="autoSubmit();"> <option VALUE=""></option> <?PHP $query = "SELECT Food, Size, Calories FROM food order by Food"; $result = mysqli_query($con,$query); while($row = mysqli_fetch_assoc($result)) { echo ("<option VALUE=\"".$row['Food']."\" " . ($food == $row['Food'] ? " selected" : "") . ">".$row['Food'].' - ' .$row['Size']. ' - '.$row['Calories']."</option>"); } ?>
×
×
  • 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.