0

I am new here and i trying to make some PHP page working but failed miserably. I am not very good with logic nor PHP, so please bear with my stupid question and my messy codes :)

I have array of textboxes with value and there are array of buttons next to it. what i want is each button capture specific value what i typed into the corresponding textbox

here's the piece of my code

<?php
  $data = mysql_query("SELECT * from tempimg"); 
  while($hasil = mysql_fetch_assoc($data)){   
    $i++;
  echo "<tr>
        <td align=center><input type= checkbox name=check[] value=$hasil[idFoto]</td>
        <td align=center><img src=$hasil[thumbPath]></td>
        <td align=center>$hasil[imgName]</td>
        <td align=center>$hasil[thumbPath]</td>
        <td align=center>$hasil[Path]</td>
        <td align=center>

        <input type=text align=center value=$hasil[imgLink] name=link[{$hasil['idFoto']}] id=link />

        <td align=center>
        <button type=submit onClick=\"return confirm('you clicked button  with ID: $hasil[idFoto] '+'value: '+(document.getElementById('link').value))\">
        <img src=images/sav.png alt=search-btn id=img />
        </button>
        </td>
        <td align=center><img src=images/del.png></img></td>";    
  }

      ?>

and here's the link of image for the PHP page I'm talking about

enter image description here

enter image description here

so I humbly request of help from people here, please help me.

EDIT: thanks to Mr. Barmar i manage to pop out the value of the text box inside the dialog box with the corresponding button,

here a new question, how to save the value from the text box that i got from clicking the corresponding button into the database?

or more simple, how to capture the value from the text box by using the button next to it and then post it on the screen using "echo"

11
  • Use javascript for this, read tutorials. Commented Jul 18, 2013 at 6:04
  • You have a key mistakes, you have placed the same ID for every element i.e. link this needs to be unique to each row. Commented Jul 18, 2013 at 6:06
  • Mr.Yogesh: i'm trying not use javascript Commented Jul 18, 2013 at 6:08
  • i am not very good with logic nor PHP. LIke a doctor who isn't very good with biology. Commented Jul 18, 2013 at 6:09
  • Mr.DevZero: can you please point out what my mistakes, i spend hours just to fix this but failed Commented Jul 18, 2013 at 6:09

1 Answer 1

1

You need to give all the id=XXX attributes unique values, by including $i in the ID. Then your onclick code can get the value of the input from the same row.

<?php
  $data = mysql_query("SELECT * from tempimg"); 
  while($hasil = mysql_fetch_assoc($data)){   
    $i++;
  echo "<tr>
        <td align='center'><input type='checkbox' name='check[]' value='$hasil[idFoto]'</td>
        <td align='center'><img src='$hasil[thumbPath]'></td>
        <td align='center'>$hasil[imgName]</td>
        <td align='center'>$hasil[thumbPath]</td>
        <td align='center'>$hasil[Path]</td>
        <td align='center'>

        <input type='text' align='center' value='$hasil[imgLink]' name='link[{$hasil['idFoto']}]' id='link$i' />

        <td align='center'>
        <button type='submit' onclick='return confirm(\"you clicked button  with ID: $hasil[idFoto] \"+\"value: \"+(document.getElementById(\"link$i\").value))'>
        <img src='images/sav.png' alt='search-btn' id='img$i' />
        </button>
        </td>
        <td align='center'><img src='images/del.png' /></td>";    
  }

      ?>

You should also put quotes around all attribute values.

Sign up to request clarification or add additional context in comments.

2 Comments

urm, sorry Mr.Barmar for being rude. But after i retype my codes as you said, the dialog box won't appear anymore. Then i reverted back my code, the dialog box works, and i try to add $i for attribute unique values, but again the dialog box stopped working EDIT: thank you very much Mr.Barmar, now it works :) i appreciate your scolding and your help :D
Mr.Barmar sorry to disturb you again. At the code above, we only get the value in the dialog box, if i want to save it to database, no atleast if i want to display it on screen using "echo" what should i do?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.