PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
burnhallian
Forum Commoner
Posts: 28 Joined: Tue Jul 12, 2005 2:47 am
Post
by burnhallian » Tue Dec 20, 2005 2:57 am
patrikG | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
hello all !
hey can someone help me in this; its a ctually simple. im using a radio button and i want to kow how would i edit the radio button when im using it in a form and also how would i display it once the form is filled, i mean how would i take its value from the database? the code for the button is below:Code: Select all
<tr><td><font face="Arial" size="3"><b>5. How would you characterize the quality of this output ? </b><br><br>
<input type="radio" name="kl" value="sig" checked> Significant breakthrough <br>
<input type="radio" name="kl" value="maj" > Major improvement <br>
<input type="radio" name="kl" value="min" > Minor improvement <br><HR>
</td></tr>
patrikG | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Tue Dec 20, 2005 5:12 am
To use it in a form is no different, just put <form> tags around the whole thing with action="php-script.php" and method as POST or GET.
Probably best to look in the manual at php.net for this, it's explained quite nicely.
As for displaying the result you just
Code: Select all
echo $_POST['kl']; //or $_GET['kl'] if you used GET
Display value from the database? We'd need to know something about your database before we can answer that one
burnhallian
Forum Commoner
Posts: 28 Joined: Tue Jul 12, 2005 2:47 am
Post
by burnhallian » Tue Dec 20, 2005 8:53 pm
i still couldnt get it. Simply how do we edit a radio button. i have a form and once it is filled i want it to be edited. like i use for text box to retrive the value from database, what should i write for radio button ? thanx in advance
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Tue Dec 20, 2005 9:21 pm
Huh? Can you please explain what you mean by "edit the radio button"?
josh
DevNet Master
Posts: 4872 Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida
Post
by josh » Tue Dec 20, 2005 9:54 pm
If you have a group of radio buttons, and you have your variable already its pretty easy:
Code: Select all
<?
$data = 'bar';
?>
<input name="foo" type="radio" value="bar"<?=($data=='bar') ? ' checked' : '' ?> />
<input name="foo" type="radio" value="hello"<?=($data=='hello') ? ' checked' : '' ?> />
<input name="foo" type="radio" value="world"<?=($data=='world') ? ' checked' : '' ?> />
burnhallian
Forum Commoner
Posts: 28 Joined: Tue Jul 12, 2005 2:47 am
Post
by burnhallian » Tue Dec 20, 2005 9:55 pm
HawleyJR | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Actually im using a simple form in which user key in values. If a user wants to edit what they have submitted, for that im writing the code which is given below. im able to get the values from database so that the user can see what they have put in previously and they can add/delete text from it. but in the last part of the code im having a radio button, so i dont know how to get the values what the user had already submitted. there are 3 fields 1) Significant breakthrough, 2) Major improvement, 3) Minor improvement with the values sig, maj, min respectively in the radio button which have the field in database as "kl" . Plzz help
php code:Code: Select all
<?php
if(!isset($_COOKIE['user_id'])||empty($_COOKIE['user_id'])){
include('header.inc');
echo "Please login first";
include('footer.inc');
exit();}
include('header.inc');
$_SESSION['iddd']=$_GET['id1'];
if(isset($_GET['id1'])) {
require_once('mysql_connect.php');
$query="SELECT * from objective WHERE hw_id={$_GET['id1']}";
$result=@mysql_query($query);
$row=mysql_fetch_array($result);
}
if(isset($_POST['submit']))
{ require_once('mysql_connect.php');
$i=$_POST['iii'];
$abc=$_POST['orig'];
$def=$_POST['ach'];
$ghi=$_POST['nach'];
$jkl=$_POST['indi'];
$mno=$_POST['kl'];
$sql="UPDATE objective SET orig='$abc',ach='$def',nach='$ghi',
indi='$jkl',kl='$mno' WHERE hw_id='$i'";
$result=@mysql_query($sql);
if($result) { echo 'Your Report is updated, ';
echo "Click Next to continue with editing";
$url1="edits3.php?hw=$i "; ?>
<button onClick="window.location='<?php echo $url1;?>'">Next>></button>
<?php include ('footer.inc');
exit();}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<fieldset><legend><font size="4" color="blue">OBJECTIVE ACHIEVEMENT
</font</legend>
<input type="hidden" name="iii" VALUE="<?php echo $row['hw_id'] ?>"/>
<table width="100%" bgcolor="#d0d8ea">
<tr><td><font face="Arial" size="3"><b>1. Original Project Achievement</b><br><font face="Times" size="3" color="blue"><i>(State the specific project objectives as described in proposal)</i><br>
<p><textarea name="orig" rows="4" cols="70" align="center">
<?php echo $row['orig']; ?>
</textarea></p>
<hr></td></tr>
<tr><td><font face="Arial" size="3"><b>2. Objectives Achieved</b><br><font face="Times" size="3" color="blue"><i>(State the extent to which the project objectives were achieved)</i></tr></td>
<tr><td>
<textarea name="ach" rows="4" cols="70"><?php echo $row['ach']; ?> </textarea><hr></td></tr>
<tr><td><font face="Arial" size="3"><b>3. Objectives not Achieved</b><br><font face="Times" size="3" color="blue"><i>(Identify the objectives that were not achieved and give reasons for not achieving the objectives)</i></tr></td>
<tr><td>
<textarea name="nach" rows="4" cols="70"><?php echo $row['nach']; ?> </textarea><hr></td></tr>
<tr><td><font face="Arial" size="3"><b>4. Indicators for achievement of objectives</b><br><font face="Times" size="3" color="blue"><i>(Specify the key indicators applied, quantifiable or qualitative, in assessing the degree of success in achieving the objectives of the project)</i></tr></td>
<tr><td>
<textarea name="indi" rows="4" cols="70"><?php echo $row['indi']; ?> </textarea><hr></td></tr>
<tr><td><font face="Arial" size="3"><b>5. How would you characterize the quality of this output ? </b><br><br>
<input type="radio" name="kl" value="sig" checked> Significant breakthrough <br>
<input type="radio" name="kl" value="maj" > Major improvement <br>
<input type="radio" name="kl" value="min" > Minor improvement <br><HR>
</td></tr>
</table>
<div align="center"><input type="submit" name="submit" value="UPDATE REPORT"/> </div>
</form>
HawleJR | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
josh
DevNet Master
Posts: 4872 Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida
Post
by josh » Tue Dec 20, 2005 10:06 pm
I think I just showed you how to do it? maybe I'm still mis-understanding...
I check the first radio button, then submit the form... so now the value is updated in the DB. When I go back to the form whatever I had checked before is now already checked because it is looking at the DB to decide which item should be checked? See my previous post.
burnhallian
Forum Commoner
Posts: 28 Joined: Tue Jul 12, 2005 2:47 am
Post
by burnhallian » Tue Dec 20, 2005 10:36 pm
thanks a lot jshpro2, but im still not getting it . im a new bio in PHP so sorry for troubling u guys ! i have modified the code as given below but still it does not take the value of radio button from database.
thanx in advance
$mno=$_POST['kl'];
Code: Select all
<tr><td><font face="Arial" size="3"><b>5. How would you characterize the quality of this output ? </b><br><br>
<input name="kl" type="radio" value="sig"<?=($mno=='sig') ? ' checked' : '' ?> />Significant breakthrough <br>
<input name="kl" type="radio" value="maj"<?=($mno=='maj') ? ' checked' : '' ?> />Major improvement <br>
<input name="kl" type="radio" value="min"<?=($mno=='min') ? ' checked' : '' ?> />Minor improvement <br><HR>
</td></tr>
josh
DevNet Master
Posts: 4872 Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida
Post
by josh » Tue Dec 20, 2005 10:51 pm
you are getting $mno from the post data though, you need to pull it from the database. I assume you already know how to do this as you said it was working for all your text-boxes?
burnhallian
Forum Commoner
Posts: 28 Joined: Tue Jul 12, 2005 2:47 am
Post
by burnhallian » Tue Dec 20, 2005 11:32 pm
thanx for the reply man ! but still i couldnt get it... still newbie in PHP.
im posting the code.. do plzz check out where the problem is, sory again,
Code: Select all
<?php
if(!isset($_COOKIE['user_id'])||empty($_COOKIE['user_id'])){
include('header.inc');
echo "Please login first";
include('footer.inc');
exit();}
include('header.inc');
$_SESSION['iddd']=$_GET['id1'];
if(isset($_GET['id1'])) {
require_once('mysql_connect.php');
$query="SELECT * from objective WHERE hw_id={$_GET['id1']}";
$result=@mysql_query($query);
$row=mysql_fetch_array($result);
}
if(isset($_POST['submit']))
{ require_once('mysql_connect.php');
$i=$_POST['iii'];
$abc=$_POST['orig'];
$def=$_POST['ach'];
$ghi=$_POST['nach'];
$jkl=$_POST['indi'];
$mno=$_POST['kl'];
$sql="UPDATE objective SET orig='$abc',ach='$def',nach='$ghi',
indi='$jkl',kl='$mno' WHERE hw_id='$i'";
$result=@mysql_query($sql);
if($result) { echo 'Your Report is updated, ';
echo "Click Next to continue with editing";
$url1="edits3.php?hw=$i "; ?>
<button onClick="window.location='<?php echo $url1;?>'">Next>></button>
<?php include ('footer.inc');
exit();}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<fieldset><legend><font size="4" color="blue">OBJECTIVE ACHIEVEMENT
</font</legend>
<input type="hidden" name="iii" VALUE="<?php echo $row['hw_id'] ?>"/>
<table width="100%" bgcolor="#d0d8ea">
<tr><td><font face="Arial" size="3"><b>1. Original Project Achievement</b><br><font face="Times" size="3" color="blue"><i>(State the specific project objectives as described in proposal)</i><br>
<p><textarea name="orig" rows="4" cols="70" align="center">
<?php echo $row['orig']; ?>
</textarea></p>
<hr></td></tr>
<tr><td><font face="Arial" size="3"><b>2. Objectives Achieved</b><br><font face="Times" size="3" color="blue"><i>(State the extent to which the project objectives were achieved)</i></tr></td>
<tr><td>
<textarea name="ach" rows="4" cols="70"><?php echo $row['ach']; ?> </textarea><hr></td></tr>
<tr><td><font face="Arial" size="3"><b>3. Objectives not Achieved</b><br><font face="Times" size="3" color="blue"><i>(Identify the objectives that were not achieved and give reasons for not achieving the objectives)</i></tr></td>
<tr><td>
<textarea name="nach" rows="4" cols="70"><?php echo $row['nach']; ?> </textarea><hr></td></tr>
<tr><td><font face="Arial" size="3"><b>4. Indicators for achievement of objectives</b><br><font face="Times" size="3" color="blue"><i>(Specify the key indicators applied, quantifiable or qualitative, in assessing the degree of success in achieving the objectives of the project)</i></tr></td>
<tr><td>
<textarea name="indi" rows="4" cols="70"><?php echo $row['indi']; ?> </textarea><hr></td></tr>
<tr><td><font face="Arial" size="3"><b>5. How would you characterize the quality of this output ? </b><br><br>
<input name="kl" type="radio" value="sig"<?=($mno=='sig') ? ' checked' : '' ?> />Significant breakthrough <br>
<input name="kl" type="radio" value="maj"<?=($mno=='maj') ? ' checked' : '' ?> />Major improvement <br>
<input name="kl" type="radio" value="min"<?=($mno=='min') ? ' checked' : '' ?> />Minor improvement <br><HR>
</td></tr>
</table>
<div align="center"><input type="submit" name="submit" value="UPDATE REPORT"/> </div>
</form>
josh
DevNet Master
Posts: 4872 Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida
Post
by josh » Tue Dec 20, 2005 11:42 pm
add this somewhere
now visit the form, is it the value you're expecting?
burnhallian
Forum Commoner
Posts: 28 Joined: Tue Jul 12, 2005 2:47 am
Post
by burnhallian » Wed Dec 21, 2005 12:14 am
poor me !
im lost ... donno how to go about with it.... i thought it was simple.
where to put that line ? i tried but im not getting the real output for radio button. its jus giving the default for radio button.
josh
DevNet Master
Posts: 4872 Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida
Post
by josh » Wed Dec 21, 2005 12:16 am
then your problem is with this line:
why did you put that line? Can you show us what your database looks like, do you actually have this stored in a mysql table somewhere?
Hint: if you have phpmyadmin just go to the 'export' tab and click structure only, and show us the sql it shows you
burnhallian
Forum Commoner
Posts: 28 Joined: Tue Jul 12, 2005 2:47 am
Post
by burnhallian » Wed Dec 21, 2005 12:43 am
this is the table structure"
CREATE TABLE `objective` (
`hw_id` int(11) NOT NULL default '0',
`orig` text NOT NULL,
`ach` text NOT NULL,
`nach` text NOT NULL,
`indi` text NOT NULL,
`kl` char(3) NOT NULL default '0'
) TYPE=MyISAM;
kl is the one in which i am putting the value of radio button. So im not sure may be im doing it wrongly... correct me plzz
feyd | read your private messages.