Jump to content

[SOLVED] Replace line into the textbox


deepson2

Recommended Posts

Hello,

 

I am working on the fill in the blank quiz. I am fetching questions and options from the database.So  using radio button user can enter his/her right choice answer like this

 

[quote

]A_________ is the basic structural and functional unit of the kidney

1)Neurone 2)Nephron 3)Cell 4)Ureter

 

On submit i am able to insert the record into my database. Now my question is can i replace the line which is coming from database as a text box, so when user inters something it ll go first into the text box and on submit i can add it into the database.

 

Can anyone tell me how can i replace line into the text box?

 

Thnaks in advance

Link to comment
Share on other sites

Thanks for your reply JonathanV,

 

I am sorry that you wont understand my post. But i just wanted to ask you that if i am fetching one question from the database which is having a line(-------) so can i replace that with text box?

 

Hope you understand what i am trying to ask you.

Link to comment
Share on other sites

Yes

 

check this code

 

<?
//$abbr='ad lib';
$a='___';
echo "$abbr";
$ab=str_replace('___', '<input type="text" name="d" value=""',$a);
echo "$ab";
?>

 

Now my question is how can i get radio buttons value into text box? and then on submit it will go into the database.

Link to comment
Share on other sites

You will have to submit your radiobuttons to your php file either using GET or POST and in your php file you will have to catch their values and put them in variables.

 

Then you can just change your code to :

 

$ab=str_replace('___', '<input type="text" name="d" value="' . $radiobuttonValue1 . $radiobuttonValue2 . '"',$a);

 

That's an example if you have 2 radiobuttons.

 

Oh and your opening php tag should be

<?php

instead of just

<?

!

I know developers should be all lazy and write as little code as possible to do as much work as possible but a basic understanding of the language is needed and can easily be required by doing some research  ;D

Link to comment
Share on other sites

Here is my main code

 

<?
$query= mysql_query( "SELECT * FROM fillintheblank WHERE startdate= '".date('Y-m-d')."' AND stopdate='".date('Y-m-d')."'");
       	 if(mysql_num_rows($query) > 0){
         while($row = mysql_fetch_assoc($query)){ ?>

   <?
$a =$row['question'];
//echo "$a";
if(preg_match("/__________/i",$a)){
echo "hello";
$ab=str_replace('___', '<input type="text" name="d" value=""',$a);

}
else{}

?>

     <table>
     <tr>
     <td> <?=$a;?> </td>
     </tr><tr><td>
     <?
 	$options=$row['answer'];
 	$string                   = explode(",",$options);
 	$total_count=count($string);
 	//echo "$total_count"; ?>


 		<?   for($i=0;$i<$total_count;$i++)
 		   { ?>
<input type="radio" name="RBGroup" value="<?php echo $string[$i]; ?>" onclick="Toggle('<?php echo $string[$i]; ?>')">
<?php echo $string[$i]; ?>

 	<div id="contents">
	 <div id="<?php echo $string[$i]; ?>" class="TA"><textarea><?php echo $string[$i]; ?></textarea></div>

</div>
 	<?php
      }
?>

 </td>
     </tr>
     <tr><td>
     <input type="submit" name="submit" value="submit">
     </td></tr>
     </table>
<? } } ?>

 

I tried using somthing like this. but no luck Can anyone see and tell me how can i repalce line from my question to text box?

Link to comment
Share on other sites

You've got a mistake here ...

 

<?   for($i=0;$i<$total_count;$i++)
             { ?>

 

Did you enable error reporting in your php.ini file ?

If so you shoul've been abled to see this error by yourself, if not, hurry up and enable it, it'll help you a lot!

 

You still didn't fix your php opening tag(s)!  ;)

 

I would advice you to take a deep breath, relax and then look at your code closely, it's full of tags being closed in seperate php fields etc ... couldn't possibly work.

Link to comment
Share on other sites

I would advice you to take a deep breath, relax and then look at your code closely, it's full of tags being closed in seperate php fields etc ... couldn't possibly work.

 

Done.  :D

 

Well, my code is working. have checked all the closing braces and everything.(except the line is not getting replace yet.)

 

here is code

 

<?
$link = mysql_connect('***', '**', '**')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('***') or die('Could not select database');
$query= mysql_query( "SELECT * FROM fillintheblank WHERE startdate= '".date('Y-m-d')."' AND stopdate='".date('Y-m-d')."'");
           if(mysql_num_rows($query) > 0){
         while($row = mysql_fetch_assoc($query)){ ?>

   <?
$a =$row['question'];
//echo "$a";
if(preg_match("/__________/i",$a)){
echo "hello";
$ab=str_replace('___', '<input type="text" name="d" value=""',$a);

}
else{}

?>

     <table>
     <tr>
     <td> <?=$a;?> </td>
     </tr><tr><td>
     <?
       $options=$row['answer'];
       $string                   = explode(",",$options);
       $total_count=count($string);
       //echo "$total_count"; ?>


          <?   for($i=0;$i<$total_count;$i++)
             { ?>
<input type="radio" name="RBGroup" value="<?php echo $string[$i]; ?>" onclick="Toggle('<?php echo $string[$i]; ?>')">
<?php echo $string[$i]; ?>

       <div id="contents">
       <div id="<?php echo $string[$i]; ?>" class="TA"><textarea><?php echo $string[$i]; ?></textarea></div>

</div>
       <?php
         }
?>

    </td>
     </tr>
     <tr><td>
     <input type="submit" name="submit" value="submit">
     </td></tr>
     </table>
<? } } ?>

Link to comment
Share on other sites

It took me 5 seconds to find these faults :

 

Opening php tags STILL not correct!

<?

 

An empty else tag, not really a fault but heck, it shouldn't be there anyway, keep your code clean!

else{}

 

Closing/opening curly braces in a seperate php field, no way that's gonna do anything at all ...

<?php
         }
