Best way to make table data editable?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ehauser
Forum Newbie
Posts: 6
Joined: Fri Sep 23, 2011 8:30 am

Best way to make table data editable?

Post by ehauser »

I have made a web page which is a grouping of three HTML tables that reads or writes different parts of an order (customer information, parts information, and price totals). I am trying to have the page pull data from a MySQL table so specific users can edit it. I am having trouble with this. I have tried to attach the code but no luck.

Is there anyway someone could please look at my code and point me in the right direction? Its a lot of code to post here but I am willing to get it on here if needed...

Thanks, Erik!
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Best way to make table data editable?

Post by Celauran »

I'm afraid you haven't given us much to work with. If you copy/paste your code here and give us specific examples of what isn't working, we'll be better able to help.
ehauser
Forum Newbie
Posts: 6
Joined: Fri Sep 23, 2011 8:30 am

Re: Best way to make table data editable?

Post by ehauser »

Sorry about that, I do realize that. The code is quite lengthy that's why I didn't post it, and it wouldn't allow me to upload it. I guess if I were to put into simpler terms, is there a base example of how I can have data show up in an html table?

I have copied over the PHP script i am using to pull the data from the mysql table. I have edited out some for length purposes...

<?php
$submittedby = $_GET["submittedby"];
$submittedtime = $_GET["submittedtime"];
$projectname = $_GET["projectname"];
...etc


// Connect to sqlbd port 3307

mysql_connect ('sqldb',user','pass') or die ('Error Connecting To Database Server, Please contact IT!');
mysql_select_db ('db_name');

// START THE QUERY

$query="UPDATE orderstest SET
(submittedby='$_GET[submittedby]',submittedtime='$_GET[submittedtime]',projectname='$_GET[projectname]'... etc)";

// RUN THE QUERY OR DISPLAY AN ERROR
mysql_query($query) or die ('Error Updating Orders Test Database || Return to <a href="mockup.php">Order Form</a>');

?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Best way to make table data editable?

Post by Celauran »

ehauser wrote:I guess if I were to put into simpler terms, is there a base example of how I can have data show up in an html table?
You mean something like this?

Code: Select all

<?php

$sql    = new mysqli(connection parameters here);

$query  = "SELECT foo, bar, baz FROM table WHERE whatever";
$result = $sql->query($query);

?>

<form>
    <table>
    <?php while ($row = $result->fetch_object()) { ?>
        <tr><td><input type="text" name="foo" value="<?php echo $row->foo; ?>" /></td></tr>
        <tr><td><input type="text" name="bar" value="<?php echo $row->bar; ?>" /></td></tr>
        <tr><td><input type="text" name="baz" value="<?php echo $row->baz; ?>" /></td></tr>
    <?php } ?>
        <tr><td><input type="submit" value="Submit" /></td></tr>
    </table>
</form>
or have I completely misunderstood you?
ehauser
Forum Newbie
Posts: 6
Joined: Fri Sep 23, 2011 8:30 am

Re: Best way to make table data editable?

Post by ehauser »

Yes, that is basically what I was looking for. As you can see, the code I had found and edited wasn't working correctly and I knew that was a simpler way to do it. I'll start out with what you had an edit it into what I am doing.

Thanks so much!
Post Reply