Ask Experts Questions for FREE Help !
Ask
    leenakrishna's Avatar
    leenakrishna Posts: 4, Reputation: 1
    New Member
     
    #1

    Jan 1, 2009, 11:40 PM
    Update in PHP
    This is my code.Please tell me how to update it.How can I get values individually so that I can update my database.please help me...

    <?php
    $con = mysql_connect("localhost","root","");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("hai", $con);

    $sql = "SELECT FirstName,LastName,Age FROM persons where Age='12'";

    $result = @mysql_query($sql, $con) or die("Cannot execute query.". mysql_error());
    $numrow = mysql_num_rows($result);
    if ($numrow != 0)
    {
    // fetch each record in result set
    for ($counter == 0; $row = mysql_fetch_row($result); $counter++)
    {
    // build table to display result
    print ("<form action='pp1.php' method='post'><h2><center>Member Profile</center></h2>");
    print ("<table border = '1' cellpadding = '3' cellspacing = '2' style = 'background-color: #ADD8E6'>");
    print ("<tr>");
    print ("<th>Firstname</th>");
    print ("<th>Lastname</th>");
    print ("</tr>");
    print ("<tr>");

    foreach ($row as $key => $value)
    print ("<td><input type ='text' value='$value' size = '30'></td>");

    print ("</tr>");
    print ("</table>");
    }
    }


    print ("<table>");
    print ("<tr>");
    print ("<td>&nbsp;</td>");
    print ("<td width='4%'>&nbsp;</td>");
    print ("<td></tr>");

    print ("<tr>");
    print ("<td>&nbsp;</td>");
    print ("<td width='4%'>&nbsp;</td>");

    print ("<td><input type='submit' name='submit' value='Upgrade'></td>");
    print ("</table></form>");



    mysql_close($con);




    ?>
    yesbeckjs's Avatar
    yesbeckjs Posts: 20, Reputation: 3
    New Member
     
    #2

    Sep 13, 2010, 02:35 PM
    I don't see an insert/update statement. If you did this by mistake, try including it and maybe I can assist you further.
    rlerne's Avatar
    rlerne Posts: 10, Reputation: 1
    New Member
     
    #3

    Oct 22, 2011, 10:56 PM
    First things first, I had to update your code. It was kind of hard to read.

    Secondly, I'd need more information on the table (are there any IDs available)... If you can provide that, I can show you how to make it update the names.


    And just for your learning pleasure, here's the cleaned up script. P.S. You don't need to select the age column when you provide the value in the query :P


    &lt;?php
    $con = mysql_connect("localhost","root","");
    If (!$con)
    &nbsp;&nbsp;&nbsp;&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;die('Could not connect: ' . Mysql_error());
    &nbsp;&nbsp;&nbsp;&nbsp;}
    mysql_select_db("hai", $con);
    ?&gt;

    &nbsp;&nbsp;&nbsp;&nbsp;&lt;form action='pp1.php' method='post'&gt;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&l t;h2 align='center'&gt;Member Profile&lt;/h2&gt;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&l t;table border='1' cellpadding='3' cellspacing='2' style='background-color: #add8e6'&gt;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt; th&gt;First Name&lt;/th&gt;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt; th&gt;Last Name&lt;/th&gt;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;
    &lt;?PHP
    $query = mysql_query("SELECT FirstName,LastName FROM persons where Age=12") or die("Cannot execute query." . mysql_error());
    while ($row = mysql_fetch_assoc($query))
    &nbsp;&nbsp;&nbsp;&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;echo "
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt; td&gt;&lt;input type='text' value='{$row['FirstName']}' size='30' name='FirstName' /&gt;&lt;/td&gt;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt; td&gt;&lt;input type='text' value='{$row['LastName']}' size='30' name='LastName' /&gt;&lt;/td&gt;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;";
    &nbsp;&nbsp;&nbsp;&nbsp;}
    ?&gt;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&l t;/table&gt;
    &nbsp;&nbsp;&nbsp;&nbsp;&lt;/form&gt;

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

How to update AVG antivirus Update to computer,which is not connect with internet [ 2 Answers ]

Hello, Computer (No.A) is connected with internet. So I can get the update automatically. But, Computer (No.B, and No.C ) is not connect with internet. But we use the flash Drive and 3 1/2 Floppy disk. Without antivirus software, No.B & C can get the virus. Already having the antivirus software...

Ok update [ 1 Answers ]

Well since I last posted I went to the docs had a pap and she was pushing on stomach I have to go in on Monday to have a internal ultra sound But now I'm spotting brown since last night but its more brown since last night

Update [ 13 Answers ]

I just got home from the dr appointment. I was schedualed to see a nurse practitioner, but they had me see my dr who was in the office anyway. He said everything is normal... lol... I'm so relieved. The reason he gave for the discharge was because of double the hormones. The contractions are normal...


View more questions Search