?>

  <?   for($i=0;$i<$total_count;$i++)
             { ?>

 

I just feel as if I should notify you of the unpleasant feeling one encounters when trying to help someone only to notice that person isn't really putting any effort in things himself but is rather letting someone else do the dirty work.

Link to comment
Share on other sites

Just a little warning to OP. Some servers do not support or have turned of PHP short tags, also you may get conflics errors with XML tags (<?xml). Script compatibility will rise as an issue in the future for you, so you make it best to use full PHP tags as all the experts recommend to.

Link to comment
Share on other sites

Buddy it was just one of the part of my code so i guess

 

<?

this works perfectly fine for me.

 

secondly,

else {}

I don't find anything wrong here,as i was only testing my condition.

 

Both the thins  are not at all responsible if i consider that you are suggesting something concrete here.

 

So, i request you to be polite. No one here to ask you to do dirty works.

 

Well, i have solve my issue. if you would like to see it then

 

$a =$row['question'];
if(preg_match('/[|____|]/',$a))
{
	$ab=str_replace('____', '<input type="text" name="d" value="">',$a);
//echo "$ab";
}
?>
<table>
     <tr>
     <td> <?=$ab;?> </td>
</tr>
</table>

 

 

Link to comment
Share on other sites

Buddy it was just one of the part of my code so i guess

 

<?

this works perfectly fine for me.

 

secodly,

else {}

I dont find anything wrong here,as i was only testing my condintion.

 

Both the think are not at all resposible if i consider that you are suggesting somthing concrete.

 

So, i request you to be polite. No one here to ask you to do dirty works.

 

Well, i have solve my issue. if you would like to see it then

 

$a =$row['question'];
if(preg_match('/[|____|]/',$a))
{
	$ab=str_replace('____', '<input type="text" name="d" value="">',$a);
//echo "$ab";
}
?>
<table>
     <tr>
     <td> <?=$ab;?> </td>
</tr>
</table>

 

He was just trying to help you and if I were you I would listen to what he has to say. Your coding is sloppy and we are just saying that for your own good. It will come in handy in the future and you will surely thank us.

Link to comment
Share on other sites

phpSensei,

 

He was just trying to help you and if I were you I would listen to what he has to say. Your coding is sloppy and we are just saying that for your own good. It will come in handy in the future and you will surely thank us.

 

I was just typing to thank you as well as JonathanV. but got the notification of your new post.  If you think what i had said is harsh. I would like to say sorry to JonathanV.

 

Link to comment
Share on other sites

phpSensei,

 

He was just trying to help you and if I were you I would listen to what he has to say. Your coding is sloppy and we are just saying that for your own good. It will come in handy in the future and you will surely thank us.

 

I was just typing to thank you as well. If you think what i had said it harsh. I would like to say sorry here to jorden.

 

It wasn't harsh, you just didn't seem like you appreciated the free help this community gives. No problem though :)

Link to comment
Share on other sites

phpSensei,

 

He was just trying to help you and if I were you I would listen to what he has to say. Your coding is sloppy and we are just saying that for your own good. It will come in handy in the future and you will surely thank us.

 

I was just typing to thank you as well as JonathanV. but got the notification of your new post.  If you think what i had said is harsh. I would like to say sorry to JonathanV.

 

No problem, it's all good. I've been up for 30 hours and communication is quite hard with our English not being very great and all that so these conflicts occur.

 

Just pay attention to your code in the future, it'll save you from a lot of trouble.

 

I'm glad to see you figured out the issue on your own, good luck in your further coding  ;)

Link to comment
Share on other sites

No problem, it's all good. I've been up for 30 hours and communication is quite hard with our English not being very great and all that so these conflicts occur.

 

Thanks for understanding. I think you should take some sleep then. :D

 

Just pay attention to your code in the future, it'll save you from a lot of trouble.

 

Yes, i ll do that.

 

I'm glad to see you figured out the issue on your own, good luck in your further coding  ;)

 

Thanks for your help.  :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.