March 18, 2012

i want to get data from textbox in php

Question by vishal5721

I hav created a group of textboxes using a loop and its names are unique and names are assigned using variable ( like ). Then How can i retrieve the values in that textboxes after a button click with in a loop. Really I cant move from here. Can anyone plz help me..
Part of the my code is given below

$q1="select * from result where s_id=$sid";
$res1=mysql_query($q1,$link) or die($q1);
echo '<form action="editresultprofile.php?sid=$sid">';
while($row1=mysql_fetch_assoc($res1))
    {
    echo '<td><input type="text" name='.$row1['sub_name'].' class="textfield" value='.$row1['result'].'></td>';
    }
    echo '<input type="submit" value="update" ></form>';

Answer by Starx

It is not possible through PHP. You have use javascript to get the values in the textbox at realtime.

But using php, you have submit the form first, and then only you will get the data on the page its submit the data too. For example as per your question, only editresultprofile.php will be able to get the data values.

On editresultprofile.php, you can do

$name = $_POST['thesubname']; //You have to change the name to what is reflected on your case

However, if you use javascript, you can get the values as they were typed, before submitting the form.

function getValues(){
  var tbox = document.getElementById('yourtextboxid');
  alert(tbox.value);
  return false; //stop the submisison
}

Attach the function in the onSubmit event of the form.

<form onsubmit="return getValues()" >

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!