Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

radiobutton

Posted on 2007-03-20
22
Medium Priority
?
394 Views
Last Modified: 2013-12-13
I have alist of articles taken out of the db. At the end of each line, I've put a radiobutton, because you can only change 1 article at the time. I'm I on the right track?

<?php
if (isset($_POST["check"])) {
      $res=mysql_query("Select * FROM articles WHERE id in (" . $_POST["check"] . ")") or die(mysql_error());
}
?>

<form method='post' name='form1' action='changearticles.php'>
<table border="1" width="100%" cellpadding="0" cellspacing="0">
<tr>
      <td width="20%"><b>&nbsp;ID</b></td>
      <td width="60%"><b>&nbsp;Title</b></td>
      <td width="10%"><b>&nbsp;Category&nbsp;</b></td>
      <td width="10%"><center><b>Change</b></center></td>
</tr>
<?php
$res=mysql_query("SELECT id, title, category FROM articles Order by id") or die(mysql_error());
while($r = mysql_fetch_array($res)) {
      echo '<tr><td>&nbsp;'.$r['id'].'</td><td>&nbsp;'.$r['title'].'</td><td><center>'.$r['category'].'</center></td><td><center><input name="check" type="radio" value="'.$r['id'].'" /></center></td></tr>';  
}
?>
</table>
<br />
<input type=submit name=cmdSubmit value='Change' />
</form>
0
Comment
Question by:jvuz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 6
  • 4
22 Comments
 
LVL 14

Expert Comment

by:Aamir Saeed
ID: 18755695
i think you should use a hyperlink for it as it is standard as you might see it in phpmyadmin [EDIT]

0
 
LVL 24

Accepted Solution

by:
glcummins earned 750 total points
ID: 18755717
I agree that a link is the better choice, because it is easier to use. The user only needs to click once, rather than twice (once on the radio button, and once on the submit button).

A radio button would be a good choice if:
   1. You are limited on line space, and
   2. You provide multiple options on your submit buttons (Eg, change, delete, move, copy)
0
 
LVL 21

Author Comment

by:jvuz
ID: 18755855
So I should do it this way. Ask, through a query, every links, then, by clicking on a link, go to a page where I get the ID and get all data into a textbox, so I can change it?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 24

Expert Comment

by:glcummins
ID: 18755897
Yes. Your link would look like this:

<a href="changearticles.php?id=<?php $r['id']; ?>">Edit article</a>

Then in your 'changearticles.php', just check for the existance of the article ID:

if (isset($_REQUEST['id']))
{
   $id = $_REQUEST['id'];
   // Retrieve the article and display the textbox
}
0
 
LVL 14

Expert Comment

by:Aamir Saeed
ID: 18756144
i think you 'll have to echo the id e.g.

<a href="changearticles.php?id=<?php echo $r['id']; ?>">Edit article</a>
0
 
LVL 21

Author Comment

by:jvuz
ID: 18756215
In the page where I get the list of all the articles and I put them in an url,

<?php
                                     $res=mysql_query("SELECT id, title FROM articles Order by id") or die(mysql_error());
                                    while($r = mysql_fetch_array($res)) {
                        echo '<a href=pages/changingarticle.php?id='.$r['ID'].'>' . $res['ID']. '&nbsp;' . $r['title'] . '</a>'.'<br />';
                        } while($r = mysql_fetch_array($res));
                               ?>

I get:
Notice: Undefined index: ID
0
 
LVL 21

Author Comment

by:jvuz
ID: 18756223
Sorry, already solved that.
0
 
LVL 14

Expert Comment

by:Aamir Saeed
ID: 18756245
i think your field name is id and here you are using ID
0
 
LVL 24

Expert Comment

by:glcummins
ID: 18756247
Try a lower-case 'id', since that matches what you are pulling from the database.
0
 
LVL 21

Author Comment

by:jvuz
ID: 18756268
So now I need to select... and put this in a textbox?
0
 
LVL 14

Expert Comment

by:Aamir Saeed
ID: 18756288
yes
0
 
LVL 24

Expert Comment

by:glcummins
ID: 18756290
Yes, so that the user can edit the article.
0
 
LVL 14

Assisted Solution

by:Aamir Saeed
Aamir Saeed earned 750 total points
ID: 18756329
1; make select query
2; take vaues and display in the textbox
3; keep these input boxes into form
4; submit that form and get values e.g.
   $_POST['posted_data'];
5; update query
0
 
LVL 21

Author Comment

by:jvuz
ID: 18756417
I don't think this is in the good direction.

<?php
                                   $res=mysql_query("SELECT id, title, article, category, author WHERE id=".$_GET['id']) or die(mysql_error());
                                   $r = mysql_fetch_array($res);
                                   $article = nl2br($r['article']);
                                   echo '<table><tr>Title:<td></td><td><input type="text" name="title" size="90" maxlength="120"  />'.$r['title'].'</td></tr><tr>Title:<td></td><td>'.$r['title'].'</td></tr>;
                                   
                       ?>
