Jump to content

need some help with $_GET and javascript:ajaxpage('','');


Rizla

Recommended Posts

Hello,

 

i'm making this guestbook admin script for a client and i'm using an ajaxscript that loads external files into divs on my pages.

when a link is pressed it includes the file to the requested div like so <a href="javascript:ajaxpage('example.php','exaple_div');">[/url]

 

then we would need a div <div id="example_div></div> to represent the requested page.

now in order to make the edit function, you need to send the id of the db entry in a $_GET right?

 

so this is what i tried:

gbbeheer.php just retrieves data from my db and shows it and then at the end of every displayed entry there is an edit and delete button (link)

located the lower part of gbbeheer.php.

 

Now i wonder if this would work or am i completely doing it wrong???

atm i'm getting this error: "this is an errorQuery was empty" when i press the edit button.

 

gbbeheer.php:

<?php
include("../config.php");
?>

<div class="toevoegendiv">
    <table width="599" border="0" cellpadding="4" cellspacing="2">
      <tr>
        <td colspan="8" valign="top" class="container"><p class="title">Welkom op je beheer pagina voor jouw gastenboek.</p> </td>
      </tr>
      <tr>
  <td colspan="8">
  <div id="exec_div"></div>
  </td>
  </tr>
      <tr>
        <td width="20" class="menu"><p class="formtext">N°</p></td>
        <td width="224" class="menu"><p class="formtext">Naam</p></td>
        <td width="224" class="menu"><p class="formtext">Datum</p></td>
        <td width="450" class="menu"><p class="formtext">Website</p></td>
        <td width="450" class="menu"><p class="formtext">Bericht</p></td>
        <td width="450" class="menu"><p class="formtext">ip</p></td>
        <td width="224" class="menu"><p class="formtext">bewerken</p></td>
        <td width="224" class="menu"><p class="formtext">verwijderen</p></td>
      </tr>
  <?php
  $query = "SELECT * FROM guestbook ORDER BY ID DESC";
  $result = mysql_query($query)or die(mysql_error());
  while($r=mysql_fetch_array($result)) {
  extract($r);
  ?>
      <tr>
        <td class="menu"><?= $id ?></td>
        <td class="menu"><?= $author ?></td>
        <td class="menu"><?= $date ?></td>
        <td class="menu"><a href="<?= $website ?>" target="_blank"><?= $website ?></a></td>
        <td class="menu"><?= $bericht ?></td>
        <td class="menu"><?= $ip ?></td>
        <td class="btn"><a href="javascript:ajaxpage('gbentry.php?action=edit&id=$id','exec_div');">bewerken</a></td>
        <td class="btn"><a href="javascript:ajaxpage('gbentry.php?action=delete&id=$id','exec_div');">bewerken</a></td>
      </tr>
  <?php
  }
  ?>
      <tr>
        <td colspan="8" class="container"> </td>
      </tr>
    </table>
  </div>

-------------------------------------------------------------------------------------------

and then gbentry.php:

<?php
include("../config.php");
?>

<div class="toevoegendiv">
    <table width="599" border="0" cellpadding="4" cellspacing="2">
      <tr>
        <td colspan="8" valign="top" class="container"><p class="title">Welkom op je beheer pagina voor jouw gastenboek.</p> </td>
      </tr>
      <tr>
  <td colspan="8">
  <div id="exec_div"></div>
  </td>
  </tr>
      <tr>
        <td width="20" class="menu"><p class="formtext">N°</p></td>
        <td width="224" class="menu"><p class="formtext">Naam</p></td>
        <td width="224" class="menu"><p class="formtext">Datum</p></td>
        <td width="450" class="menu"><p class="formtext">Website</p></td>
        <td width="450" class="menu"><p class="formtext">Bericht</p></td>
        <td width="450" class="menu"><p class="formtext">ip</p></td>
        <td width="224" class="menu"><p class="formtext">bewerken</p></td>
        <td width="224" class="menu"><p class="formtext">verwijderen</p></td>
      </tr>
  <?php
  $query = "SELECT * FROM guestbook ORDER BY ID DESC";
  $result = mysql_query($query)or die(mysql_error());
  while($r=mysql_fetch_array($result)) {
  extract($r);
  ?>
      <tr>
        <td class="menu"><?= $id ?></td>
        <td class="menu"><?= $author ?></td>
        <td class="menu"><?= $date ?></td>
        <td class="menu"><a href="<?= $website ?>" target="_blank"><?= $website ?></a></td>
        <td class="menu"><?= $bericht ?></td>
        <td class="menu"><?= $ip ?></td>
        <td class="btn"><a href="javascript:ajaxpage('gbentry.php?action=edit&id=$id','exec_div');">bewerken</a></td>
        <td class="btn"><a href="javascript:ajaxpage('gbentry.php?action=delete&id=$id','exec_div');">bewerken</a></td>
      </tr>
  <?php
  }
  ?>
      <tr>
        <td colspan="8" class="container"> </td>
      </tr>
    </table>
  </div>

-------------------------------------------------------------------------------------------

 

thanks in advance Wink

greets Rizla

 

Link to comment
Share on other sites

when you do these 2 statements, you are not in php mode, you are in html mode:

<td class="btn"><a href="javascript:ajaxpage('gbentry.php?action=edit&id=$id','exec_div');">bewerken</a></td>
<td class="btn"><a href="javascript:ajaxpage('gbentry.php?action=delete&id=$id','exec_div');">bewerken</a></td>

--so therefore $id is printed as a string, not it's value.  Instead use:

<td class="btn"><a href="javascript:ajaxpage('gbentry.php?action=edit&id=<?= $id ?>','exec_div');">bewerken</a></td>
<td class="btn"><a href="javascript:ajaxpage('gbentry.php?action=delete&id=<?= $id ?>','exec_div');">bewerken</a></td>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.