hello
i want display ( topic and author and date ) if user choose then click "save "

how can do that ?

this is my code:

<?php
$con=mysql_connect("localhost","root","");  

  if(!$con)  
  {  
   die('can not connect'.mysql_error());  
  }  
   mysql_select_db("scms", $con );  

   $result = mysql_query("select * from others");
    $num = mysql_num_rows($result);
     $row = mysql_fetch_array($result);
   echo"<table border='1' width='100%' id='table1'>";  
    echo"<thead>
    <tr>   <th>#</th>  <th>topic</th><th> author </th>  <th>date</th> 
        </thead>";
        echo"<tbody>";
   $i=0;  



  while( $i < $num )  { 

  $id  = mysql_result( $result , $i , "id" );     
   $topic = mysql_result( $result , $i , "topic" );  
   $author = mysql_result( $result , $i , "author" );  
    $date=mysql_result( $result , $i , "date" ); 
   echo"<tr>";
   ?>
   <form name="form1" method="post" action="show_others_0.php">
    <td> <input name="radio" type="radio" id="radio" value="<?php echo $row['id']?>"> </td> 
  <?php
   echo"<td width='20%'>$topic </td>";  
   echo"<td width='20%'>$author </td>";  
     echo"<td width='20%'> $date </td>";

   echo"</tr>"; 

   ++$i;  
  }  
    echo"</tbody>";
  echo"</table>";  
 ?>  


  <input name="save" type="submit" id="save" value="save">
  </form>


  <?php
mysql_close($con); 

?> 

please help me
thanks alot

Can you please explain some more what you want?

Sorry for the delay

if user choose from radio bottom then press save -> display information That have been selected :)

First move the beginning form tag (line 30) out of the while loop. It should be before the <table> tag, just after line 12.

The rest is similar to your previous post. If show_others_0.php script is another page (not this one) then you will process POST data there. First check if $_POST['save'] exists. If yes then the user has clicked the save button; insert the record and redirect to previous page. If $_POST['save'] does not yet exist check if $_POST['radio'] existst (comming from the previous page) and if it yes, display the other fields from the $_POST array. The code for show_others_0.php should be something like (not tested):

// check if the save button was pressed and if yes save the record and go back to previous page
if(isset($_POST['save']) and isset($_POST['id']) {

    $sql = 'INSERT INTO ... SELET * FROM   ... WHERE id=$id';

    // submit the query
    ...

    // go to previous page
    header('location:prev_page.php');
    exit;
}

// if no data in $_POST['radio'], print error message and exit
if(!isset($_POST['radio'])) {

    die('Nothing was selected!');
}

// to be safe force the value to be integer
$id = (int) $_POST['radio'];

// display the data by reading it from the database (you could also have it posted through the POST using hidden fields)
$sql = SELECT topic, author, date FROM ....;
// read the data and store it in variables
$topic = ...
$author = ...
$date = ...

// display the data
echo ...

// display the form
echo '<form>';

// put ID in hidden field
<input type="hidden" name="id" value="' . $id . '"><>

// display the save button
'<input type="submit" name="save" value="Save">';

// end the form
echo '</form>';

i am not understand :(
this code With modified form :

<?php
$con=mysql_connect("localhost","root","");  
  if(!$con)  
  {  
   die('can not connect'.mysql_error());  
  }  
   mysql_select_db("scms", $con );    
   $show_others="show_others";
   $sql = "select * FROM $show_others";
    $result=mysql_query($sql);
    $num = mysql_num_rows($result);
   echo"<table border='1' width='100%' id='table1'>";  
    echo"<thead>
    <tr>   <th>#</th>  <th>topic</th><th> author </th>  <th>date</th> 
        </thead>";
        echo"<tbody>";
        ?>

     <form name="form1" method="post" action="">
     <?php
while( $row = mysql_fetch_array($result))  { 
   echo"<tr>";
  ?>

    <td> <input name="radio[]" type="radio" id="radio[]" value="<?php echo $row['id']?>"> </td> 
  <td ><?php echo $row['topic']; ?></td>
    <td ><?php echo $row['author']; ?></td>
  <td ><?php echo $row['date']; ?></td>




<?php 
   echo"</tr>"; 
  }  
 echo"</tbody>";
  echo"</table>";  
  ?>


  <input name="save" type="submit" id="save" value="save">
  </form>


  <?php
    if(isset($_POST['save'])) 
    {

    if(isset($_POST['radio']) and !empty($_POST['radio']))
    {
    // What do I write here ??? to print topic and author and date ??? :(

    }
    }


mysql_close($con); 

?> 

please help me :(

Do you want to print topic and author and date on the same page or on another page?

first on the same page then on another page =)

Sorry, I do not get it. Can you explain a bit more (what is displayed and what are user actions).

i want display "topic and and author " if user choose then press save :)

Correct me if I did not understand OK:

  1. you want to display a table where each topic, author and date are one row
  2. each row has a radion button
  3. the user clicks one of the radio buttons to select the record to be saved (only one can be selected in a table)
  4. when user clicks on the save button then you want to save that record

How do you want the save to occur:

a. when user clicks on Save the topic, author and date are displayed on a new page with save button and the user has to click save button to actually save the record
b. when user clicks on the save button the record is saved and no new page is displayed (the page with the table remains open)
c. any other option

You understand the true

Choose a
:)

