g0liatH
10-02-2004, 08:27 PM
ok I'm following a tutorial on a news script with php, but instead of using one table, I want to use more tables. so everytime $table comes in the script, I have to create a form to let the script know which table I'll use.
This worked pretty well until I came to the edit page:
list.php (edited)
<form name="form2" method="post">
<table width="100%" border="0" cellspacing="3" cellpadding="0">
<tr>
<td colspan="2"><strong><font size="3">Posting form...</font></strong></td>
</tr>
<tr>
<td width="8%">Table:</td>
<td width="92%"><input name='table' type='text' id='table' size='30'></td>
</tr>
<tr>
<td> </td>
<td width="92%"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
<?php
if($_POST['table'] == td_news) {
include('db.php');
$table = $_POST['table'];
$q = mysql_query("SELECT * FROM $table ORDER BY id, date DESC");
echo "<table with='100%' cellspacing='2'>";
while($r=mysql_fetch_array($q)){
$id = $r["id"];
$title = $r["title"];
echo "<tr><td><b>$title - options: <a href=\"edit.php?id=$id\" target=\"_blank\">Edit post</a> |
<a href=\"delete.php?id=$id\" target=\"_blank\">Delete Post</a></td></tr>";
}
echo "</table>";
mysql_close($cnx);
}
?>
ok I can see the list with news if I enter the table, but then comes edit.php:
<?
include('db.php');
$table = $_COOKIE['table'];
$id = $_GET['id'];
$q = mysql_query("SELECT * FROM $table WHERE id='$id'");
$r = mysql_fetch_array($q);
$news = $r["news"];
echo "<form action=\"editprocess.php?id=$id\" method=\"post\">
<textarea id=\"news\" name=\"news\">$news</textarea><input type=\"submit\"
id=\"submit\"></form>";
?>
I tried about everything to get the table variable here, even cookies :mad:
can someone please help me?
also: Instead of the type form I want to have a list form so you can just select the right table. how can I do that?
help is appreciated :)
This worked pretty well until I came to the edit page:
list.php (edited)
<form name="form2" method="post">
<table width="100%" border="0" cellspacing="3" cellpadding="0">
<tr>
<td colspan="2"><strong><font size="3">Posting form...</font></strong></td>
</tr>
<tr>
<td width="8%">Table:</td>
<td width="92%"><input name='table' type='text' id='table' size='30'></td>
</tr>
<tr>
<td> </td>
<td width="92%"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
<?php
if($_POST['table'] == td_news) {
include('db.php');
$table = $_POST['table'];
$q = mysql_query("SELECT * FROM $table ORDER BY id, date DESC");
echo "<table with='100%' cellspacing='2'>";
while($r=mysql_fetch_array($q)){
$id = $r["id"];
$title = $r["title"];
echo "<tr><td><b>$title - options: <a href=\"edit.php?id=$id\" target=\"_blank\">Edit post</a> |
<a href=\"delete.php?id=$id\" target=\"_blank\">Delete Post</a></td></tr>";
}
echo "</table>";
mysql_close($cnx);
}
?>
ok I can see the list with news if I enter the table, but then comes edit.php:
<?
include('db.php');
$table = $_COOKIE['table'];
$id = $_GET['id'];
$q = mysql_query("SELECT * FROM $table WHERE id='$id'");
$r = mysql_fetch_array($q);
$news = $r["news"];
echo "<form action=\"editprocess.php?id=$id\" method=\"post\">
<textarea id=\"news\" name=\"news\">$news</textarea><input type=\"submit\"
id=\"submit\"></form>";
?>
I tried about everything to get the table variable here, even cookies :mad:
can someone please help me?
also: Instead of the type form I want to have a list form so you can just select the right table. how can I do that?
help is appreciated :)