php - Form Values not getting submitted -
i have following php code
<form action="admin.php" method="post"> <?php $conn=mysqli_connect("localhost","root","vravi","mrconnect"); if(!$conn) { echo "error establishing connection"; } $sql="select userid,useremail users order userid"; $result=mysqli_query($conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_assoc($result)) { echo $row["userid"]; echo $row["useremail"]." ".'<input type=\"text\" name=\"name[]\"/>'."</br>"; } echo '<button type=\"submit\" name=\"submit\" value=\"submit\">'.submit.'</button></br>'; } ?> </form>
which gives following output in browser.
now have 2 questions.
1)when try insert values in 1 of textboxes , click submit button in bottom, values not getting submitted.
below admin.php php file.
<?php if(isset($_post['submit'])) { echo "submitted"; } else { echo "not submitted"; } ?>
2)now second question that, want email id submitted through form, normal text, can tell me how that?
there few things change:
- you don't need escape double quotes when between single quotes
- use
name="name['.$row["userid"].']"
change<button...
<input type="submit"...
your page this:
<form action="admin.php" method="post"> <?php $conn=mysqli_connect("localhost","root","vravi","mrconnect"); if(!$conn) { echo "error establishing connection"; } $sql="select userid,useremail users order userid"; $result=mysqli_query($conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_assoc($result)) { echo $row["userid"] . ' ' . $row["useremail"] ." "; echo '<input type="text" name="name['.$row["userid"].']" />'."<br />"; } echo '<button type="submit" name="submit" value="submit">submit</button></br>'; } ?> </form>
then, when form submitted admin.php, can loop name
.
<?php if( $_server['request_method'] == 'post' ) { foreach( $_post['name'] $data => $value ) { echo $data . ': ' . $value . '<br />'; // output 2: 12 } } ?>
in example echo user id , submitted value. ofcourse save database.
Comments
Post a Comment