farahZ
-
Posts
80 -
Joined
-
Last visited
Posts posted by farahZ
-
-
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 outputtingif ( ! 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"); } } }
-
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>
-
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?? -
and how can i print them and submit it?
i.e. how can i extract their values???
using a for loop or foreach??
-
as u have said before, the problem is with $c .. its not being changed or saved!
-
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; }
-
Saving the value of $c??
What do u mean? Any quick example
-
Hey
Its not working and I have no clue why
Problem with the counter cz I tried echoing it.. no value nothing
-
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']); } ?> }
-
Hey ginerjm, I tried that..
The problem is in the first section.. quantity isnt being registered and I dont know the reason for this
-
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()); }
-
ya i found
thanks for your help!!! -
the table in mysql has:
FID---Food---Size---Calories
in the dropdown list.. each option has: Food--Size--Calories
-
hey guys!!!
i was working on extractinng value from MySql and inserting them in a drop-down listbut 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>"); } ?>
-
can it be using like this?
SELECT fe.DayTime, SUM(f.Calories) as Calories, GROUP_CONCAT(select Food from fooddiary where DayTime=fe.DayTime and Date=2013-05-17) FROM fooddiary fe INNER JOIN food f USING (Food) WHERE fe.ID= 111 And fe.Date=2013-05-17 GROUP BY fe.DayTime
-
dont wanna mess up the daytime and calories.. they are working fine here!
-
i'm trying to view in a table:daytime --- meal --- caloriesthe table in the database has (fooddiary)ID--Date---DayTime---Food--Caloriesand table: foodFID---FoodName---Size---Caloriesi'm not able to show the food a person ate for each meal !!DayTime and Sum of Calories were working fine,, now trying to add the food a user ate corresponding to the day time.. please help me
SELECT fe.DayTime, SUM(f.Calories) as Calories, (select FoodName from fooddiary where DayTime=fe.DayTime) as meal
FROM fooddiary fe
INNER JOIN food f USING (Food)
WHERE fe.ID= 111 And fe.Date='$date'
GROUP BY fe.DayTime -
done.. by removing the num_rows!!
-
i tried that, its now creating rows but not filling them!!
thats the code i reached<?php $num_rows =''; $i=0; $date =$_POST['dates']; $sql="SELECT fe.DayTime, SUM(f.Calories) as Calories FROM fooddiary fe INNER JOIN food f USING (Food) WHERE fe.ID= 111 And fe.Date='$date' GROUP BY fe.DayTime"; $result = mysqli_query($con, $sql) or die(mysqli_error()); //var_dump($sql); $num_rows = mysqli_num_rows($result); ?> <table width="800" border="3"> <tr> <th bgcolor="#77eb8a" height="25" scope="col">Meal</th> <th bgcolor="#77eb8a" scope="col">Calories</th> </tr> <?php while ($row = mysqli_fetch_array($result) && $i<$num_rows) { ?> <tr> <td><?php echo $row['DayTime'];?></td> <td><?php echo $row['Calories'];?></td> </tr> <?php $i++; } ?></table> <?php $sql1="SELECT SUM(f.Calories) as Calories FROM fooddiary fe INNER JOIN food f USING (Food) WHERE fe.ID= 111 And fe.Date='$date'"; $result1 = mysqli_query($con, $sql1) or die(mysqli_error()); $row = mysqli_fetch_array($result1); echo 'The total Calories for this day is ' . $row['Calories']; mysqli_close($con); }
-
hello, i am trying to print the query $result, each in a row!!but i am just getting the form of the table without values added to it..the query works fine since it was outputting normally before adding the table codeany help !!
$result = mysqli_query($con, $sql) or die(mysqli_error());
$num_rows = mysqli_num_rows($result);
while ($row = mysqli_fetch_array($result) && $i<$num_rows) {
?>
<tr>
<td><?php echo $row['DayTime'];?></td>
<td><?php echo $row['Calories'];?></td>
</tr>
</table>
<?php
$i++;
} -
thankss !! solved )
-
hello
i am asking the user to enter into a textfield a number .. of course , it will be entered as a string
how can i check whether his entry is a number? (integer)
is parsing it into int a solution? whats the function for parsing in php?
$foodCals = $_POST['foodCals']; function checkCalories() { global $message,$foodCals; if(is_int($foodCals)==false) $message=" Calories should be a number!"; }
-
how can fix the tags..
i need to put some php in my html table -
yes it's.. i missed copying one brace
help help help!
in PHP Coding Help
Posted · Edited by farahZ
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)