Jump to content

annaright

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Posts posted by annaright

  1. Hi anyone here know how to insert $GET variable into mysql, i don't know how to put this variable between curly bracket, when i put on top insert query, i got error 'Could not insert admin'...please help  :'(

     

    <?php
    mysql_connect("localhost","root","") or die(mysql_error());
    mysql_select_db("healthsystem") or die(msql_error());
    
    [color=red]//GET varibable
    
    $id = $_GET['id'];[/color]
    
    
    
    
    // file properties
    $file = $_FILES['image']['tmp_name'];
    
    
    if (!isset($file))
    
    
    echo "Please select an image";
    
    else
    {
    
    $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
    $image_name = addslashes($_FILES['image']['name']);
    $image_size = getimagesize($_FILES['image']['tmp_name']);
    
         
    
    if ($image_size==FALSE)
    	echo "That's not an image.";
    else
    {
    
    	$insert = "INSERT INTO image_tbl(m_id,name,image) VALUES ('$id','$image_name','$image')";
    	$insert2=mysql_query($insert) or die("Could not insert admin"); 
        	print "Personal Wellness Successfully Submitted";
    
    
    }
    }
    
    
    ?>
    
    

  2. I don't understand the question -- just keep everything.

     

    sorry maybe my question a bit confusing, its not INSERT but UPDATE....i want to update a table which is already have a data in the same time i don't want to overwrite the existing data. example;

     

    Table person:

     

    P_Id LastName FirstName Address City

    1 John Mayer Street 1 London

    2 Ray Caroline Street 2 Leeds

     

    UPDATE Persons

    SET Address='Street3', City='Manchester'

    WHERE LastName='Ray' AND FirstName='Caroline'

     

    The "Persons" table will now look like this:

     

    P_Id LastName FirstName Address City

    1 John Mayer Street 1 London

    2 Ray Caroline Street 3 Manchester

     

    but I still want to keep the previous data before the update as a history.

     

    sorry my english really bad  :-[

  3. First of all, post your code in code or php tags (the # button in the post editor) Secondly, you need to be specific. Just posting code and asking how to do something won't get you help. When you run this code, what happens? What do you expect to happen (obviously this would be the get variable is inserted into the database) What have you done to debug the problem. Have you printed your $_GET variable to verify it has a value? Is there a mysql error? php error?

     

    sorry i'm new in php, actually i have to two table, table1 will store members info and table2 will store personal wellness info. there is a relationship between table1 and table2, so i need to store the member_id into table2.

     

    <a href=\"add_wellness.php?id=$res[m_id]\">Add</a> when i click add, it will pass the member_id and i can add the personal wellness which is belong to this member_id.  what i expect to happen is i can insert this member_id into table2. there is no mysql error or php error , when i click submit only member_id still no value

     

     

  4. hello can anyone help me how to insert GET variable into mysql   

     

     

    <?php

    $page_title = 'Personal Wellness';

    include ('template/header.inc');

    include_once('config.php');

     

    $id = $_GET['id'];

     

    if(isset($_POST['submit']))

    //if submit was pressed

    {

    if(strlen($_POST['height'])<1) //if there was no height

    {

    print "You did not enter a height.";

    }

    else if(strlen($_POST['weight'])<1) //no weight

    {

    print "You did not enter a weight.";

    }

    else if(strlen($_POST['bodyfat'])<1) //no bodyfat

    {

    print "You did not enter a Body Fat Range";

    }

    else if (strlen ($_POST['bodywater'])<1) //no bodywater

    {

    print "You did not enter a Body Water Range";

    }

    else if( strlen($_POST['musclemass'])<1) //no musclemass

    {

    print "You did not enter a Muscle Mass";

    }

    else if (strlen ($_POST['physiqueratt'])<1) //no physiqueratt

    {

    print "You did not enter a Physique Ratings";

    }

    else if (strlen ($_POST['bonemass'])<1) //no bonemass

    {

    print "You did not enter a Bone Mass";

    }

    else if (strlen ($_POST['bmr'])<1) //no bmr

    {

    print "You did not enter a BMR";

    }

    else if (strlen ($_POST['basalmetabolic'])<1) //no basalmetabolic

    {

    print "You did not enter a Basal Metabolic Age";

    }

    else if (strlen ($_POST['visceralfat'])<1) //no visceralfat

    {

    print "You did not enter a Visceral Fat";

    }

    else if(strlen($_POST['registrationmonth'] && $_POST['registrationday'] && $_POST['registrationyear'])<1) // no date

    {

    print "You did not enter a date of birth";

    }

    else //all fields met

    {

    $id=$_GET['id'];

    $height=$_POST['height'];

    $weight=$_POST['weight'];

    $bodyfat=$_POST['bodyfat'];

    $bodywater=$_POST['bodywater'];

    $musclemass=$_POST['musclemass'];

    $physiqueratt=$_POST['physiqueratt'];

    $bonemass=$_POST['bonemass'];

    $bmr=$_POST['bmr'];

    $basalmetabolic=$_POST['basalmetabolic'];

    $visceralfat=$_POST['visceralfat'];

    $date=$_POST['registrationyear'] . '-' . $_POST['registrationmonth'] . '-' . $_POST['registrationday'];

     

    $insertadmin="INSERT into personalwelness (m_id,height,weight,body_fat,body_water,muscle_mas s,physique_ratt,bone_mass,bmr,basal_metabolic,visc eral_fat,evaluation_date) values ('$id','$height','$weight','$bodyfat','$bodywater','$mus clemass','$physiqueratt','$bonemass','$bmr','$basa lmetabolic','$visceralfat','$date')"; //registering admin in databae

    echo $insertadmin;

    $insertadmin2=mysql_query($insertadmin) or die("Could not insert admin");

    print "Personal Wellness Successfully Submitted";

    }

    }

     

    ?>

    <form method="post" class="form" action="<?php echo $_SERVER['PHP_SELF'];?>">

    <fieldset><legend>Enter Personal Wellness Information in the form below:</legend>

     

    <table width="80%" border="0">

    <tr>

    <td width="16%">Height(CM)</td>

    <td width="2%">:</td>

    <td width="82%"><label for="height"></label>

    <input type="text" name="height" id="height" value="<?php if (isset($_POST['height']))

    echo $_POST['height'];?>" /></td>

    </tr>

    <tr>

    <td>Weight(KG)</td>

    <td>:</td>

    <td><label for="weight"></label>

    <input type="text" name="weight" id="weight" value="<?php if (isset($_POST['weight']))

    echo $_POST['weight'];?>" /></td>

    </tr>

    <tr>

    <td >Body Fat Range</td>

    <td>:</td>

    <td><label for="body fat"></label>

    <input type="text" name="bodyfat" id="bodyfat" value="<?php if (isset($_POST['bodyfat']))

    echo $_POST['bodyfat'];?>" ></td>

    </tr>

    <tr>

    <td>Body Water Range(%)</td>

    <td>:</td>

    <td><label for="bodywater"></label>

    <input type="text" name="bodywater" id="bodywater" value="<?php if (isset($_POST['bodywater']))

    echo $_POST['bodywater'];?>"/></td>

    </tr>

    <tr>

    <td>Muscle Mass</td>

    <td>:</td>

    <td><label for="musclemass"></label>

    <input type="text" name="musclemass" id="musclemass" value="<?php if (isset($_POST['musclemass']))

    echo $_POST['musclemass'];?>"></td>

    </tr>

    <tr>

    <td>Physique Ratings</td>

    <td>:</td>

    <td><label for="physiqueratt"></label>

    <input type="text" name="physiqueratt" id="physiqueratt" value="<?php if (isset($_POST['physiqueratt']))

    echo $_POST['physiqueratt'];?>"></td>

    </tr>

    <tr>

    <td>Bone Mass</td>

    <td>:</td>

    <td><label for="bonemass"></label>

    <input type="text" name="bonemass" id="bonemass" value="<?php if (isset($_POST['bonemass']))

    echo $_POST['bonemass'];?>" /></td>

    </tr>

    <tr>

    <td>BMR</td>

    <td>:</td>

    <td><label for="bmr"></label>

    <input type="text" name="bmr" id="bmr" value="<?php if (isset($_POST['bmr']))

    echo $_POST['bmr'];?>"/></td>

    </tr>

    <tr>

    <td>Basal Metabolic Age</td>

    <td>:</td>

    <td><label for="basalmetabolic"></label>

    <input type="text" name="basalmetabolic" id="basalmetabolic" value="<?php if (isset($_POST['basalmetabolic']))

    echo $_POST['basalmetabolic'];?>"></td>

    </tr>

    <tr>

    <td>Visceral Fat</td>

    <td>:</td>

    <td><label for="visceralfat"></label>

    <input type="text" name="visceralfat" id="visceralfat" value="<?php if (isset($_POST['visceralfat']))

    echo $_POST['visceralfat'];?>"></td>

    </tr>

    <tr>

    <td>Evaluation Date</td>

    <td>:</td>

    <td> <?php echo date_picker("registration")?></td>

    </tr>

    </table>

    </fieldset>

    <div align="center"><input type="submit" name="submit" value="Submit" />

     

    </div>

    </form>

    <?php

    function date_picker($name, $startyear=NULL, $endyear=NULL)

    {

    if($startyear==NULL) $startyear = date("Y")-100;

    if($endyear==NULL) $endyear=date("Y")+50;

     

    $months=array('','January','February','March','Apr il','May',

    'June','July','August', 'September','October','November','December');

     

    // Month dropdown

    $html="<select name=\"".$name."month\">";

     

    for($i=1;$i<=12;$i++)

    {

    $html.="<option value='$i'>$months[$i]</option>";

    }

    $html.="</select> ";

     

    // Day dropdown

    $html.="<select name=\"".$name."day\">";

    for($i=1;$i<=31;$i++)

    {

    $html.="<option $selected value='$i'>$i</option>";

    }

    $html.="</select> ";

     

    // Year dropdown

    $html.="<select name=\"".$name."year\">";

     

    for($i=$startyear;$i<=$endyear;$i++)

    {

    $html.="<option value='$i'>$i</option>";

    }

    $html.="</select> ";

     

    return $html;

    }

    ?>

     

    <?php

    include ('template/footer.inc');

    ?>

×
×
  • 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.