Jump to content

farahZ

Members
  • Posts

    80
  • Joined

  • Last visited

Posts posted by farahZ

  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. 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;
    }
    
  6. 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']);
    }
    ?>
    }
    
  7. 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());
    }
     
    
    
    

     

  8. 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>");
      }
    ?>
    
  9. 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
    
  10. i'm trying to view in a table:

     

    daytime --- meal --- calories

     

    the table in the database has (fooddiary)

    ID--Date---DayTime---Food--Calories

     

    and table: food

    FID---FoodName---Size---Calories

     

    i'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
  11. 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);
    }
     
    
  12. 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 code

    any 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++;
    }
  13. 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!";
    }
    
×
×
  • 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.