Page 1 of 1

view records form database in text area, seleck.....

Posted: Fri Dec 19, 2008 3:12 am
by dourvas
hallo there,

i am trying to implement an admin page ro my sql db.

the easy task was the insert records which i have done it and it works fine.
Now i want to have a text area to show some of the records. later i want the end-user to be able to select from text area any record ena erase it.

i thouhgt of some code put nothinf seems to work. here what i wrote:
<?php

//Include database connection details
require_once('config.php');

//Array to store validation errors
$errmsg_arr = array();

//Validation error flag
$errflag = false;
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
mysql_query("set character set 'greek'",$link);
mysql_query("SET NAMES 'greek'",$link);

$get = mysql_query("SELECT * FROM members where class=1") or die("Mmm pie:" . mysql_error());

while ($row = mysql_fetch_row($get)) {

echo "<h4>Stuff you stored:</h4>\n";

echo '<form action="update.php" method="post">';

for ($number = 1; $number < 7; $number++)
{

echo '<textarea>' .$row[$number]. '</textarea>';
}

echo '<input type="submit" name="update" value="Update" /></form>';
}

?>
the text area shows the correct data. how do i impllement the delete function? any ideas? i want the end user to select from textarea and delete every record he wish

Re: view records form database in text area, seleck.....

Posted: Fri Dec 19, 2008 4:05 am
by papa
Change < to <.

Any perticual reason for doing that?

Re: view records form database in text area, seleck.....

Posted: Fri Dec 19, 2008 4:08 am
by dourvas
i ve already did that. it was a copy-paste error form another script i used. i changed my first post. please read it again. thanks....

Re: view records form database in text area, seleck.....

Posted: Fri Dec 19, 2008 4:11 am
by papa
Easiest solution would be to display each record in an input text field instead and have a checkbox next to it.

Re: view records form database in text area, seleck.....

Posted: Fri Dec 19, 2008 5:18 am
by dourvas
u are wright. of course.
so i started to implement this. i wrote this code

$get = mysql_query("SELECT * FROM members where class=1") or die("Mmm pie:" . mysql_error());

while ($row = mysql_fetch_row($get)) {

$member = mysql_fetch_assoc($get);

$id=$member['member_id'];
$lastname=$member['lastname'];
$firstname=$member['firstname'];
$class=$member['class'];
$login=$member['login'];
$password=$member['passwd'];

//echo $id," ",$lastname," ", $firstname," ",$class," ",$login," ",$password; it works!!
echo "<h4>ÏÉ ÊÁÈÇÃÇÔÅÓ:</h4>\n";

echo '<form action="update.php" method="post">';


echo '<input type="text" name="txtbox" value=.$id," ",.$lastname," ", .$firstname," ",.$class," ",.$login," ",.$password> ';

echo '<input type="checkbox" name="deletecheck">';
echo '<input type="submit" name="delete" value="DELETE CHECKED"></form>';
}

?>

i can not put the data into the txtbox.
i also would appreciate if u could give an idea about the deletechecked.php.
i would appreciate another one advice.......

Re: view records form database in text area, seleck.....

Posted: Fri Dec 19, 2008 5:44 am
by papa
I'm just guessing here so you need to try:


echo '<input type="checkbox" name="deletecheck[]" value=$id>';

Also, your form should be outside the loop.

Tick a few checkboxex and then on update.php you can then print_r($_POST['deletecheck']); to see if you array is passed.

Re: view records form database in text area, seleck.....

Posted: Fri Dec 19, 2008 5:54 am
by dourvas
ok i ll try that.
just tell me how to parse the data into the txbox.
this line does not work...

echo '<input type="text" name="txtbox" value=.$id," ",.$lastname," ", .$firstname," ",.$class," ",.$login," ",.$password> ';

Re: view records form database in text area, seleck.....

Posted: Fri Dec 19, 2008 6:04 am
by papa
echo '<input type="text" name="txtbox" value="$id, $lastname, $firstname, $class, $login, $password" /> ';

Re: view records form database in text area, seleck.....

Posted: Mon Dec 22, 2008 1:13 am
by dourvas
i am afraid this line does not work either
the line
echo $id," ",$lastname," ", $firstname," ",$class," ",$login," ",$password;
works fine. the variables all have data inside.
now i want to insert that data into textbox. i ve tried a lot of solutions i thought, but it always finally i see the variables as they are and not what they contain..

code

$get = mysql_query("SELECT * FROM members where class=1") or die("Mmm pie:" . mysql_error());

while ($row = mysql_fetch_row($get)) {

$member = mysql_fetch_assoc($get);

$id=$member['member_id'];
$lastname=$member['lastname'];
$firstname=$member['firstname'];
$class=$member['class'];
$login=$member['login'];
$password=$member['passwd'];

echo $id," ",$lastname," ", $firstname," ",$class," ",$login," ",$password;
echo "<h4>title:</h4>\n";

echo '<form action="update.php" method="post">';

echo '<input type="text" name="txtbox" value=" <?php echo ($id, $lastname, $firstname, $class, $login, $password) ?>"/>';

echo '<input type="checkbox" name="deletecheck">';
echo '<input type="submit" name="delete" value="DELETE CHECKED"></form>';
}

?>

Re: view records form database in text area, seleck.....

Posted: Mon Dec 22, 2008 1:20 am
by dourvas
found it sorry

echo "<input type='text' name='txtbox' value=' $id, $lastname, $firstname, $class, $login, $password) ' />";

had to change double quotes with quotes and vise versa