SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: update problem

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    uganda
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    update problem

    i have an update code but it does not seem to be working. below is the code.

    Code:
    html>
    <head>
    <title> Hostel - Admin </title>
    </head>
    <body>
    <p align="center" > Editting - Hostel Details </p>
    <?php
    $con= mysql_connect('localhost','aashaba', 'aashaba');
    $dab= mysql_select_db('Hostel');
    
    $ql= mysql_query("select * from Hostel order by hostelName");
    
    while($we=mysql_fetch_array($ql)){
    
    $hon = $we['hostelName'];
    $loc = $we['locationId'];
    $hot = $we['hostelType'];
    $pad = $we['postalAddress'];
    $cap = $we['capacity'];
    $cust=$we['custodian'];
    $pho = $we['phone'];
    $mail = $we['email'];
    $rul = $we['rules'];
    $custnam=$we['custodianUser'];
    $custpas=$we['custodianPass'];
    $id = $we ['hostelId'];
    
    if($update)
    {
    
    $sql = "UPDATE Hostel SET postalAddress='$pad', capacity='$cap',custodian='$cust', phone='$pho',
    email='$mail', rules='$rul', custnam='$custodianUser', custodianPass='$custpas' WHERE id=$id";
    $result = mysql_query($sql);
    echo "Thank you! Information updated.\n";
    }
    
    }
    ?>
    <form action='view1.php' method='post'>
    Hostel Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='hostelName' value='<? echo $hon ?>' >*<br>
    location &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='locationId' value='<? echo $loc ?>' >*<br>
    hostelType&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='hostelType' value='<? echo $hot ?>' ><br>
    Postal Address&nbsp;&nbsp;&nbsp;<input type='text' name='postalAddress' value='<? echo $pad ?>' ><br>
    Capacity &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='capacity' value='<? echo $cap ?>' ><br>
    Capacity &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='custodian' value='<? echo $cust ?>' ><br>
    Phone&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='phone' value='<? echo $pho ?>' ><br>
    Email&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='email' value='<? echo $mail ?>' ><br>
    Terms & Agreements<input type='text' name='rules' value='<? echo $rul ?>' ><br>
    Custodian Username <input type='text' name='custodianUser' value='<? echo $custnam ?>' ><br>
    Custodian Password<input type='text' name='custodianPass' value='<? echo $custpass?>' ><br>
    <br>
    
    Fields with * should not be edited. thank you.<br><br>
    
    
    <input type='submit' name='sub' value='UPDATE'>
    
    </form>
    </body>
    </html>

    could some one please help.

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    does the space exist between the $we and ['hostelId'] ??

    PHP Code:
    $id $we ['hostelId']; 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2004
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A security tip : Put your password and username in a common file outside your htdocs, and the call it with an include or a require.

    Which error message do you get ?

    Webnology

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    uganda
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    update problem

    below is how i modified the upadate but it does not update at all.
    Code:
    <html>
    <head>
    <title> Hostel - Admin </title>
    </head>
    <body>
    <p align="center" > Editting - Hostel Details </p>
    <?php
    if ($jc=="edit") {
    
    $id = $_POST["id"];
    
    $con= mysql_connect('localhost','aashaba', 'aashaba');
    $dab= mysql_select_db('Hostel');
    
    $ql= mysql_query("select * from Hostel where hostelId=$id");
    
    while($we=mysql_fetch_array($ql)){
    
    $hon = $we['hostelName'];
    $loc = $we['locationId'];
    $hot = $we['hostelType'];
    $pad = $we['postalAddress'];
    $cap = $we['capacity'];
    $cust=$we['custodian'];
    $pho = $we['phone'];
    $mail = $we['email'];
    $rul = $we['rules'];
    $custnam=$we['custodianUser'];
    $custpas=$we['custodianPass'];
    
    }
    }
    ?>
    <form action='view1.php' method='post' name="update">
    Hostel Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='hostelName' value='<? echo $hon ?>' >*<br>
    location &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='locationId' value='<? echo $loc ?>' >*<br>
    hostelType&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='hostelType' value='<? echo $hot ?>' ><br>
    Postal Address&nbsp;&nbsp;&nbsp;<input type='text' name='postalAddress' value='<? echo $pad ?>' ><br>
    Capacity &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='capacity' value='<? echo $cap ?>' ><br>
    CUstodian &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='custodian' value='<? echo $cust ?>' ><br>
    Phone&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='phone' value='<? echo $pho ?>' ><br>
    Email&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='email' value='<? echo $mail ?>' ><br>
    Terms & Agreements<input type='text' name='rules' value='<? echo $rul ?>' ><br>
    Custodian Username <input type='text' name='custodianUser' value='<? echo $custnam ?>' ><br>
    Custodian Password<input type='text' name='custodianPass' value='<? echo $custpass?>' ><br>
    <br>
    <input type="submit" name="sub" value="UPDATE">
    
    Fields with * should not be edited. thank you.<br><br>
    </form>
    </body>
    </html>
    <?php
    
    global $id;
    
    echo $id;
    
    
    $post = $_POST["sub"];
    $a = $_POST ["postalAddress"]; 
    
    $b = $_POST ["capacity"]; 
    $c = $_POST ["custodian"]; 
    $d = $_POST ["phone"]; 
    $z = $_POST ["email"]; 
    $e = $_POST ["rules"]; 
    $f = $_POST ["custodianUser"]; 
    $g = $_POST ["custodianPass"]; 
    
    if($post="UPDATE")
    {
     $con= mysql_connect('localhost','aashaba', 'aashaba');
    $dab= mysql_select_db('Hostel');
    
    $sql = "UPDATE Hostel SET postalAddress='$a', capacity='$b', custodian='$c',phone='$d', email='$z', rules='$e', custodianUser='$f', custodianPass='$g' WHERE hostelId ='$id'";
    if ($result = mysql_query($sql))
    {
    	echo "Thank you! Information updated.\n";
    } else { echo mysql_error(); }
    
    }
    
    ?>
    could some one please help.
    Last edited by aashaba; Feb 11, 2005 at 00:08.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •