Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
radio button and mysql HELP PLEASE!
Old 09-11-2007, 12:19 AM radio button and mysql HELP PLEASE!
Skilled Talker

Posts: 65
Trades: 0
hi, this is the beginning of my php lesson and i might need some guide here

I have created a simple MySQL database, with fields;
$idnum
$name
$address
$date

I'd like to be able to show idnum, name, and address, and date (along with a radio button in front of each record) for all record in the database into a table.

The user will select a radio button for appropriate peom, then simply hit a
'delete' button, which of course will delete it from the database.
currently i am having a hard time with what I need to DO them.

Anyone who can help?
So, can anyone point me to any tutorials/scripts/tips/etc that might help?

Thanks
leolim is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-11-2007, 12:49 PM Re: radio button and mysql HELP PLEASE!
Super Talker

Posts: 134
Trades: 0
something like this :


PHP Code:
<?
mysql_connect
("host","username","password");
mysql_select_db("dbname");
if (isset(
$_POST["delete"])) {
    
mysql_query ("delete from atable where idnum = ".$_POST["idnum"]);
    
} else {
$res=mysql_query("SELECT * FROM atable");
echo 
"<form method='post' action='".$_SERVER['PHP_SELF']."'>";
while (
$rec=mysql_fetch_array($res)) {
 echo 
"<input type='radio' name = 'idnum' value='".$rec["idnum"]."'> ".$rec["idnum"]." ".$rec["name"]." ".$rec["address"].$rec["date"]."<br />";    
}
echo 
"<input type = 'submit' name='delete' value='delete'>";
echo 
"</form>";

}
mysql_close();       
?>
__________________

Please login or register to view this content. Registration is FREE

Check out the Facebook Clone build with Jcow SNS at
Please login or register to view this content. Registration is FREE
, it is free and it always will be
Falcone is offline
Reply With Quote
View Public Profile
 
Old 09-11-2007, 09:04 PM Re: radio button and mysql HELP PLEASE!
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
just a few pointers:

It is general practice now (and XHTML compliant) to close tags so tags which dont have a end tage like <span> and </span> do like <img src="" /> or <input type="text" /> etc..

Also with SQL queries its a good idea to make them in caps as it makes easier to read.

so like
PHP Code:
mysql_query ("DELETE FROM atable WHERE idnum = ".$_POST["idnum"]); 

Just some tips which will help you
Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-11-2007, 10:20 PM Re: radio button and mysql HELP PLEASE!
Skilled Talker

Posts: 65
Trades: 0
falcone thanks for the tips and it works
thanks all
leolim is offline
Reply With Quote
View Public Profile
 
Old 09-11-2007, 10:43 PM Re: radio button and mysql HELP PLEASE!
Skilled Talker

Posts: 65
Trades: 0
FALCON there is something i want to ask again.
now i have created a button called 'edit'
how do i transfer the value of the selected radio button to the next page once the edit clicked?
and how do get the value from the radio button in the second page?

really need help cause i am really blur now with the PHP coding

thanks
leolim is offline
Reply With Quote
View Public Profile
 
Old 09-12-2007, 01:12 AM Re: radio button and mysql HELP PLEASE!
brandrocker's Avatar
Experienced Talker

Posts: 30
Name: CONFIDENTIAL
Location: India
Trades: 0
Quote:
Originally Posted by leolim View Post
FALCON there is something i want to ask again.
now i have created a button called 'edit'
how do i transfer the value of the selected radio button to the next page once the edit clicked?
and how do get the value from the radio button in the second page?

really need help cause i am really blur now with the PHP coding

thanks
This may help you:
http://www.w3schools.com/php/php_forms.asp
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
brandrocker is offline
Reply With Quote
View Public Profile Visit brandrocker's homepage!
 
Old 09-12-2007, 03:37 PM Re: radio button and mysql HELP PLEASE!
Super Talker

Posts: 134
Trades: 0
in this case:

<input type='radio' name='idnum' />


if you hit the edit button the value would be $_POST["idnum"]


PS: i put the / this time
__________________

Please login or register to view this content. Registration is FREE

Check out the Facebook Clone build with Jcow SNS at
Please login or register to view this content. Registration is FREE
, it is free and it always will be
Falcone is offline
Reply With Quote
View Public Profile
 
Old 09-12-2007, 09:19 PM Re: radio button and mysql HELP PLEASE!
Skilled Talker

Posts: 65
Trades: 0
falcone i am not really sure about that
could you show me some example please?

