Need some help using checkbox and select query.

Hi, I’ve been working on these php code for three days now and I can’t seem to figure out how to make it work. Ok so what I want to do is to check a checkbox, when I check a checkbox it should display the value of the checkbox to the other page, So far I’ve managed to display the first value, but if I check the second check box or other, It sayd that the index is undefined. I’ve been stopped on my tracks because of this. Can anyone give me some idea or help on how to make it work? Thanks in advance!

[code][php]/DISPLAY DATABASE ITEM/

$result = mysql_query(“SELECT * FROM t_board ORDER BY registerTime DESC LIMIT $offset, $rowsperpage”)
or die("Error processing query. ".mysql_error());

while($row = mysql_fetch_object($result))
{
echo"";

echo “”;

echo “

”;
echo “”.$row->index."";

echo "

"
."".$row->subject." ";
echo “”.$row->writer."";
echo “”.$row->registerTime."";
echo “”;

echo “”;
}[/php][/code]

and the other code where the form is called is:

[code][php]$con = mysql_connect(“localhost”,“root”,“asa123”);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

mysql_select_db(“bbs”,$con);

$result = mysql_query(“SELECT index FROM t_board”);

mysql_close($con);

echo "Index received: ".$_POST[‘id’];
[/php][/code]

I’ll really appreciate your help!

The reason your getting " index is undefined " is because $_POST[‘id’] isn’t being set. If its not selected, its not sent. So [‘id’] is undefined.

If you have only a set number of checkbox’s you can assign each checkbox its own name and value.

<input type='checkbox' name='id' value='".$row->index."' /> <input type='checkbox' name='other' value='".$row->index."' />

Then in your other code.
[php]if(isset($_POST[‘id’])){ echo "Index received: ".$_POST[‘id’]; }
if(isset($_POST[‘other’])){ echo "Index received: ".$_POST[‘other’]; }[/php]

If you have a dynamic amount of checkbox’s you need to build an array.

I hope this is what you mean.

Thanks for the reply, but yeah I have a dynamic amount of checkbox, I’ve included the

<input type='checkbox' name='id' value='".$row->index."' />

inside the while loop, so every time I add a new data in the database, it will have a checkbox when I print it.

I tried to change the value to $row-writer to get the writer name insted of the index, so far I’ve managed to print it right with the first checkbox but if I check the other checkbox I got the same error.

<input type='checkbox' name='id[]' value='".$row->index."' />

Then when processing the forms.

[php]if(is_array($_POST[‘id’])) foreach($_POST[‘id’] as $value){
echo "Index received: ".$value;
}[/php]

I was able to get the value of the checkbox using this code, but if I try to check the other checkbox I get an undefined index error… I don’t know why… Here’s the whole code.

[php]

Simplexi Board

Board List

