Jump to content

Problem with TMS...


miligraf

Recommended Posts

hello there, im new to the forum and to PHP as well. Your tutorials have helped me get around it and understand it lil by lil hehehe
the thing is that with the help of different tutorials and taking them as a base, ive worked out a TMS (tutorial management system) but ive started over like 3 times cuz ive got to a dead-end, but i beleive that im kinda in the right way so i dont wanna start it all over again but i would like for you guys to help me if possible :)

in the admin panel, you can see all the tuts and some links to edit or delete them. ive added a tutorial so i could test it but the whenever i click to edit or delete, it says that the ID is missing...

and when i put the mouse over the button, i can see the link.

it should be: ...php?id=5

but it gives: ...php?id=

plz tell me which code you need to see, thanks for your help :D
Link to comment
Share on other sites

ok, this is the code of the admin panel in which you visualize all tutorials in database and gives you the options to Edit or Delete:

[code]<style type="text/css">
A:link {
    COLOR: #3E454B; TEXT-DECORATION: underline
}
A:active {
    COLOR: #3E454B; TEXT-DECORATION: none
}
A:visited {
    COLOR: #333333; TEXT-DECORATION: none
}
A:hover {
    COLOR: #3E454B; TEXT-DECORATION: underline
}
</style>
<?php
include('../conbd.php');
include ('../tutorial.php');

if(!isset($_GET['page'])){    
$page = 1;
}else{
$page = $_GET['page'];
}
$max_results = 10;                                        
$from = (($page * $max_results) - $max_results);

$query = "SELECT * FROM `tutoriales` ORDER BY id DESC LIMIT $from, $max_results";
$result = mysql_query($query)
or die("Error in query: $query . " . mysql_error());

echo '<a href="agregar.php">Agregar Tutorial</a>';

if(mysql_num_rows($result) > 0)
{
    while($row = mysql_fetch_row($result))
    {
    ?>
    <table width="100%">
        <tr>
            <td width="40"><img src="<?php echo $imagen; ?>" alt="<?php echo $titulo; ?>"></td>
            <td><span class='style20 Estilo3'><?php echo $id; ?>: <?php echo $titulo; ?><br /><a href="editar.php?id=<?php echo $id; ?>">Editar</a> | <a href="borrar.php?id=<?php echo $id; ?>" onClick="return confirm('¿Seguro que quieres borrarlo?')">Borrar</a></span></td>
        </tr>
    </table>
    <hr>
    <?php
    }

}
else
{
    echo 'No hay Tutoriales<hr class="news">';
}
echo '<center>';

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM tutoriales"),0);

$total_pages = ceil($total_results/$max_results);
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
}else{                  
echo "<a href='?page=$i'>$i</a> ";  
} }

echo '</center><hr>';
echo '<a href="agregar.php">Agregar Tutorial</a>';

mysql_close($connection);
?>[/code]

this is the tutorial.php in wich i got the click counter:

[code]<?
include ('conbd.php');

$query ="SELECT * from tutoriales where id='$id'";
$result = mysql_query($query) or die
("Could not execute query : $x." . mysql_error());

while ($row = mysql_fetch_array($result))
{
$id = $row['id'];
$titulo = $row['titulo'];
$imagen = $row['imagen'];
$clics = $row['clics'];
$descripcion = $row['descripcion'];
$enlace = $row['enlace'];
$autor = $row['autor'];

header('Location: '.$enlace);

$query ="update tutoriales set clics=clics+1 where id='$id'";
$result = mysql_query($query) or die
("Could not execute query : $x." . mysql_error());
}
?>[/code]

this is the add.php (i guess the problem is here, but cant find it...):

[code]<style type="text/css">
.Estilo3 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 9px;
    color: #333333;
}
</style>
<style type="text/css">
A:link {
    COLOR: #3E454B; TEXT-DECORATION: underline
}
A:active {
    COLOR: #3E454B; TEXT-DECORATION: none
}
A:visited {
    COLOR: #333333; TEXT-DECORATION: none
}
A:hover {
    COLOR: #3E454B; TEXT-DECORATION: underline
}
</style>
<?php
include ("../conbd.php");

if (!isset($_POST['submit']))
{
    ?>
    <span class='style20 Estilo3'>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <h2>Agregar Tutorial</h2>
    <table width="75%"  border="0">
      <tr>
        <th class="Estilo3"><div align="left"><strong>Titulo</strong></div></th>
        <th scope="col"><div align="right">
          <input name="titulo" type="text" class="Estilo3" size="100">
        </div></th>
      </tr>
      <tr>
        <td class="Estilo3"><div align="left"><strong>Imagen</strong></div></td>
        <td><div align="right">
          <input name="imagen" type="text" class="Estilo3" size="100">
        </div></td>
      </tr>
      <tr>
        <td class="Estilo3"><div align="left"><strong>Descripcion</strong></div></td>
        <td><div align="right">
          <textarea name="descripcion" cols="100" rows="5" class="Estilo3"></textarea>
        </div></td>
      </tr>
      <tr>
        <td class="Estilo3"><div align="left"><strong>Enlace</strong></div></td>
        <td><div align="right">
          <input name="enlace" type="text" class="Estilo3" id="enlace" value="" size="100">
        </div></td>
      </tr>
      <tr>
        <td class="Estilo3"><div align="left"><strong>Autor</strong></div></td>
        <td><div align="right">
          <input name="autor" type="text" class="Estilo3" id="autor" size="100">
        </div></td>
      </tr>
    </table>
    <h2>
      <input name="submit" type="Submit" value="Agregar">
      <input type="reset" value="Cancelar">
    </h2>
  </form>
    </span>
    <?php
}
else
{
    $query = "INSERT INTO tutoriales (titulo, imagen, descripcion, enlace, autor, timestamp) VALUES ( '".mysql_real_escape_string($titulo)."', '".mysql_real_escape_string($imagen)."', '".mysql_real_escape_string($descripcion)."', '".mysql_real_escape_string($enlace)."', '".mysql_real_escape_string($autor)."',  NOW())";
    mysql_query($query)or die(mysql_error());
    
    echo 'Tutorial agregado exitosamente, <a href="index.php">regresar</a>.';
}
mysql_close($connection);
?>[/code]