do you mean that one delete and edit button have different forms each?
leolim is offline
Reply With Quote
View Public Profile
 
Old 09-12-2007, 09:52 PM Re: radio button and mysql HELP PLEASE!
Skilled Talker

Posts: 65
Trades: 0
This is what i do but nothing but error come out and if i remove the second form and click the delete button it triggered
" Forbidden
You don't have permission to access /".$_SERVER[ on this server.
Apache/1.3.33 Server at localhost Port 80" <-- what does this mean?

This is my code
PHP Code:
<?
mysql_connect
("localhost","root","");
mysql_select_db("school");
if (isset(
$_POST["delete"])) {
    
mysql_query ("delete from employee_data where idnum = ".$_POST["idnum"]);
 
} else {
$res=mysql_query("SELECT * FROM employee_data");
while (
$rec=mysql_fetch_array($res)) {
 echo 
"<input type='radio' name = 'idnum' value='".$rec["idnum"]."'> ".$rec["idnum"]." ".$rec["name"]." ".$rec["address"].$rec["date"]."<br />";    
}
}
mysql_close();       
?> 
<html>
<head>
<title>MY FORM</title>
</head><body>
<form method='post' action='".$_SERVER['PHP_SELF']."'>
<input type = 'submit' name='delete' value='delete'>
</form>
<form method='post' action='edit.php'>
<input type = 'submit' name='EDIT' value='<?php $_POST["idnum"?>'>
</form></body>
</html>
and in the edit.php i try to display the value like this:
PHP Code:
<?php
// Get the specified id
$val=$_GET['idnum'];
echo 
$val;
?>

Falcone am i doing the correct thing? what is my problem? could you help me to correct it?
thanks
leolim is offline
Reply With Quote
View Public Profile
 
Old 09-13-2007, 07:11 AM Re: radio button and mysql HELP PLEASE!
Super Talker

Posts: 134
Trades: 0
i has to be action = '<?= $_SERVER['PHP_SELF']; ?>'

it means if you it the submit button it sends the posted form values to the same page. if you want to send it to edit.php it should be: action = 'edit.php'
__________________

Please login or register to view this content. Registration is FREE

Check out the Facebook Clone build with Jcow SNS at
Please login or register to view this content. Registration is FREE
, it is free and it always will be
Falcone is offline
Reply With Quote
View Public Profile
 
Old 09-14-2007, 05:40 AM Re: radio button and mysql HELP PLEASE!
Skilled Talker

Posts: 65
Trades: 0
i don`t really get it. may be i am a slow learner but how to correct my mistake?
PHP Code:
<?
mysql_connect
("localhost","root","");
mysql_select_db("school");
if (isset(
$_POST["delete"])) {
    
mysql_query ("delete from employee_data where idnum = ".$_POST["idnum"]);
 
} else {
$res=mysql_query("SELECT * FROM employee_data");
while (
$rec=mysql_fetch_array($res)) {
 echo 
"<input type='radio' name = 'idnum' value='".$rec["idnum"]."'> ".$rec["idnum"]." ".$rec["name"]." ".$rec["address"].$rec["date"]."<br />";    
}
}
mysql_close();       
?> 
<html>
<head>
<title>MY FORM</title>
</head><body>
<form method='post' action='".$_SERVER['PHP_SELF']."'>
<input type = 'submit' name='delete' value='delete'>
</form>
<form method='post' action='edit.php'>
<input type = 'submit' name='EDIT' value='<?php $_POST["idnum"?>'>
</form></body>
</html>
is my method to pass the radio button value to the edit page is correct? which is
PHP Code:
<form method='post' action='edit.php'>
<input type = 'submit' name='EDIT' value='<?php $_POST["idnum"?>'>
</form>
if yes why i can`t pass the value?

thanks
leolim is offline
Reply With Quote
View Public Profile
 
Old 09-14-2007, 05:43 AM Re: radio button and mysql HELP PLEASE!
Skilled Talker

Posts: 65
Trades: 0
what i want is one button is to triggered the delete button and edit button is to pass the selected idnum value to the edit.php page.
some help please. really blur

thankz
leolim is offline
Reply With Quote
View Public Profile
 
Old 09-14-2007, 10:27 AM Re: radio button and mysql HELP PLEASE!
Super Talker

Posts: 134
Trades: 0
try this


