/    Sign up×
Community /Pin to ProfileBookmark

Adding Data Into A MySQL Table

Hi All,

I can easily pull data about my members using this page, not sure if you can see from the code but I also have textfields, in each column. I want to just be able to type in these and then click Submit/Update and the user get’s added… Anyone have any idea?

[code=php]<?php

/* connect to the mysql database and use different queries for the count of members */

include ‘library/config.php’;
include ‘library/opendb.php’;

//navigation
include(“nav.php”);

$info = mysql_query(“SELECT * FROM tbladministrators”);

echo ‘<table border=”1″ cellpadding=”3″ cellspacing=”1″>
<tr valign=”top”>
<td>First Name</td>
<td>Last Name</td>
<td>Username</td>
<td>Password</td>
<td>Super User</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr><tr valign=”top”>
<td><input type=”text” name=”firstname” /></td>
<td><input type=”text” name=”lastname” /></td>
<td><input type=”text” name=”username” /></td>
<td><input type=”text” name=”password” /></td>
<td><select name=”select”>
<option value=”0″>Yes</option>
<option value=”1″>No</option>
</select></td>
<td>&nbsp;</td>
<td>Insert</td>
</tr>’;

if (mysql_num_rows($info) < 1) {
echo ‘<tr valign=”top”>
<td colspan=”4″>There are no members that match the query. Please go back and try again</td>
</tr>’;
}

else {
while ($qry = mysql_fetch_array($info)) {

//create the layout
?>
<link href=”cs_style.css” rel=”stylesheet” type=”text/css” />

<tr valign=”top”>
<td><?php echo $qry[‘firstname’]; ?></td>
<td><?php echo $qry[‘lastname’]; ?></td>
<td><?php echo $qry[‘username’]; ?></td>
<td><?php echo $qry[‘password’]; ?></td>
<td><?php echo $qry[‘superuser’]; ?></td>
<td><a href=”showAdminEdit.php?record_id=<?php echo $qry[‘id’]; ?>”>Edit</a></td>
<td>Delete</td>
</tr>
<?php
}
}

echo ‘</table>’;

include ‘library/closedb.php’;

?>[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@tomyknokerauthorMar 31.2007 — I was able to build the query, just not sure where to add it to the page?

[code=php]
$query = "INSERT INTO tbladministrators (firstname, lastname, username, password, superuser) VALUES ($value1, $value2, $value3, $value4, $value5)";
mysql_query($query) or die('Error, insert query failed');

$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, insert query failed');
[/code]
×

Success!

Help @tomyknoker spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...