thank you alot

The following is a script I named table.php that displays rows with topic, author etc.

<?php
$con=mysql_connect("localhost","root","");

if(!$con) {

   die('can not connect'.mysql_error());
}

mysql_select_db("scms", $con );
$show_others="show_others";
$sql = "select * FROM $show_others";
$result=mysql_query($sql);
$num = mysql_num_rows($result);

// moved form tag here so the table is properly nested
// action is set to another page (confirm_save.php)
echo '<form name="form1" method="post" action="confirm_save.php">';

echo"<table border='1' width='100%' id='table1'>";
echo"<thead>
    <tr><th>#</th><th>topic</th><th>author</th><th>date</th>
    </thead>";
echo"<tbody>";

while( $row = mysql_fetch_array($result))  {
    echo"<tr>";
?>

<td> <input name="radio[]" type="radio" id="radio[]" value="<?php echo $row['id']?>"> </td>
<td ><?php echo $row['topic']; ?></td>
<td ><?php echo $row['author']; ?></td>
<td ><?php echo $row['date']; ?></td>

<?php
   echo"</tr>";
}

echo"</tbody>";
echo"</table>";
?>

<input name="save" type="submit" id="save" value="save">
</form>

<?php

mysql_close($con);

?>

When radio button is clicked it is submitted to the next page confirm_save.php which also has a form (for buttons to save or cancel).

<?php
// this script will get the form data through POST and ask user for confirmation
// if confirmed it will save the record otherwise it will redirect to the page
// POST was sent (I call it table.php)

// if this form (on this page) was submited with save button
// save the record and redirect back
if(isset($_POST['save']) and isset($_POST['id'])) {

    $id = $_POST['id'];

    $sql = "INSERT INTO others_2 VALUES SELECT FROM show_others WHERE id=$id";

    header('location:table.php');
    exit();
}

// if this form (on this page) was submited with cancel button
// only redirect back
if(isset($_POST['save'])) {

    header('location:table.php');
    exit();
}

// check if radio button has been submitted from the form on previous page
if(isset($_POST['radio']) and !empty($_POST['radio'])) {

    // the ID that was sent over
    $id = $_POST['radio'];

    // read the topic and author
    $qry = "SELECT topic, author, date FROM show_others WHERE id=$id";
    $result=mysql_query($sql);
    $row = mysql_fetch_array($result);

    echo "<p>Topic: $row['topic'], Auhor: $row['author'], Date: $row['date']</p>";

    echo '<p>Do you realy want to save the above data</p>';

    // a form with a hidden field that hold ID and two buttons
    // one for saving other for cancelling
    // form submits to the same page
    echo '<p><form method="post" action="#">';
    echo '<input type="hidden" name="id" value="' . $id . '"> ';
    echo '<input type="submit" name="save" value="Save"> ';
    echo '<input type="submit" name="cancel" value="Cancel"></form></p>';


// if radio button has not been sent (this should not happen really)
// then redirect to the page back
} else {

    header('location:table.php');
    exit();
}
?>

The code has not been tested but from comments you can see what is the point. Hope it helps.

thank you alot :)
I will try it :)

:""( i can't solve this problem :"(
please help me

here is error :""(

echo "<p>Topic: $row['topic'], Auhor: $row['author'], Date: $row['date']</p>";

i am solve this error
<p>Topic:<?php echo $row['topic'];?>
but this code not display anything !

:"(

Somewhere in your code is this: $id = $_POST['radio']; which overwrites the id with a wrong version, remove it.

Sorry, I was away for a week and this was my mistake; correct code is (enclose array element in curly braces):

echo "<p>Topic: {$row['topic']}, Auhor: {$row['author']}, Date: {$row['date']}</p>";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.