Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

displaying data in textbox from mysql db (PHP)

Options
  • 24-02-2008 3:52pm
    #1
    Closed Accounts Posts: 51 ✭✭


    hey
    im trying to pull data from a mysql database and display it in texboxes,

    here is the code sample:
    <?php
    $con = mysql_connect()
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    mysql_select_db("mydatabase", $con);
    mysql_query("UPDATE mytable SET availability  = '23 weeks'
    WHERE userid = '2'");
    $result = mysql_query("SELECT * FROM mytable");
    echo "<table border='1'>
    <tr>
    <th>Type</th>
    <th>Location</th>
    <th>Availability</th>
    <th>StarRating</th>
    <th>name</th>
    <th>email</th>
    <th>username</th>
    </tr>";
    while($row = mysql_fetch_array($result))
      {
     
      
    echo "<tr>";
      echo "<td>" . $row['type'] . "</td>";
      echo "<td>" . $row['location'] . "</td>";
      echo "<td>" . $row['availability'] . "</td>";
      echo "<td>" . $row['StarRating'] . "</td>";
     echo "<td>" . $row['name'] . "</td>";
      echo "<td>" . $row['email'] . "</td>";
     echo "<td>" . $row['username'] . "</td>";
      echo "</tr>";
      }
    
    mysql_close($con);
    ?>
    


    the above code works, but it displays teh data in a table, that is uneditable, i need to display the data in textboxes, or somethying that will allow edit them, and then save changes, i.e. updating the table.

    can someone PLEASE help me on this one, its killing me

    thanks :)


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh




  • Closed Accounts Posts: 51 ✭✭poissys




    thanks for that

    so it it just: <input type="text" name="fname" value="Mickey" />
    <br />
    <input type="text" name="fname" value="<php echo'$location'"?> />
    <br />


  • Registered Users Posts: 4,188 ✭✭✭pH


    The input fields will need to be part of a form and you'll need a submit button to send it back as well.

    http://www.w3schools.com/html/html_forms.asp


  • Closed Accounts Posts: 1,444 ✭✭✭Cantab.


    why don't you use <input> </input> tags?

    Give your <input> tags a unique name and id
    <input name='abc' id='abc'>
    <input name='def' id='def'>
    ...
    

    Now use javascript (embedded in PHP) to set your <input>'s value
    e.g.
    <?php
    $type=$row['type'];
    $location=$row['location'];
    
    echo "<script type='text/javascript'>document.getElementById('abc').value=$type;</script>";
    echo "<script type='text/javascript'>document.getElementById('def').value=$location;</script>";
    ...
    
    ?>
    


  • Closed Accounts Posts: 51 ✭✭poissys


    thanks for the help guys i got it to work!
    delighted
    but no i have a new problem there but now i need to update the table, and i have done everything neccesary for this to work, but im getting a: "Not Found

    The requested URL /pluralism/--WEBBOT-SELF-- was not found on this server."


    Here is the code:
    <form action="--WEBBOT-SELF--" method="POST">
                                                <!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
                                                <p>
    <input type="submit" name="submit" value="Update"></p>
                                            </form>
    

    i think/hope th error resides within that code sample there.
    i d really appreciate some help on this one
    thanks for the help, its been a great help

    on clicking the update button, which this webbot relates to , it loads to the error page very quickly so i hope that its just a case it cant find wat its looking for


  • Advertisement
  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Where the heck did the webbot stuff come from? What you want to do is pass the information to another PHP page that makes the appropriate changes on the database.


  • Closed Accounts Posts: 51 ✭✭poissys


    Where the heck did the webbot stuff come from? What you want to do is pass the information to another PHP page that makes the appropriate changes on the database.

    its just i used webbot method for something else and i was gonna reuse that technique.

    what do u recommend doing?


  • Registered Users Posts: 1,821 ✭✭✭Skud


    he means call another php page in the action, or else call it to self and check if the parameters are set. A googling of webot shows it's a frontpage extension??? so either make sure the extension is installed properly on the server or use php to do what frontpage is doing... i.e. linking to that php page instead of the frontpage webbot thing.


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    I see the code now, you never attached it to the email mate.

    Yes that is frontpage stuff, I remember that from years ago - so no you need to set that action to a php page! - No wonder it is going to /--WebBot-- . Simply change that to your PHP page.

    You should nearly be able to guess that since you've done pages like it before :)


Advertisement