PHP Code:
<html>
<head>
<title>MY FORM</title>
</head>
<body>
<?
mysql_connect
("localhost","root","");
mysql_select_db("school");
if (isset(
$_POST["delete"])) {
    
mysql_query ("DELETE FROM employee_data WHERE idnum = ".$_POST["idnum"]);
} elseif(isset(
$_POST["edit"]))  { 
$res=mysql_query("SELECT * FROM employee_data WHERE idnum =".$_POST["idnum"]);
$rec mysql_fetch_array($res);
    
?>
<form method='post' action='<?= $_SERVER['PHP_SELF']; ?>'>
<input type = "hidden" name = "idnum" value = '<?= $rec['idnum']; ?>'>
name : <input type = "text" name = "name" value = '<?= $rec['name']; ?>'><br />
address  : <input type = "text" name = "address" value = '<?= $rec['address']; ?>'><br />
date  : <input type = "text" name = "date" value = '<?= $rec['date']; ?>'><br />
<input type = 'submit' name='update' value='update'>

</form>

<?
} elseif(isset($_POST["update"]))  {
    
mysql_query("UPDATE employee_data SET name = ".$_POST['name'].", address =  ".$_POST['address'].", date =  ".$_POST['date']." WHERE id = ".$_POST['idnum']); 
} else {
//$res=mysql_query("SELECT * FROM employee_data");
$res=mysql_query("SELECT * FROM employee_data"); ?>
<form method='post' action='<?= $_SERVER['PHP_SELF']; ?>'>
<?
while ($rec=mysql_fetch_array($res)) {
 echo 
"<input type='radio' name = 'idnum' value='".$rec["idnum"]."'> ".$rec["idnum"]." ".$rec["name"]." ".$rec["address"].$rec["date"]."<br />";    

?>
<input type = 'submit' name='delete' value='delete'>&nbsp;&nbsp;
<input type = 'submit' name='edit' value='edit'>
</form>
<?
}
mysql_close();       
?> 
</body>
</html>
__________________

Please login or register to view this content. Registration is FREE

Check out the Facebook Clone build with Jcow SNS at
Please login or register to view this content. Registration is FREE
, it is free and it always will be
Falcone is offline
Reply With Quote
View Public Profile
 
Old 09-17-2007, 11:17 AM Re: radio button and mysql HELP PLEASE!
Skilled Talker

Posts: 65
Trades: 0
falcone thanks for the solution. it works.
just wanna to ask if i want to pass the radiobutton value can i just pass the value to another page using
PHP Code:
$a=$_POST['idnum'];
header("Location:edit.php?val="$a); 
am i correct?

i am really looking foward to learn php language.
thanks
leolim is offline
Reply With Quote
View Public Profile
 
Old 09-17-2007, 11:19 AM Re: radio button and mysql HELP PLEASE!
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
PHP Code:
$a=$_POST['idnum'];
header("Location:edit.php?val="$a); 
not quite...

you can just have:

PHP Code:
$a=$_POST['idnum'];
header("Location:edit.php?val=$a"); 
or if you want the Var seperated:
PHP Code:
$a=$_POST['idnum'];
header("Location:edit.php?val=".$a); 
Hope this helps
as always TP apprieciated

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-17-2007, 11:42 PM Re: radio button and mysql HELP PLEASE!
Skilled Talker

Posts: 65
Trades: 0
look at what i have created
PHP Code:
<html>
<head>
<title>My Data</title>
</head>
<body>
<?php 
mysql_connect
("localhost","root","");
mysql_select_db("school");
$query  "SELECT * FROM employee_data";
$result mysql_query($query) or die('Error, query failed');
$flag=0;
// print the student info in table
echo "<table border=2>"
while ( 
$r mysql_fetch_array($result) ) 

    foreach ( 
$r AS $key=>$value 
    { 
        
$ed $r['idnum'];
        if ( !
is_int($key) ) 
        { 
      if(
$flag==0)
  {
   echo 
"<td width=150 align=center ><input type='radio' name = 'idnum' value='$ed'></td>";
   
$flag=1;
  }  
     if(
$value!="")
     {
             echo 
"<td width=150>$value</td>";
     }
        } 
    }
    echo 
"</tr>"
 
$flag=0;

echo 
"</table>";  
if (isset(
$_POST["delete"])) {
    
mysql_query ("DELETE FROM employee_data WHERE idnum = ".$_POST["idnum"]);
} elseif(isset(
$_POST["edit"]))  { 
header("Location:edit.php");
}
?>
<table>
<tr>
<td>
<form method='post' action='<?= $_SERVER['PHP_SELF']; ?>'>
<table width="300" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><input type = 'submit' name='delete' value='delete'>&nbsp;&nbsp;
<input type = 'submit' name='edit' value='edit'></td>
</tr>
</table>
</form>
</body>
</html>
at edit.php
PHP Code:
<?php
include 'library/config.php';
include 
'library/opendb.php';
$val=$_POST['Lid'];
echo 
$val;
?>

why i can`t get the value from the radio button which i selected?
and why when i press edit the message appear
"Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\pt\ets.php:6) in c:\program files\easyphp1-8\www\pt\ets.php on line 42"


could any one help me to correct it pls and please tell me why the message appear

thankx
leolim is offline
Reply With Quote
View Public Profile
 
Old 09-18-2007, 06:03 AM Re: radio button and mysql HELP PLEASE!
Super Talker

Posts: 134
Trades: 0
because of the php function header() after the <html> tag
__________________

Please login or register to view this content. Registration is FREE

Check out the Facebook Clone build with Jcow SNS at
Please login or register to view this content. Registration is FREE
, it is free and it always will be
Falcone is offline
Reply With Quote
View Public Profile
 
Old 09-18-2007, 10:45 PM Re: radio button and mysql HELP PLEASE!
Skilled Talker

Posts: 65
Trades: 0
falcone do you mean put my entire php code before the html tag?
leolim is offline
Reply With Quote
View Public Profile
 
Old 09-19-2007, 02:48 AM Re: radio button and mysql HELP PLEASE!
killdude69's Avatar
Average Talker

Posts: 24
Name: Brandon Miller
Trades: 0
Use this to display edit and delete. You must assign a name and value to the radio button. Say you got the value from a MySQL database, you echo the radio input and assign the value recieved from the database.

Try This:
PHP Code:
<?php
  
/////////view.php/////////
 
 
 
  //Connect to DB
 
  //Display and goto edit
  
$result=mysql_query("SELECT * FROM tbl");
  while(
$row=mysql_fetch_array($result)){
    echo 
'<form action="edit.php" method="get">';
    echo 
'<input type="radio" name="idnum" value="'$row['idnum']'" />';
    echo 
'<input type="hidden" name="name" value="'$row['name']'" />';
    echo 
'<input type="hidden" name="address" value="'$row['address']'" />';
    echo 
'<input type="hidden" name="bio" value="'$row['bio']'"  />';
    echo 
$row['name'];
    echo 
$row['address'];
    echo 
'<input type="submit" name="sub" value="edit" />';
    echo 
'</form> <br /><br />';
  }
?>
___________________________
 
<?php
  
//edit.php
 
 
  //Connect to DB
 
  //Select and Edit
 
$id=$_GET['idnum'];
$sql "SELECT * FROM tbl WHERE idnum='"$id"';
mysql_query(
$sql);
if(isset(
$_POST['submit'])){
  
$name=$_POST['name'];
  
$address=$_POST['address'];
  
$bio=$_POST['bio'];
  
$sql2 = "UPDATE tbl SET name=$name SET address=$address SET bio=$bio WHERE idnum=$id";//add LIMIT statment if necessary
  mysql_query(
$sql2);
}
if(isset(
$_POST['delete'])){
  
$sql3 = "DELETE FROM tbl WHERE id=$id";
  mysql_query(
$sql3);
}
?>
<!-- Form values are from the GET vars -->
<form action="
<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  <input type="text" name="name" value="<?php echo $_GET['name']; ?> />
  <input type="text" name="address" value="<?php echo $_GET['address'];" />
  <textarea cols="
45" rows="6" name="bio">
      <?php echo 
$_GET['bio']; ?>
  </textarea>
  <input type="
submit" name="sub" value=" Save " />
  <input type="
submit" name="delete" value=" Delete " />
</form>
__________________
Huhh, well, you screwed up this time dumby.

Free PHP BBCode parser & inserter:
Please login or register to view this content. Registration is FREE
killdude69 is offline
Reply With Quote
View Public Profile
 
Old 09-19-2007, 07:21 AM Re: radio button and mysql HELP PLEASE!
Super Talker

Posts: 134
Trades: 0
Quote:
Originally Posted by leolim View Post
falcone do you mean put my entire php code before the html tag?
header(location:edit.php) has to be before the <html> tag
__________________

Please login or register to view this content. Registration is FREE

Check out the Facebook Clone build with Jcow SNS at
Please login or register to view this content. Registration is FREE
, it is free and it always will be
Falcone is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to radio button and mysql HELP PLEASE!

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.71432 seconds with 12 queries