Tadziz Posted February 1, 2011 Share Posted February 1, 2011 I'm new in php and i need help. I have wrote script to show that is in my mysql table called 'irasas' if(isset($_POST['ri'])){ include "../valdymas/conf.php"; $result = mysql_query("SELECT * FROM irasas"); echo " <table border='1' class='sample'> <tr> <th>Numeris duomenų bazėje</th> <th>Įrašo sukūrimo data</th> <th>Name</th> <th>Tipas</th> <th>Miestas</th> <th style=\"width: 100px\"><form method='POST' action='".$_SERVER["PHP_SELF"]."'><input type='submit' name='sumbit' value='Delete'/></form></th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td><center>" . $row['id'] . "</center></td>"; echo "<td><center>" . $row['idejimo_data'] . "</center></td>"; echo "<td><a href=\"../valdymas/edit.php?topic=\"".$id."\">" . $row['name'] . "</a></td>"; echo "<td>" . $row['tipas'] . "</td>"; echo "<td>" . $row['miestas'] . "</td>"; echo "<td style=\"width: 50px\"><center><input type=\"checkbox\" name=\"deleted_items[]\" </center>"; echo "</tr>"; } echo '</table>'; $display_block='<form method="POST" action="../valdymas/edit.php"> <table> <col span="1" align="right"> <tr> <td><font color="blue">Enter number you want to edit:</font></td> <td><input type="text" name="id" size="50"></td> </tr> <tr> <td><input type="submit" name="sumbit" value="Edit"/></td> </tr> </table> </form>'; Now if i want to edit topic i have to enter ID of topic, and then i press EDIT, and open new page with all info and i can edit. But i wan to make that users and i don't need to enter numbers, but just press on topic name in table. As you can see here i tryed something to do, but... i don't have enought experience in php. echo "<td><a href=\"../valdymas/edit.php?topic=\"".$id."\">" . $row['name'] . "</a></td>"; And sorry if i had written something wrong , english is not my native language. Thank you for answer. Quote Link to comment Share on other sites More sharing options...
ChemicalBliss Posted February 1, 2011 Share Posted February 1, 2011 $id should be as it is above on this line: echo "<td><center>" . $row['id'] . "</center></td>"; eg, echo "<td><a href=\"../valdymas/edit.php?topic=\"".$row['id']."\">" . $row['name'] . "</a></td>"; hope this helps Quote Link to comment Share on other sites More sharing options...
requinix Posted February 1, 2011 Share Posted February 1, 2011 Partway there. You also need to get rid of the extra quote. They do not go inside URLs. no: ?topic="id yes: ?topic=id Quote Link to comment Share on other sites More sharing options...
Tadziz Posted February 1, 2011 Author Share Posted February 1, 2011 I don't understand. I have this line: echo "<td><a href=\"../valdymas/redaguoti.php?irasas=\"".$row['id']."\">" . $row['pavadinimas'] . "</a></td>"; But i when i press on topic name it redirect me in this url http://localhost/valdymas/redaguoti.php?irasas= . But withoud ID. And it gives me error : Undefined index: id in C:\Program Files\EasyPHP-5.3.4.0\www\Tikrasis muziejaus puslapis\valdymas\redaguoti.php on line 5 Code of redaguoti.php <?php //prisijungiam infomacija apie duomenu bazes prisijungima include "../valdymas/conf.php"; /////////////// $id=$_POST['id']; $query=" SELECT * FROM irasas WHERE id='$id'"; $result=mysql_query($query); $num=mysql_numrows($result); ///////// $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $idejimo_data=mysql_result($result,$i,"idejimo_data"); $redagavimo_data=mysql_result($result,$i,"redagavimo_data"); $pavadinimas=mysql_result($result,$i,"pavadinimas"); $miestas=mysql_result($result,$i,"miestas"); $tipas=mysql_result($result,$i,"tipas"); ++$i; mysql_close(); } ?> <html> <form action="../valdymas/atnaujinti.php" method="post"> Irašo numeris: <input type="" name="id" value="<?php echo $id; ?>" readonly> Idejimo data: <input type="text" name="idejimo_data" style="width: 300px" value="<?php echo $idejimo_data; ?>" readonly> Redagavimo data: <input type="text" name="idejimo_data" style="width: 300px" value="<?php echo $redagavimo_data; ?>" readonly><br> Pavadinimas: <input type="text" name="pavadinimas" style="width: 300px" value="<?php echo $pavadinimas; ?>"><br> Miestas: <input type="text" name="miestas" style="width: 300px" value="<?php echo $miestas; ?>"><br> Tipas: <input type="text" name="tipas" style="width: 300px" value="<?php echo $tipas; ?>"><br> <input type="submit" name="atnaujinti" value="Atnaujinti"> <a href="../vartotojas/redaktorius.php" ><input type="button" value="Grįžti atgal"></a> </form> </html> I feels very bad, that i ask you these questions but i really don't understand how to make it work. I even don't know how to write in english what i want to google answer :/ Quote Link to comment Share on other sites More sharing options...
Tadziz Posted February 1, 2011 Author Share Posted February 1, 2011 Ok. I manage to find out what why it didin't show ID numbers. It was becouse this line was written bad by me this is how it should be i think: echo '<td><a href="../valdymas/redaguoti.php?irasas='.$row['id'].'">' . $row['pavadinimas'] . '</a></td>'; But now when it redirect me in redaguoti.php still say that it don't know who is ID "Undefined index: id" on line 5 . In my older post i have writtent redaguoti.php code. Maybe someone could look to it and say what is wrong. Thank you. Quote Link to comment Share on other sites More sharing options...
Tadziz Posted February 1, 2011 Author Share Posted February 1, 2011 I have solved my problem there is how should look my redaguoti.php code. Maybe it will help someone in future <?php //prisijungiam infomacija apie duomenu bazes prisijungima include "../valdymas/conf.php"; /////////////// if(isset($_GET['irasas'])){ ///$id=$_POST["id"]; echo "<input type=\"hidden\" name=\"irasas\" value=\"".$_GET['irasas']."\" />"; $query=" SELECT * FROM irasas WHERE id='".$_GET['irasas']."'"; $result=mysql_query($query); $num=mysql_numrows($result); ///////// $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $idejimo_data=mysql_result($result,$i,"idejimo_data"); $redagavimo_data=mysql_result($result,$i,"redagavimo_data"); $pavadinimas=mysql_result($result,$i,"pavadinimas"); $miestas=mysql_result($result,$i,"miestas"); $tipas=mysql_result($result,$i,"tipas"); ++$i; mysql_close(); } } ?> <html> <form action="../valdymas/atnaujinti.php" method="post"> Irašo numeris: <input type="" name="id" value="<?php echo $id; ?>" readonly> Idejimo data: <input type="text" name="idejimo_data" style="width: 300px" value="<?php echo $idejimo_data; ?>" readonly> Redagavimo data: <input type="text" name="idejimo_data" style="width: 300px" value="<?php echo $redagavimo_data; ?>" readonly><br> Pavadinimas: <input type="text" name="pavadinimas" style="width: 300px" value="<?php echo $pavadinimas; ?>"><br> Miestas: <input type="text" name="miestas" style="width: 300px" value="<?php echo $miestas; ?>"><br> Tipas: <input type="text" name="tipas" style="width: 300px" value="<?php echo $tipas; ?>"><br> <input type="submit" name="atnaujinti" value="Atnaujinti"> <a href="../vartotojas/redaktorius.php" ><input type="button" value="Grįžti atgal"></a> </form> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.