<?php $con = mysql_connect("localhost","root","asa123"); if (!$con) { die('Could not connect: ' . mysql_error()); } /******** PAGING *******/ mysql_select_db("bbs",$con); $sql = "SELECT COUNT(*) FROM t_board"; $result2 = mysql_query($sql, $con) or die(mysql_error()); $r = mysql_fetch_row($result2); $numrows = $r[0]; $rowsperpage = 10; $totalpages = ceil($numrows / $rowsperpage); if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { $currentpage = (int) $_GET['currentpage']; } else { $currentpage = 1; } if ($currentpage > $totalpages) { $currentpage = $totalpages; } if ($currentpage < 1) { $currentpage = 1; } $offset = ($currentpage - 1) * $rowsperpage; /*****END OF PAGING PART 1***/ /***** DATABASE ITEM IN TABLE *****/ echo ""; /**COUNT TOTAL POST**/ $count = "SELECT registerTime, COUNT(writer) FROM t_board"; $result1= mysql_query($count) or die(mysql_error()); while($row1=mysql_fetch_array($result1)) { echo "Today / Total ".$row1['COUNT(writer)']; } /**DISPLAY DATABASE ITEM**/ $result = mysql_query("SELECT * FROM t_board ORDER BY registerTime DESC LIMIT $offset, $rowsperpage") or die("Error processing query. ".mysql_error()); while($row = mysql_fetch_object($result)) { echo""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
No Subject Writer Date
".$row->index." " ."".$row->subject." ".$row->writer."".$row->registerTime."
"; if ($currentpage > 1) { echo " << "; $prevpage = $currentpage - 1; echo " Prev "; } $range = 3; for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { if (($x > 0) && ($x <= $totalpages)) { if ($x == $currentpage) { echo " [$x] "; } else { echo " $x "; } } } if ($currentpage != $totalpages) { $nextpage = $currentpage + 1; echo " next "; echo " >> "; } mysql_close($con); ?>
[/php]

and the other part is where I process the form

[php]

Simplexi Board

Board View

<?php //echo "Index received: ".$_POST['id']; $con = mysql_connect("localhost","root","asa123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("bbs",$con); $query = "SELECT * FROM t_board WHERE writer = '".mysql_real_escape_string($_POST['id'])."'"; $result = mysql_query($query) or die("Error processing query. ".mysql_error()); $row = mysql_fetch_object($result); echo ""; echo "".""; echo "".""; echo "".""; echo "".""; echo "
Writer ".$row->writer."
Subject ".$row->subject."
Message ".$row->message."
File "."
"; mysql_close($con); ?>


[/php]

You are creating a new form with each entry , if you are wanting to do this just ignore me here.
[php]while($row = mysql_fetch_object($result))
{
echo"";

echo “”;

echo “

”;
echo “”.$row->index."";

echo "

"
."".$row->subject." ";
echo “”.$row->writer."";
echo “”.$row->registerTime."";
echo “”;

echo “”;
}[/php]

Would it not be better to just do the while with the checkbox’s?
[php]while($row = mysql_fetch_object($result))
{
echo “

”;
echo “”.$row->index."";

echo "

"
."".$row->subject." ";
echo “”.$row->writer."";
echo “”.$row->registerTime."";
echo “”;
}[/php]

Are you only wanting people to be able to select one checkbox at a time??
In that case. You can just name each field " id "

I’m guessing this is your undefined index.
[php]writer = ‘".mysql_real_escape_string($_POST[‘id’])."’";[/php]

[php]<?
if(is_array($_POST[‘id’])) foreach($_POST[‘id’] as $value){
//echo "Index received: ".$_POST[‘id’];

$con = mysql_connect(“localhost”,“root”,“asa123”);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

mysql_select_db(“bbs”,$con);

$query = “SELECT * FROM t_board WHERE
writer = '”.mysql_real_escape_string($value)."’";
$result = mysql_query($query) or die("Error processing query. ".mysql_error());
$row = mysql_fetch_object($result);

echo “

”;
echo "“.”“;
echo "“.”“;
echo "“.”“;
echo "“.”";
echo “
Writer ".$row->writer."
Subject ”.$row->subject."
Message ”.$row->message."
File ”."
”;

mysql_close($con);
}

?>[/php]

I’m getting whinged at while doing this, so could be wrong.

[php]while($row = mysql_fetch_object($result))
{
echo “

”;
echo “”.$row->index."";

echo "

"
."".$row->subject." ";
echo “”.$row->writer."";
echo “”.$row->registerTime."";
echo “”;
}[/php]

I used this along with this code that you gave me

[php]<?
if(is_array($_POST[‘id’])) foreach($_POST[‘id’] as $value){
//echo "Index received: ".$_POST[‘id’];

$con = mysql_connect(“localhost”,“root”,“asa123”);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

mysql_select_db(“bbs”,$con);

$query = “SELECT * FROM t_board WHERE
writer = '”.mysql_real_escape_string($value)."’";
$result = mysql_query($query) or die("Error processing query. ".mysql_error());
$row = mysql_fetch_object($result);

echo “

”;
echo "“.”“;
echo "“.”“;
echo "“.”“;
echo "“.”";
echo “
Writer ".$row->writer."
Subject ”.$row->subject."
Message ”.$row->message."
File ”."
”;

mysql_close($con);
}

?>[/php]

Thank you for the effort lothop I really appreciate this but I still get the index undefined error. :C

Change <? to <?php, I also re-arranged the loop.

[php]<?php

//echo "Index received: ".$_POST[‘id’];

$con = mysql_connect(“localhost”,“root”,“asa123”);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

mysql_select_db(“bbs”,$con);

if(is_array($_POST[‘id’])) foreach($_POST[‘id’] as $value){

$query = “SELECT * FROM t_board WHERE writer = '”.mysql_real_escape_string($value)."’";
$result = mysql_query($query) or die("Error processing query. ".mysql_error());
$row = mysql_fetch_object($result);

echo “

”;
echo "“.”“;
echo "“.”“;
echo "“.”“;
echo "“.”";
echo “
Writer ".$row->writer."
Subject ”.$row->subject."
Message ”.$row->message."
File ”."
”;
}

mysql_close($con);

?>[/php]

It’s working for the first checkbox, but if I check the second checkbox it says Index Undefined,

This is what I did, First I changed id to id[]

[php]echo "

"[/php]

then I used this code for my view.php

[php]<?php

//echo "Index received: ".$_POST[‘id’];

$con = mysql_connect(“localhost”,“root”,“asa123”);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

mysql_select_db(“bbs”,$con);

if(is_array($_POST[‘id’])) foreach($_POST[‘id’] as $value){

$query = “SELECT * FROM t_board WHERE writer = '”.mysql_real_escape_string($value)."’";
$result = mysql_query($query) or die("Error processing query. ".mysql_error());
$row = mysql_fetch_object($result);

echo “

”;
echo "“.”“;
echo "“.”“;
echo "“.”“;
echo "“.”";
echo “
Writer ".$row->writer."
Subject ”.$row->subject."
Message ”.$row->message."
File ”."
”;
}

mysql_close($con);

?>[/php]

Am I doing it wrong?

Weird, because I’m just removing your database information and its working fine for me.
test.php
[php]<?php

echo “

”;
echo “”;

echo “


."";
echo “ ”;
echo “”;
echo “”;

?>[/php]

test2.php
[php]<?php
if(is_array($_POST[‘id’])) foreach($_POST[‘id’] as $value){
echo $value;
}
?>[/php]

When first one is checked I get “100”
When second is checked it get “200”
When both are checked i get “100200”

Please include error_reporting(E_ALL); at the top of your view.php
What index is undefined?

Can’t edit my last post :confused:

I setup a mock database to use your variables etc.
Works fine for me.
[php]$result = mysql_query(“SELECT * FROM t_board ORDER BY registerTime DESC LIMIT $offset, $rowsperpage”)
or die("Error processing query. ".mysql_error());

while($row = mysql_fetch_object($result))
{

echo ‘’;

echo “

”;
echo “”.$row->index."";

echo "

"
.’’;
echo “”.$row->writer."";
echo “”.$row->registerTime."";
echo “”;

}
echo “”;
echo “”;[/php]
This displays the table. echo “”; is outside the while so it sends all the checkbox’s at once.
Put it inside it to send only the values depending on what submit is pressed.

[php]if(is_array($_POST[‘id’])) foreach($_POST[‘id’] as $value){

$query = “SELECT * FROM t_board WHERE writer = '”.mysql_real_escape_string($value)."’";
$result = mysql_query($query) or die("Error processing query. ".mysql_error());
$row = mysql_fetch_object($result);

echo “

”;
echo "“.”“;
echo "“.”“;
echo "“.”“;
echo "“.”";
echo “
Writer ".$row->writer."
Subject ”.$row->subject."
Message ”.$row->message."
File ”."
”;
} [/php]

If both checked it displays 2 tables for me.
If one or the other is checked it displays 1 table depending on which is selected.
Oh, and I couldn’t get the javascript submit script to work for me… which was very weird so I added submit buttons.

OMG! Thank you lothop! It’s working now.

The reason why I used that javascript because I need to make a text link that can submit the data, the submit button really gets the job but I think it’s much better to see if that button is a text link cause I find it awkward.

Lothop, is it possible to make that button beside the checkbox a text link?

Lothop I’m very grateful for your help but now again I’m facing a new ordeal. I can’t update the items on my db. Using the view.php I send the date to modify.php then I accessed the input through $_POST then used this

[php] $query2 = "UPDATE t_board SET writer =’$_POST[mWriter]’, subject=’$_POST[mSubject]’, message=’$_POST[mMessage]’
WHERE writer = ‘$vIndex’ "[/php]

to update the row I selected from list.php

I think the problem is, I’m accessing a data from the db which is not existing.

[php]

<?php echo "";

$vIndex = $_POST[‘getIndex’];
$vWriter = $_POST[‘getWriter’];
$vSubject = $_POST[‘getSubject’];
$vMessage = $_POST[‘getMessage’];

echo “<link type=“text/css” rel=“stylesheet” href=“board.css” />\n”;

echo “\n”;
echo “<div id=“wrap”>\n”;
echo " <div id=“content”>\n";
echo "

Board Modify

\n";
echo " <ul class=“board_detail”>\n";
echo "
  • \n";
    echo "
    \n";
    echo "
    Writer
    \n";
    echo "
    <input type=“text” value="$vWriter" name=“mWriter” />
    \n";
    echo "
    \n";
    echo "
  • \n";
    echo "
  • \n";
    echo "
    \n";
    echo "
    Subject
    \n";
    echo "
    <input type=“text” value="$vSubject" name=“mSubject” />
    \n";
    echo "
    \n";
    echo "
  • \n";
    echo "
  • \n";
    echo "
    \n";
    echo "
    Message
    \n";
    echo " <dd class=“message”><textarea rows=“8” cols=“40” name=“mMessage”>$vMessage\n";
    echo "
    \n";
    echo "
  • \n";
    echo "
  • \n";
    echo "
    \n";
    echo "
    File
    \n";
    echo "
    <input type=“text” value=“filename” class=“fileupload” /><input type=“button” value=“Search”/>
    \n";
    echo "
    \n";
    echo "
  • \n";
    echo " <li class=“submit”>\n";

    error_reporting(0);

    $con = mysql_connect(“localhost”,“root”,“asa123”);
    if (!$con)
    {
    die('Could not connect: ’ . mysql_error());
    }

    mysql_select_db(“bbs”,$con);

    $query2 = "UPDATE t_board SET writer =’$_POST[mWriter]’, subject=’$_POST[mSubject]’, message=’$_POST[mMessage]’
    WHERE writer = ‘$vIndex’ ";

    echo " <input type=“submit” value=“Submit”/>\n";
    echo " <input type=“button” onClick=parent.location=‘http://localhost/UI-Simplex%20internet%20web%20developer%20test/src/list.php’ value=“Cancel”/>\n";
    echo " \n";
    echo " \n";
    echo " \n";
    echo “\n”;

    echo “”;

    ?>

    [/php]

    I agree the button looks crap, and I agree the text link is best in this situation, but I just got it working now.

    Submit

    The name=“theForm”. Not id=“theForm”

    Now your update is wack.
    For modifying data, how are you getting your data from
    $vIndex = $_POST[‘getIndex’];
    $vWriter = $_POST[‘getWriter’];
    $vSubject = $_POST[‘getSubject’];
    $vMessage = $_POST[‘getMessage’];

    You should use $_GET[‘id’] to get the id number from the link. Then grab the information from database WHERE id = $_GET['id]. Then you can use predefined values when modifying. I’m guessing index is your id?
    So in view.php where you click modify
    echo "

    Modify “.”"." ";

    You need to display the form. Send it to be updated. Return to list.php
    You can update it on the same page of the form if you would like.

    [php]<?php
    error_reporting(0);

    if(isset($_POST[‘submit’])){
    $con = mysql_connect(“localhost”,“root”,"");
    if (!$con)
    {
    die('Could not connect: ’ . mysql_error());
    }

    mysql_select_db(“bbs”,$con);

    $query2 = "UPDATE t_board SET writer =’$_POST[mWriter]’, subject=’$_POST[mSubject]’, message=’$_POST[mMessage]’
    WHERE index = ‘$vIndex’ ";
    header(‘Location:view.php’);
    exit();
    }
    ?>

    <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("bbs",$con); $query = "SELECT * FROM t_board WHERE index = '".mysql_real_escape_string($_GET['id'])."'"; $result = mysql_query($query) or die("Error processing query. ".mysql_error()); $row = mysql_fetch_object($result); echo ""; echo "\n"; echo "\n"; echo "
    \n"; echo "
    \n"; echo "

    Board Modify

    \n"; echo "
      \n"; echo "
    • \n"; echo "
      \n"; echo "
      Writer
      \n"; echo "
      writer\" name=\"mWriter\" />
      \n"; echo "
      \n"; echo "
    • \n"; echo "
    • \n"; echo "
      \n"; echo "
      Subject
      \n"; echo "
      subject\" name=\"mSubject\" />
      \n"; echo "
      \n"; echo "
    • \n"; echo "
    • \n"; echo "
      \n"; echo "
      Message
      \n"; echo "
      $row->message
      \n"; echo "
      \n"; echo "
    • \n"; echo "
    • \n"; echo "
      \n"; echo "
      File
      \n"; echo "
      \n"; echo "
      \n"; echo "
    • \n"; echo "
    • \n"; echo " \n"; echo " \n"; echo "
    • \n"; echo "
    \n"; echo "
    \n"; echo "
    \n"; echo ""; ?> [/php]

    I hope this makes sense to you.
    So when you click modify it;
    Sends you to a link with id= in the url.
    Use GET to get the id value.
    Selects database information based on id matchup.
    Files in form input fields with the matched data, so you know what your changing.
    Form is submitted to modify.php?id=
    Checks to see submit has been pressed, updates database information.
    Sends back to list.php where the information will be updated.

    Thanks a lot lothop, I tried using the javascript, but it doesn’t link me to the other page. I now get the idea, so it sends the index e.g 40 to the url so I get it using $_GET, but it says
    " Error processing query. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘index = ‘40’’ at line 1" I tried chaging the method post to get but I still get the error.

    I guess the problem is here lothop, I’m still figuring out how to make it work.

    [php] mysql_select_db(“bbs”,$con);
    $query = “SELECT * FROM t_board WHERE index = '”.mysql_real_escape_string($_GET[‘id’])."’";
    $result = mysql_query($query) or die("Error processing query. ".mysql_error());
    $row = mysql_fetch_object($result);[/php]

    I’m trying to simply things because my deadline is today :c, ok so the data from view.php is sent to modify.php. and then after I modify it I send the data to view2.php to see the changes.

    This is what I did in modify.php

    [php]

    <?php $vIndex = $_POST['getIndex']; $vWriter = $_POST['getWriter']; $vSubject = $_POST['getSubject']; $vMessage = $_POST['getMessage']; echo ""; //echo ""; echo "\n"; echo "\n"; echo "
    \n"; echo "
    \n"; echo "

    Board Modify

    \n"; echo "
      \n"; echo "
    • \n"; echo "
      \n"; echo "
      Writer
      \n"; echo "
      \n"; echo "
      \n"; echo "
    • \n"; echo "
    • \n"; echo "
      \n"; echo "
      Subject
      \n"; echo "
      \n"; echo "
      \n"; echo "
    • \n"; echo "
    • \n"; echo "
      \n"; echo "
      Message
      \n"; echo "
      $vMessage
      \n"; echo "
      \n"; echo "
    • \n"; echo "
    • \n"; echo "
      \n"; echo "
      File
      \n"; echo "
      \n"; echo "
      \n"; echo "
    • \n"; echo "
    • \n"; echo " \n"; echo " \n"; echo "
    • \n"; echo "
    \n"; echo "
    \n"; echo "
    \n"; echo ""; ?> [/php]

    and then after the data is submitted to view2.php it will update and display the changes.

    [php]

    Simplexi Board <?php

    echo “”;

    if(isset($_POST[‘submit’]))
    {
    $con = mysql_connect(“localhost”,“root”,“asa123”);
    if (!$con)
    {
    die('Could not connect: ’ . mysql_error());
    }
    else
    {
    mysql_select_db(“bbs”,$con);

    $query2 = "UPDATE t_board SET writer =’$_POST[mWriter]’, subject=’$_POST[mSubject]’, message=’$_POST[mMessage]’
    WHERE writer = ‘$vWriter’ ";

    }
    }

    $con = mysql_connect(“localhost”,“root”,“asa123”);
    if (!$con)
    {
    die('Could not connect: ’ . mysql_error());
    }

    mysql_select_db(“bbs”,$con);

    $query = “SELECT * FROM t_board WHERE writer = '”.mysql_real_escape_string($_GET[‘id’])."’";
    $result = mysql_query($query) or die("Error processing query. ".mysql_error());
    $row = mysql_fetch_object($result);

    $index = $row->index;
    $writer = $row->writer;
    $subject = $row->subject;
    $message = $row->message;

    echo “<link type=“text/css” rel=“stylesheet” href=“board.css” />\n”;
    echo “\n”;
    echo “<div id=“wrap”>\n”;
    echo " <div id=“content”>\n";
    echo "

    Board View

    \n";
    echo " <ul class=“board_detail”>\n";
    echo "
  • \n";
    echo "
    \n";
    echo "
    Index
    \n";
    echo "
    <input = ‘text’ name=‘getIndex’ value=’$index’ >
    \n";
    echo "
    \n";
    echo "
  • \n";
    echo "
  • \n";
    echo "
  • \n";
    echo "
    \n";
    echo "
    Writer
    \n";
    echo "
    <input = ‘text’ name=‘getWriter’ value=’$writer’ >
    \n";
    echo "
    \n";
    echo "
  • \n";
    echo "
  • \n";
    echo "
    \n";
    echo "
    Subject
    \n";
    echo "
    <input = ‘text’ name=‘getSubject’ value=’$subject’ >
    \n";
    echo "
    \n";
    echo "
  • \n";
    echo "
  • \n";
    echo "
    \n";
    echo "
    Message
    \n";
    echo " <dd class=“message”>$message\n";
    echo "
    \n";
    echo "
  • \n";
    echo "
  • \n";
    echo "
    \n";
    echo "
    File
    \n";
    echo "
    <a href="#">
    \n";
    echo "
    \n";
    echo "
  • \n";
    echo " <li class=“submit”>\n";
    echo " <input type=“button” onClick=parent.location=‘http://localhost/UI-Simplex%20internet%20web%20developer%20test/src/list.php’ value=" List “/>\n”;
    echo " <input type=‘submit’ name=‘submit’ value=“Modify” />\n";
    echo " \n";
    echo " \n";
    echo " \n";
    echo “\n”;

    echo “”;
    mysql_close($con);
    ?>

    [/php]

    Any ideas why the view2.php is not updating lothop?

    I was able to make it work using this lothop

    [php]

    Simplexi Board <?php

    echo “”;

    $con = mysql_connect(“localhost”,“root”,“asa123”);
    if (!$con)
    {
    die('Could not connect: ’ . mysql_error());
    }

    mysql_select_db(“bbs”,$con);

    $result = mysql_query(“UPDATE t_board SET writer=’$_POST[mWriter]’, subject =’$_POST[mSubject]’, message=’$_POST[mMessage]’
    WHERE writer=’$_GET[id]’”)
    or die(mysql_error());

    $result = mysql_query(“SELECT * FROM t_board WHERE writer = '”.mysql_real_escape_string($_GET[‘id’])."’")
    or die(mysql_error());
    //$result = mysql_query($query) or die("Error processing query. ".mysql_error());
    $row = mysql_fetch_object($result);

    echo $row->message;

    echo “<link type=“text/css” rel=“stylesheet” href=“board.css” />\n”;
    echo “\n”;
    echo “<div id=“wrap”>\n”;
    echo " <div id=“content”>\n";
    echo "

    Board View

    \n";
    echo " <ul class=“board_detail”>\n";
    /*echo "
  • \n";
    echo "
    \n";
    echo "
    Index
    \n";
    echo "
    <input = ‘text’ name=‘getIndex’ value=’$index’ >
    \n";
    echo "
    \n";
    echo "
  • \n";
    */
    echo "
  • \n";
    echo "
  • \n";
    echo "
    \n";
    echo "
    Writer
    \n";
    echo "
    <input = ‘text’ name=‘getWriter’ value=’$row->writer’ >
    \n";
    echo "
    \n";
    echo "
  • \n";
    echo "
  • \n";
    echo "
    \n";
    echo "
    Subject
    \n";
    echo "
    <input = ‘text’ name=‘getSubject’ value=’$row->subject’ >
    \n";
    echo "
    \n";
    echo "
  • \n";
    echo "
  • \n";
    echo "
    \n";
    echo "
    Message
    \n";
    echo " <dd class=“message”>$row->message\n";
    echo "
    \n";
    echo "
  • \n";
    echo "
  • \n";
    echo "
    \n";
    echo "
    File
    \n";
    echo "
    <a href="#">
    \n";
    echo "
    \n";
    echo "
  • \n";
    echo " <li class=“submit”>\n";
    echo " <input type=“button” onClick=parent.location=‘http://localhost/UI-Simplex%20internet%20web%20developer%20test/src/list.php’ value=" List “/>\n”;
    echo " <input type=‘submit’ name=‘submit’ value=“Modify” />\n";
    echo " \n";
    echo " \n";
    echo " \n";
    echo “\n”;

    echo “”;
    mysql_close($con);
    ?>

    [/php]

    It’s weird… If I use the index I get the error that I can’t get the index, but if it’s writer It’s working fine.

    Lothop, I tried using the javascript that you gave me earlier but I really can’t make it work also the index if I’m using it in the WHERE in query I got tons of error >_<

    You only want to update the database information when submit is pressed, which is what the first bit does.

    This updates for me fine when I do it.

    [php]<?php
    error_reporting(0);
    if(isset($_POST[‘submit’])){
    $con = mysql_connect(“localhost”,“root”,“asa123”);
    if (!$con)
    {
    die('Could not connect: ’ . mysql_error());
    }

    mysql_select_db(“bbs”,$con);

    $query2 = “UPDATE t_board SET writer =’”.$_POST[‘mWriter’]."’, subject=’".$_POST[‘mSubject’]."’, message=’".$_POST[‘mMessage’]."’ WHERE index = ‘".$_GET[‘id’]."’ ";
    $result = mysql_query($query2) or die("Error processing query. ".mysql_error());
    header(‘Location:view2.php’);
    exit();
    }
    ?>

    <?php $con = mysql_connect("localhost","root","asa123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("bbs",$con); $query = "SELECT * FROM t_board WHERE index = '".mysql_real_escape_string($_GET['id'])."'"; $result = mysql_query($query) or die("Error processing query. ".mysql_error()); $row = mysql_fetch_object($result); echo ""; echo "\n"; echo "\n"; echo "
    \n"; echo "
    \n"; echo "

    Board Modify

    \n"; echo "
      \n"; echo "
    • \n"; echo "
      \n"; echo "
      Index
      \n"; echo "
      \n"; echo "
      \n"; echo "
    • \n"; echo "
    • \n"; echo "
      \n"; echo "
      Writer
      \n"; echo "
      writer\" name=\"mWriter\" />
      \n"; echo "
      \n"; echo "
    • \n"; echo "
    • \n"; echo "
      \n"; echo "
      Subject
      \n"; echo "
      subject\" name=\"mSubject\" />
      \n"; echo "
      \n"; echo "
    • \n"; echo "
    • \n"; echo "
      \n"; echo "
      Message
      \n"; echo "
      $row->message
      \n"; echo "
      \n"; echo "
    • \n"; echo "
    • \n"; echo "
      \n"; echo "
      File
      \n"; echo "
      \n"; echo "
      \n"; echo "
    • \n"; echo "
    • \n"; echo " \n"; echo " \n"; echo "
    • \n"; echo "
    \n"; echo "
    \n"; echo "
    \n"; echo ""; ?> [/php]
    Sponsor our Newsletter | Privacy Policy | Terms of Service