0
 
LVL 14

Expert Comment

by:Aamir Saeed
ID: 18758028
this is wrong as you are not entering the table name

$res=mysql_query("SELECT id, title, article, category, author WHERE id=".$_GET['id']) or die(mysql_error());

as i dont see
   'from'
anywhere

the syntax of query is : select field1, field2 from table
0
 
LVL 21

Author Comment

by:jvuz
ID: 18762272
Tahnx, how stupid of me. But I'm wondering how I can put the data that I pulled out of the db into a textbox.
0
 
LVL 21

Author Comment

by:jvuz
ID: 18762350
I think is better

<?php
                                   $res=mysql_query("SELECT id, title, article, category, author FROM articles WHERE id=".$_GET['id']) or die(mysql_error());
                                   $r = mysql_fetch_array($res);
                                   $article = nl2br($r['article']);
                                   echo '<table><tr>Title:<td></td><td><textarea cols="5" rows="5" name="tekst">'.$r['title'].'</textarea></td></tr><tr>Title:<td></td><td>'.$r['title'].'</td></tr>;
                                   
                       ?>
0
 
LVL 21

Author Comment

by:jvuz
ID: 18762379
I think I'm getting there:

<?php
                                   $res=mysql_query("SELECT id, title, article, category, author FROM articles WHERE id=".$_GET['id']) or die(mysql_error());
                                   $r = mysql_fetch_array($res);
                                   $article = nl2br($r['article']);
                                   echo '<table><tr><td valign="top">Title:</td><td><textarea cols="70" rows="1" name="tekst">'.$r['title'].'</textarea></td></tr><tr><td valign="top">Article:</td><td><textarea cols="70" rows="10" name="tekst">'.$r['article'].'</textarea></td></tr></table>';
                                   
                       ?>

The only thing is, I don't get the box for the title smaller (in height)
0
 
LVL 21

Author Comment

by:jvuz
ID: 18762676
I'm this far for now.

<?php
                                   $res=mysql_query("SELECT id, title, article, category, author FROM articles WHERE id=".$_GET['id']) or die(mysql_error());
                                   $r = mysql_fetch_array($res);
                                   $article = nl2br($r['article']);
                                   /*echo '<table><tr><td valign="top">Title:</td><td><textarea cols="70" rows="1" name="tekst">'.$r['title'].'</textarea></td></tr><tr><td valign="top">Article:</td><td><textarea cols="70" rows="10" name="tekst">'.$r['article'].'</textarea></td></tr></table>';*/
                                   echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '" style="margin-left:1px;">';
                                   echo '<table>';
                            echo '<tr><td valign="top">Title</td><td><input type="text" name="title" value="'.$r['title'].'"style="width:535px;" /></td></tr>';
                            echo '<tr><td valign="top">Article:</td><td><textarea id="article"  name="event" rows="10" style="width:535px;">'.$r['article'].'</textarea></td></tr>';
                            echo '<tr><td></td><td><input type="submit" value="Change" /></td></tr></table>';
                            echo '</form>';
                       ?>

I think I need to add a way to send this to the db
0
 
LVL 21

Author Comment

by:jvuz
ID: 18763105
If I do this, it shows nothing on screen

   <?php
                                   $res=mysql_query("SELECT id, title, article, category, author FROM articles WHERE id=".$_GET['id']) or die(mysql_error());
                                   $r = mysql_fetch_array($res);
                                   $article = nl2br($r['article']);
                                   if(isset($_POST['submit'])) {
                                   echo '<form method="post" action="changearticles.php" style="margin-left:1px;">';
                                   echo '<table>';
                            echo '<tr><td valign="top">Title</td><td><input type="text" name="title" value="'.$r['title'].'"style="width:535px;" /></td></tr>';
                            echo '<tr><td valign="top">Article:</td><td><textarea id="article"  name="event" rows="10" style="width:535px;">'.$r['article'].'</textarea></td></tr>';
                            echo '<tr><td></td><td><input type="submit" value="Change" /></td></tr></table>';
                            echo '</form>';
                            mysql_query("UPDATE articles SET title='" . $_POST['title'] . "', article='" . $_POST['article'] . "' WHERE id='" . $id . "'");
                        }
                       ?>
0
 
LVL 21

Author Comment

by:jvuz
ID: 18763629
That's solved, but now it doesn't change anything. I can change something in the article for instance and when I click Change, nothing's changed.

