...

View Full Version : getting a form to work in itself?



thesavior
01-06-2006, 01:38 AM
im using this code:


<?php

if( !isset($_SESSION['login_username'])){
header("Location: index.php?act=admin");
} else {
$_SESSION['login_username'] = $username;
mysql_connect ($dbhost, $dbusername, $dbuserpass);
mysql_select_db($dbname) or die(mysql_error());
$query = "SELECT * FROM $tuttable WHERE onoff='0' ORDER BY id DESC";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
echo
"<table style=\"clear: both;\">
<form action=\"#\" method=\"post\">
<tr>
<td rowspan=\"2\">
<img width=\"40\" height=\"40\" alt=\"preview\" src=\"".$row['image']."\" />
</td>
<td align=\"center\">
Title: <input type=\"text\" name=\"name\" value=\"".$row['title']."\" />
</td>
<td align=\"center\">
Author: <input type=\"text\" name=\"authorname\" value=\"".$row['author']."\" />
</td>
<td align=\"center\">
Tut-URL: <input type=\"text\" name=\"loca\" value=\"viewtut.php?id=".$row['id']."\" />
</td>
<td align=\"center\" rowspan=\"2\" colspan=\"2\">
<select name=\"approve\" id=\"approve\">
<option value=\"3\" selected=\"selected\">Edit</option>
<option value=\"1\">Approve</option>
<option value=\"0\">Leave as is</option>
<option value=\"2\">Delete</option>
</select>
<br />
<input type=\"hidden\" name=\"idnum\" value=\"".$row['id']."\" />
<input type=\"submit\" class=\"submit\" value=\"Go\" />
<br />
<input type=\"reset\" class=\"submit\" value=\"Reset\" />
</td>
</tr>
<tr>
<td colspan=\"1\">
<textarea name=\"descrip\">".$row['descr']."</textarea>
</td>
<td align=\"center\">
<input type=\"radio\" name=\"cat\" value=\"Photoshop\" checked/> Photoshop<br />
<input type=\"radio\" name=\"cat\" value=\"PHP\" /> PHP<br />
<input type=\"radio\" name=\"cat\" value=\"PSP\" /> PSP<br />
<input type=\"radio\" name=\"cat\" value=\"PSE\" /> PSE<br />
</td>
</tr>
<tr>
<td colspan=\"7\">
Preview Location:
<input type=\"text\" value=\"".$row['image']."\" name=\"preview\" size=\"55\" />
</td>
</tr>
</form>
</table>";
}
if ($_POST['approve'] == 1) {
// SQL to update row to be active
} else if ($_POST['approve'] == 2) {
// SQL to delete row
} else if ($_POST['approve'] == 3) {
// SQL to update row
$update = "UPDATE $tuttable = WHERE ".$row['image']."=".$row['image']."";
mysql_query($update);
}
}
?>
and if i click edit then go, it sends me back to the login form. Also, i don't think my sql for the update is correct. Can anyone fix this form?

ClubCosmic
01-06-2006, 01:58 AM
your using session vars but the code doesnt start a session.

<?php
session_start();

also, are you using the form name for the the action or the # symbol?

<form action=\"#\" method=\"post\"> i would try using the actual filename it's submitting to for testing.

i would also try

if (isset($_POST[submit])){
if ($_POST['approve'] == 1) {
// SQL to update row to be active
} else if ($_POST['approve'] == 2) {
// SQL to delete row
} else if ($_POST['approve'] == 3) {
// SQL to update row
$update = "UPDATE $tuttable = WHERE ".$row['image']."=".$row['image']."";
mysql_query($update);
}
}



good luck

thesavior
01-06-2006, 02:10 AM
this is being included in a page that does use session_start()

thesavior
01-08-2006, 02:12 AM
*bump*



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum