Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined _post using image as submit

Tags:

html

forms

php

im using a form to select from 3 images send a post to a php but the $_POST['stars']; is not getting there

<form action="components/update_score.php" method="POST">
    <input type="image" name="stars" src="imagenes/th/0.png" value="0" width="120" />
    <input type="image" name="stars" src="imagenes/th/1.png" value="1" width="120" />
    <input type="image" name="stars" src="imagenes/th/2.png" value="2" width="120" />
    <input type="image" name="stars" src="imagenes/th/3.png" value="3" width="120" />
    <input type="hidden" name="war_enemy" value="<?php echo $rws['war_enemy'];?>" />
    <input type="hidden" name="user_username" value="<?php echo $user_score;?>" />
    <input type="hidden" name="enemy_enemynumber" value="<?php echo $i;?>" />
</form>

and on the php

<?php
ini_set("display_errors",1);
session_start();
if(isset($_POST)){
   echo $_POST['stars'],'<br>';
   echo $_POST['war_enemy'],'<br>';
   echo $_POST['user_username'],'<br>';
   echo $_POST['enemy_enemynumber'],'<br>';
}    
?>   

sending this give me the Notice: Undefined index: stars i dont want to use a submit button i want to use the images to do so but cant find the way to send the post to the php any help is appreciated

like image 636
WarLion Avatar asked Jan 21 '26 04:01

WarLion


1 Answers

You have 3 images with the same name change their name or you can use an array renaming stars as stars[] and your code will be something like this:

foreach ($_POST['stars'] as $star) {
    echo $star;
}

Also instead of src you need to add your image at value and please delete the src as you are using an input.

like image 113
Akmal Arzhang Avatar answered Jan 23 '26 19:01

Akmal Arzhang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!