Having problem with update process.

Discussion in 'PHP' started by vianca12, Jun 12, 2012.

  1. #1
    My coding for update process was unable to retrieve records from database. I really need help for this coding.

    ---This in interface page----
    <?php
    if(isset($_GET['A_id']))
    {
    include("dbconn.php");

    $A_id=" ";

    if (isset($_SESSION['A_id']))

    $A_id = $_GET['A_id'];
    $sql = "SELECT *
    FROM advisor
    WHERE A_id = $A_id";

    $query = mysql_query($sql) or die("MySQL Error: " . mysql_error());
    $row = mysql_num_rows($query);
    if($row != 0){
    $data = mysql_fetch_assoc($query);


    ?>
    <form name="form1" method="post" action="uitm_processUpdate.php">
    <table width="550" border="1">


    <tr>
    <td width="131">IC Number<input name="A_id" type="text" value="<?php echo $data['A_id']; ?>" /> </td>

    <td width="403">Username<input name="username" type="text" id="username" maxlength="10"
    value="<?php echo $data['username']; ?>" /></td>
    </tr>

    <tr>
    <td>Password </td>
    <td><input name="password" type="password" id="password" maxlength="10" value="<?php echo $data['password']; ?>" /></td>
    </tr>

    <tr>
    <td>Title </td>
    <td><input name="A_title" type="text" id="A_title" value="<?php echo $data['A_title']; ?>" /></td>
    </tr>

    <tr>
    <td>First Name </td>
    <td><input name="A_fname" type="text" id="A_fname" value="<?php echo $data['A_fname']; ?>" /></td>
    </tr>

    <tr>
    <td>Last Name </td>
    <td><input name="A_lname" type="text" id="A_lname" value="<?php echo $data['A_lname']; ?>" /></td>
    </tr>


    <tr>
    <td>Gender </td>
    <td><input name="A_gender" type="text" id="A_gender" value="<?php echo $data['A_gender']; ?>" /></td>
    </tr>

    <tr>
    <td>Address </td>
    <td><input name="A_address" type="text" id="A_address" value="<?php echo $data['A_address']; ?>" /></td>
    </tr>

    <tr>
    <td>State </td>
    <td><input name="A_state" type="text" id="A_state" value="<?php echo $data['A_state']; ?>" /></td>
    </tr>

    <tr>
    <td>Country </td>
    <td><input name="A_country" type="text" id="A_country" value="<?php echo $data['A_country']; ?>" /></td>
    </tr>

    <tr>
    <td>Institution </td>
    <td><input name="A_institution" type="text" id="A_institution" value="<?php echo $data['A_institution']; ?>" /></td>
    </tr>

    <tr>
    <td>Job Title </td>
    <td><input name="A_job" type="text" id="A_job" value="<?php echo $data['A_job']; ?>" /></td>
    </tr>

    <tr>
    <td>Email</td>
    <td><input name="A_email" type="text" id="A_email" value="<?php echo $data['A_email']; ?>" /></td>
    </tr>

    <tr>
    <td>Mobile Number</td>
    <td><input name="A_mobileNum" type="text" id="A_mobileNum" value="<?php echo $data['A_mobileNum']; ?>" /></td>
    </tr>




    <tr>
    <td><input type="submit" name="Submit" value="Submit" /></td>
    <td>&nbsp;</td>
    </tr>
    </table>
    </form>
    <?php
    }
    else{
    echo "Student does not exists.";
    }
    }
    ?>
    </body>
    </html>

    --This is process page---

    <?php
    include("dbconn.php");


    function updateIntoAdvisor($A_id, $username, $password, $A_title, $A_fname, $A_lname, $A_gender, $A_address, $A_state, $A_country, $A_institution, $A_job, $A_email, $A_mobileNum)
    {
    $sql = "UPDATE advisor SET
    A_id='".$A_id."';
    username = '".$username."',
    password= '".$password."',
    A_title = '".$A_title."',
    A_fname = '".$A_fname."',
    A_lname = '".$A_lname."',
    A_gender = '".$A_gender."',
    A_address = '".$A_address."',
    A_state = '".$A_state."',
    A_country = '".$A_country."',
    A_institution = '".$A_institution."',
    A_job = '".$A_job."',
    A_email = '".$A_email."',
    A_mobileNum = '".$A_mobileNum."',

    WHERE A_id = $A_id";
    //echo $sql;
    mysql_query($sql) or die("Error: " . mysql_error());
    }


    if(isset($_POST['Submit'])){


    $A_id= $_POST['A_id'] : '';
    $username = $_POST['username'] : '';
    $password = $_POST['password'] : '';
    $A_title = $_POST['A_title'] : '';
    $A_fname = $_POST['A_fname'] : '';
    $A_lname = $_POST['A_lname'] : '';
    $A_gender = $_POST['A_gender'] : '';
    $A_address= $_POST['A_address'] : '';
    $A_state = $_POST['A_state'] : '';
    $A_country = $_POST['A_country'] : '';
    $A_institution = $_POST['A_institution'] : '';
    $A_job = $_POST['A_job'] : '';
    $A_email = $_POST['A_email'] : '';
    $A_mobileNum = $_POST['A_mobileNum'] : '';


    else{
    updateIntoAdvisor($A_id, $username, $password, $A_title, $A_fname, $A_lname, $A_gender, $A_address, $A_state, $A_country, $A_institution, $A_job, $A_email, $A_mobileNum);

    echo "Student information has been successfully updated.";
    echo "<br /><br /><a href='index2.php'>Back to Index</a>";
    }
    }
    ?>
    ________________________________________________________________________________________________
    Can someone please tell me what is the wrong with the coding .Please
     
    vianca12, Jun 12, 2012 IP
  2. kids

    kids Active Member

    Messages:
    411
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    68
    #2
    Oh my God, can you place it into <code>
     
    kids, Jun 12, 2012 IP
  3. dujmovicv

    dujmovicv Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    4
    Trophy Points:
    48
    #3
    Have you tried to echo the variable $A_id to see if it was set properly?
    Also, in your queries try to put the variable between quot marks :

    [COLOR=#111111]WHERE A_id = '$A_id'
    Code (markup):
    [/COLOR]
     
    dujmovicv, Jun 12, 2012 IP
  4. vianca12

    vianca12 Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sorry,I'm new here.How to place it into code?
     
    vianca12, Jun 12, 2012 IP
  5. vianca12

    vianca12 Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I tried but still not working.
    The webpage does not display anything when i run the coding
     
    vianca12, Jun 12, 2012 IP
  6. dujmovicv

    dujmovicv Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    4
    Trophy Points:
    48
    #6
    type "[ code ]" at the begining of the code and "[ /code ]" at the end (without quotation marks and blank space).
     
    dujmovicv, Jun 12, 2012 IP
  7. vianca12

    vianca12 Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    
    [COLOR=#111111]<?php[/COLOR]
    [COLOR=#111111]if(isset($_GET['A_id']))[/COLOR]
    [COLOR=#111111]{[/COLOR]
    [COLOR=#111111]include("dbconn.php");[/COLOR]
    
    [COLOR=#111111]$A_id=" ";[/COLOR]
    
    [COLOR=#111111]if (isset($_SESSION['A_id'])) [/COLOR]
    
    [COLOR=#111111]$A_id = $_GET['A_id'];[/COLOR]
    [COLOR=#111111]$sql = "SELECT * [/COLOR]
    [COLOR=#111111]FROM advisor[/COLOR]
    [COLOR=#111111]WHERE A_id = $A_id";[/COLOR]
    
    [COLOR=#111111]$query = mysql_query($sql) or die("MySQL Error: " . mysql_error());[/COLOR]
    [COLOR=#111111]$row = mysql_num_rows($query);[/COLOR]
    [COLOR=#111111]if($row != 0){[/COLOR]
    [COLOR=#111111]$data = mysql_fetch_assoc($query);[/COLOR]
    
    
    [COLOR=#111111]?>[/COLOR]
    [COLOR=#111111]<form name="form1" method="post" action="uitm_processUpdate.php">[/COLOR]
    [COLOR=#111111]<table width="550" border="1">[/COLOR]
    
    
    [COLOR=#111111]<tr>[/COLOR]
    [COLOR=#111111]<td width="131">IC Number<input name="A_id" type="text" value="<?php echo $data['A_id']; ?>" /> </td>[/COLOR]
    
    [COLOR=#111111]<td width="403">Username<input name="username" type="text" id="username" maxlength="10" [/COLOR]
    [COLOR=#111111]value="<?php echo $data['username']; ?>" /></td>[/COLOR]
    [COLOR=#111111]</tr>[/COLOR]
    
    [COLOR=#111111]<tr>[/COLOR]
    [COLOR=#111111]<td>Password </td>[/COLOR]
    [COLOR=#111111]<td><input name="password" type="password" id="password" maxlength="10" value="<?php echo $data['password']; ?>" /></td>[/COLOR]
    [COLOR=#111111]</tr>[/COLOR]
    
    [COLOR=#111111]<tr>[/COLOR]
    [COLOR=#111111]<td>Title </td>[/COLOR]
    [COLOR=#111111]<td><input name="A_title" type="text" id="A_title" value="<?php echo $data['A_title']; ?>" /></td>[/COLOR]
    [COLOR=#111111]</tr>[/COLOR]
    
    [COLOR=#111111]<tr>[/COLOR]
    [COLOR=#111111]<td>First Name </td>[/COLOR]
    [COLOR=#111111]<td><input name="A_fname" type="text" id="A_fname" value="<?php echo $data['A_fname']; ?>" /></td>[/COLOR]
    [COLOR=#111111]</tr>[/COLOR]
    
    [COLOR=#111111]<tr>[/COLOR]
    [COLOR=#111111]<td>Last Name </td>[/COLOR]
    [COLOR=#111111]<td><input name="A_lname" type="text" id="A_lname" value="<?php echo $data['A_lname']; ?>" /></td>[/COLOR]
    [COLOR=#111111]</tr>[/COLOR]
    
    
    [COLOR=#111111]<tr>[/COLOR]
    [COLOR=#111111]<td>Gender </td>[/COLOR]
    [COLOR=#111111]<td><input name="A_gender" type="text" id="A_gender" value="<?php echo $data['A_gender']; ?>" /></td>[/COLOR]
    [COLOR=#111111]</tr>[/COLOR]
    
    [COLOR=#111111]<tr>[/COLOR]
    [COLOR=#111111]<td>Address </td>[/COLOR]
    [COLOR=#111111]<td><input name="A_address" type="text" id="A_address" value="<?php echo $data['A_address']; ?>" /></td>[/COLOR]
    [COLOR=#111111]</tr>[/COLOR]
    
    [COLOR=#111111]<tr>[/COLOR]
    [COLOR=#111111]<td>State </td>[/COLOR]
    [COLOR=#111111]<td><input name="A_state" type="text" id="A_state" value="<?php echo $data['A_state']; ?>" /></td>[/COLOR]
    [COLOR=#111111]</tr>[/COLOR]
    
    [COLOR=#111111]<tr>[/COLOR]
    [COLOR=#111111]<td>Country </td>[/COLOR]
    [COLOR=#111111]<td><input name="A_country" type="text" id="A_country" value="<?php echo $data['A_country']; ?>" /></td>[/COLOR]
    [COLOR=#111111]</tr>[/COLOR]
    
    [COLOR=#111111]<tr>[/COLOR]
    [COLOR=#111111]<td>Institution </td>[/COLOR]
    [COLOR=#111111]<td><input name="A_institution" type="text" id="A_institution" value="<?php echo $data['A_institution']; ?>" /></td>[/COLOR]
    [COLOR=#111111]</tr>[/COLOR]
    
    [COLOR=#111111]<tr>[/COLOR]
    [COLOR=#111111]<td>Job Title </td>[/COLOR]
    [COLOR=#111111]<td><input name="A_job" type="text" id="A_job" value="<?php echo $data['A_job']; ?>" /></td>[/COLOR]
    [COLOR=#111111]</tr>[/COLOR]
    
    [COLOR=#111111]<tr>[/COLOR]
    [COLOR=#111111]<td>Email</td>[/COLOR]
    [COLOR=#111111]<td><input name="A_email" type="text" id="A_email" value="<?php echo $data['A_email']; ?>" /></td>[/COLOR]
    [COLOR=#111111]</tr>[/COLOR]
    
    [COLOR=#111111]<tr>[/COLOR]
    [COLOR=#111111]<td>Mobile Number</td>[/COLOR]
    [COLOR=#111111]<td><input name="A_mobileNum" type="text" id="A_mobileNum" value="<?php echo $data['A_mobileNum']; ?>" /></td>[/COLOR]
    [COLOR=#111111]</tr>[/COLOR]
    
    
    
    
    [COLOR=#111111]<tr>[/COLOR]
    [COLOR=#111111]<td><input type="submit" name="Submit" value="Submit" /></td>[/COLOR]
    [COLOR=#111111]<td>&nbsp;</td>[/COLOR]
    [COLOR=#111111]</tr>[/COLOR]
    [COLOR=#111111]</table>[/COLOR]
    [COLOR=#111111]</form>[/COLOR]
    [COLOR=#111111]<?php[/COLOR]
    [COLOR=#111111]}[/COLOR]
    [COLOR=#111111]else{[/COLOR]
    [COLOR=#111111]echo "Student does not exists.";[/COLOR]
    [COLOR=#111111]}[/COLOR]
    [COLOR=#111111]}[/COLOR]
    [COLOR=#111111]?>[/COLOR]
    [COLOR=#111111]</body>[/COLOR]
    [COLOR=#111111]</html>[/COLOR]
    
    [COLOR=#111111]--This is process page---[/COLOR]
    
    [COLOR=#111111]<?php[/COLOR]
    [COLOR=#111111]include("dbconn.php");[/COLOR]
    
    
    [COLOR=#111111]function updateIntoAdvisor($A_id, $username, $password, $A_title, $A_fname, $A_lname, $A_gender, $A_address, $A_state, $A_country, $A_institution, $A_job, $A_email, $A_mobileNum)[/COLOR]
    [COLOR=#111111]{[/COLOR]
    [COLOR=#111111]$sql = "UPDATE advisor SET[/COLOR]
    [COLOR=#111111]A_id='".$A_id."';[/COLOR]
    [COLOR=#111111]username = '".$username."',[/COLOR]
    [COLOR=#111111]password= '".$password."',[/COLOR]
    [COLOR=#111111]A_title = '".$A_title."',[/COLOR]
    [COLOR=#111111]A_fname = '".$A_fname."',[/COLOR]
    [COLOR=#111111]A_lname = '".$A_lname."',[/COLOR]
    [COLOR=#111111]A_gender = '".$A_gender."',[/COLOR]
    [COLOR=#111111]A_address = '".$A_address."',[/COLOR]
    [COLOR=#111111]A_state = '".$A_state."',[/COLOR]
    [COLOR=#111111]A_country = '".$A_country."',[/COLOR]
    [COLOR=#111111]A_institution = '".$A_institution."',[/COLOR]
    [COLOR=#111111]A_job = '".$A_job."',[/COLOR]
    [COLOR=#111111]A_email = '".$A_email."',[/COLOR]
    [COLOR=#111111]A_mobileNum = '".$A_mobileNum."',[/COLOR]
    
    [COLOR=#111111]WHERE A_id = $A_id";[/COLOR]
    [COLOR=#111111]//echo $sql;[/COLOR]
    [COLOR=#111111]mysql_query($sql) or die("Error: " . mysql_error());[/COLOR]
    [COLOR=#111111]}[/COLOR]
    
    
    [COLOR=#111111]if(isset($_POST['Submit'])){[/COLOR]
    
    
    [COLOR=#111111]$A_id= $_POST['A_id'] : '';[/COLOR]
    [COLOR=#111111]$username = $_POST['username'] : '';[/COLOR]
    [COLOR=#111111]$password = $_POST['password'] : '';[/COLOR]
    [COLOR=#111111]$A_title = $_POST['A_title'] : '';[/COLOR]
    [COLOR=#111111]$A_fname = $_POST['A_fname'] : '';[/COLOR]
    [COLOR=#111111]$A_lname = $_POST['A_lname'] : '';[/COLOR]
    [COLOR=#111111]$A_gender = $_POST['A_gender'] : '';[/COLOR]
    [COLOR=#111111]$A_address= $_POST['A_address'] : '';[/COLOR]
    [COLOR=#111111]$A_state = $_POST['A_state'] : '';[/COLOR]
    [COLOR=#111111]$A_country = $_POST['A_country'] : '';[/COLOR]
    [COLOR=#111111]$A_institution = $_POST['A_institution'] : '';[/COLOR]
    [COLOR=#111111]$A_job = $_POST['A_job'] : '';[/COLOR]
    [COLOR=#111111]$A_email = $_POST['A_email'] : '';[/COLOR]
    [COLOR=#111111]$A_mobileNum = $_POST['A_mobileNum'] : '';[/COLOR]
    
    
    [COLOR=#111111]else{[/COLOR]
    [COLOR=#111111]updateIntoAdvisor($A_id, $username, $password, $A_title, $A_fname, $A_lname, $A_gender, $A_address, $A_state, $A_country, $A_institution, $A_job, $A_email, $A_mobileNum);[/COLOR]
    
    [COLOR=#111111]echo "Student information has been successfully updated.";[/COLOR]
    [COLOR=#111111]echo "<br /><br /><a href='index2.php'>Back to Index</a>";[/COLOR]
    [COLOR=#111111]}[/COLOR]
    [COLOR=#111111]}[/COLOR]
    [COLOR=#111111]?>
    
    Code (markup):
    [/COLOR]
     
    vianca12, Jun 12, 2012 IP
  8. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #8
    One big mess of unstructured non-formatted code...
     
    NetStar, Jun 13, 2012 IP
  9. vianca12

    vianca12 Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Can you help me to fix the mess?
     
    vianca12, Jun 13, 2012 IP
  10. Custom IDX/MLS

    Custom IDX/MLS Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Just remove if (isset($_SESSION['A_id'])) line
    ...
    oh and why're you updating the ID in A_id='".$A_id."'; ?
     
    Last edited: Jun 13, 2012
    Custom IDX/MLS, Jun 13, 2012 IP
  11. vianca12

    vianca12 Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I tried to remove if (isset($_SESSION['A_id'])) but the page does not display anything.Just blank.
    I also already remove
    A_id='".$A_id."'; ,because before this I thought I need to update that ID
     
    vianca12, Jun 13, 2012 IP
  12. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #12
    Use FirePHP. Throw your variables at evewry line, so you can see what the program is doing line by line. Try to find where it's not doing what you ex[ect. Even if you can't figure out why, you can post the line above the problem and the problem line, rather than the whole program. Guessing where it's not working, and what it's doing, is orders of magnitude more difficult for us than figuring out why $x is 1 instead of 2.
     
    Rukbat, Jun 15, 2012 IP