the edit.php:

[code]<style type="text/css">
.Estilo3 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 9px;
    color: #333333;
}
</style>
<style type="text/css">
A:link {
    COLOR: #3E454B; TEXT-DECORATION: underline
}
A:active {
    COLOR: #3E454B; TEXT-DECORATION: none
}
A:visited {
    COLOR: #333333; TEXT-DECORATION: none
}
A:hover {
    COLOR: #3E454B; TEXT-DECORATION: underline
}
</style>
<?php
include ("../conbd.php");
include ("../tutorial.php");

if (!isset($_POST['submit']))
{
    if ((!isset($_GET['id']) || trim($_GET['id']) == ''))
    {
    die ('Missing record ID!');
    }
    
    $id = $_GET['id'];
    $query = "SELECT * FROM tutoriales WHERE id = '$id'";
    $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
    if (mysql_num_rows($result) > 0)
    {
    $row = mysql_fetch_row($result);
    ?>
    <span class='style20 Estilo3'>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <h2>Editar Tutorial #<?php echo $row['id']; ?></h2>
    <table width="75%"  border="0">
      <tr class="Estilo3">
        <th scope="col"><div align="left"><strong>
          <input type="hidden" name="id" value="<?php echo $id; ?>">
  Titulo</strong></div></th>
        <th scope="col"><div align="right">
          <input value="<?php echo stripslashes($row['titulo']); ?>" name="titulo" type="text" size="100">
        </div></th>
      </tr>
      <tr class="Estilo3">
        <td><div align="left"><strong>Imagen</strong></div></td>
        <td><div align="right">
          <input value="<?php echo stripslashes($row['imagen']); ?>" name="imagen" type="text" size="100">
        </div></td>
      </tr>
      <tr class="Estilo3">
        <td><div align="left"><strong>Descripcion</strong></div></td>
        <td><div align="right">
          <textarea name="descripcion" cols="100" rows="5"><?php echo stripslashes($row['descripcion']); ?></textarea>
        </div></td>
      </tr>
      <tr class="Estilo3">
        <td><div align="left"><strong>Enlace</strong></div></td>
        <td><div align="right">
          <input name="enlace" type="text" value="<?php echo stripslashes($row['enlace']); ?>" size="100">
        </div></td>
      </tr>
      <tr class="Estilo3">
        <td><div align="left"><strong>Autor</strong></div></td>
        <td><div align="right">
          <input value="<?php echo stripslashes($row['autor']); ?>" name="autor" type="text" size="100">
        </div></td>
      </tr>
    </table>
    <h2>    
    <input name="submit" type="Submit" value="Cambiar">
    <input type="reset" value="Cancelar">
    </h2>
    </form>
    </span>
    <?php
    }
    else
    {
    echo 'Tutorial no encontrado!';
    }
}
else
{
$query = "UPDATE tutoriales SET name = '".mysql_real_escape_string($titulo)."', '".mysql_real_escape_string($imagen)."', '".mysql_real_escape_string($descripcion)."', '".mysql_real_escape_string($enlace)."', '".mysql_real_escape_string($autor)."', WHERE id = '$id'";
$result = mysql_query($query)or die(mysql_error());
echo 'Tutorial editado exitosamente, <a href="index.php">regresar</a>';
}


mysql_close($connection);
?>[/code]

and the delete.php:

[code]<?php
include ("../conbd.php");
include ("../tutorial.php");

if ((!isset($_GET['id']) || trim($_GET['id']) == ''))
{
    die('Missing record ID!');
}

$id = $_GET['id'];

$query = "DELETE FROM tutoriales WHERE id = '$id'";
$result = mysql_query($query)
or die ("Error in query : $query. " . mysql_error());

    echo 'El tutorial fue borrado';

mysql_close($connection);
?>[/code]

thank you!
Link to comment
Share on other sites

I have found out why your links are not returning an id value becuase you are using a variable called $id which doesnt even exist, as you are using the wrong variable/function to retrieve the tutorial id from the manual:
[code]if(mysql_num_rows($result) > 0)
{
    while($row = mysql_fetch_row($result))
    {
    ?>
    <table width="100%">
        <tr>
            <td width="40"><img src="<?php echo $imagen; ?>" alt="<?php echo $titulo; ?>"></td>
            <td><span class='style20 Estilo3'><?php echo $id; ?>: <?php echo $titulo; ?><br /><a href="editar.php?id=<?php echo $id; ?>">Editar</a> | <a href="borrar.php?id=<?php echo $id; ?>" onClick="return confirm('¿Seguro que quieres borrarlo?')">Borrar</a></span></td>
        </tr>
    </table>
    <hr>
    <?php
    }

}[/code] Notice your while loop you are using mysql_fetch_row. This will return variables as follows:
$row[0], $row[1], $row[2] etc depending on how many rows have been returned from the query. It does not return variables such as $titulo, $id.

Instead you will have to setup the variables $id and $titulo like so:
[code]    while($row = mysql_fetch_row($result))
    {
        $titulo = $row[0];
        $id = $row[1][/code]
Now your link should be showing the id.

If you are unsure have a look at how you are returning your mysql results in tutorial.php as that is the correct.
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.