<?php
                                   $res=mysql_query("SELECT id, title, article, category, author FROM articles WHERE id=".$_GET['id']) or die(mysql_error());
                                   $r = mysql_fetch_array($res);
                                   $article = nl2br($r['article']);
                                   if(!isset($_POST['submit'])) {
                                   echo '<form method="post" action="changearticles.php" style="margin-left:1px;">';
                                   echo "<input type=\"hidden\" name=\"berichtID\" value=\"".$r['id']."\" />";
                                   echo '<table>';
                            echo '<tr><td valign="top">Title</td><td><input type="text" name="title" value="'.$r['title'].'"style="width:535px;" /></td></tr>';
                            echo '<tr><td valign="top">Article:</td><td><textarea id="article"  name="article" rows="10" style="width:535px;">'.$r['article'].'</textarea></td></tr>';
                            echo '<tr><td></td><td><input type="submit" value="Change" /></td></tr></table>';
                            echo '</form>';
                        } else {
                            mysql_query("UPDATE articles SET title='" . $_POST['title'] . "', article='" . $_POST['article'] . "' WHERE id='" . $_POST['berichtID'] . "'")or die(mysql_error());
                        }
                       ?>
0
 
LVL 21

Author Comment

by:jvuz
ID: 18777977
OK, that one's solved.

<?php
ob_start();
?>
<?php
// include/require hier evt nog andere zaken
require ("../scripts/connect.php");
// we willen op deze pagina gebruik maken van beveiliging mbv sessies,
// dus includen (requiren) we session.php
require("../scripts/session.php");
$id = htmlentities($_GET["id"], ENT_QUOTES);
   // Fetch the article category
   $rsc = mysql_query("SELECT category FROM articles WHERE id=".$_GET['id']) or die(mysql_error());
   $row = mysql_fetch_array($rsc);
      $cat = $row['category'];

  if (($cat == 2) && ((int)$_SESSION['slevel'] < 2)) {
      header("Location:accessdenied.php");
      exit(); //stop the script.
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>KB RBINS</title>
<link rel="stylesheet" type="text/css" href="../main.css" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
</head>
<body>
   <!-- Begin Wrapper -->
   <div id="wrapper">
         <!-- Begin Header -->
         <div id="header">
                  <h1>Knowledgebase System RBINS</h1>      
             </div>
             <!-- End Header -->
         <!-- Begin Faux Columns -->
             <div id="faux">            
                   <!-- Begin Left Column -->
                   <div id="leftcolumn">      
                     <?php
                            include("../scripts/checkuser.php");
                     ?>      
                   </div>
                   <!-- End Left Column -->
                   <!-- Begin Right Column -->
                   <div id="rightcolumn">      
                     <center><h2>Change an article</h2></center><br />  
                     <?php
                                    if( isset( $_GET['id'] ) && is_numeric( $_GET['id'] ) ){
                                        $res = mysql_query( "SELECT title, article, category, author FROM articles  WHERE  id = " .$_GET['id'] ) or die('QUERY_SELECT ERROR:  <hr />' . mysql_error());
                                  $results = mysql_fetch_assoc( $res );
                                  if( $_SERVER['REQUEST_METHOD'] == 'POST' )
                                  {
                                // check if fields are empty

                                // no empty fields, so update:
                                $update = mysql_query( "UPDATE articles SET title     = '" . mysql_real_escape_string( $_POST['title']). "', article = '". mysql_real_escape_string( $_POST['article'] ) . "'WHERE  id = "  . $_GET['id']) or die('QUERY_UPDATE ERROR:  <hr />'. mysql_error());
                                echo "Changes have been made!";
                               }
                                  else
                                  {
                                // form without PHP
                                    ?>
                                   <!-- HIER FORMULIER -->
                                   <form method="post" action="" style="margin-left:1px;">
                        <table>
                              <tr>
                                    <td><input type="hidden" name="berichtID" value="<?php echo $results['id']; ?> " /></td>
                              </tr>
                              <tr>
                                    <td valign="top">Title</td><td><input type="text" name="title" value="<?php echo $results['title']; ?>"style="width:535px;" /></td>
                              </tr>
                            <tr>
                                  <td valign="top">Article:</td><td><textarea id="article"  name="article" rows="10" style="width:535px;"><?php echo $results['article']; ?></textarea></td>
                            </tr>
                            <tr>
                                  <td></td>
                                  <td><input type="submit" value="Change" /></td>
                            </tr>
                         </table>
                         </form>
                                    <?php
                                       }}
                                    else
                                    {
                                  echo "ONGELDIGE URL INVOER";
                                    }
                                    ?>          
                  <br />
                     <div class="clear"></div>                    
                   </div>
                   <!-- End Right Column -->                    
                     <div class="clear"></div>                    
         </div>        
         <!-- End Faux Columns -->
         <!-- Begin Footer -->
         <div id="footer">                  
               <h4>Jo Vanattenhoven&copy;2007</h4>            
         </div>
             <!-- End Footer -->            
   </div>
   <!-- End Wrapper -->
</body>
</html>
<?php
ob_end_flush();
?>

Now I just need to check if there are empty fields and see if the title doesn't exist already.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question