Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to make an admin panel

Status
Not open for further replies.

captlid

Technical User
Oct 27, 2004
82
US
ok I am trying to make something really basic.... (php 4.3.9 mysql 4.0)

The admin panel consists of:
The view and add features work.

The edit feature refuses to do anything.
The delete feature only works as a link with a get method.
I want it to work as a post method with a submit button.

The other thing I cant figure out is why in the edit area, the second input box doesnt show all the data.

For example original data
<input type=text name=link value=Some Words>
in the Edit window it shows
<input type=text name=link value=Some>
I ran print_r($_POST) when submitting an edit and all the variables have the proper data in them, it just refuses to update the new data.

Code:
//top three links for viewing/adding/editing&deleting
<a href="links.php">View</a> <a href="links.php?action=add">Add</a> <a href="links.php?action=edit">Edit</a>
<br><br>

<? 
mysql_connect("localhost", "root"); //connection works fine
mysql_select_db("database"); //db exists

$result = mysql_query("select * from table");

//edit data, data is pre-filled, or delete 
if ($_GET['action'] == edit) {
$delete = $_POST['delete'];
//if ($_GET['action'] == del) { mysql_query("delete from table where id=".$id." limit 1");  }
if ($delete) { mysql_query("delete from table where id=".$id." limit 1");}

while ($row = mysql_fetch_assoc($result)) {
$id = $row[id];
echo"<form method=\"post\" action=\"links.php?action=edit\">
<input type=text value=$row[url] name=url>
<input type=text value=$row[website] name=website>
<input type=submit value=Edit name=modify>
<input type=submit value=Delete name=delete>
<input type=hidden value=$id name=id>
<a href=links.php?action=del&id=$id>Delete</a><br>
<textarea name=description rows=7 cols=40 style=\"margin:0;padding:0\">$row[description]</textarea></form>";

if ($_POST['modify']) mysql_query("update table set url='".$url."', set website='".$website."', set description='".$description."' where id = '".$id."' limit 1");

print_r($_POST); } //while
} //if bracket 

?>
 
As for the second thing, html requires values with spaces in them to ge quoted. If they are not quoted, html has no way of knowing when one attribute ends and another begins. You will see that changing your code into:
Code:
echo '<input type="text" value="' . $row['website'] . '" name="website" />';
will make it behave correctly.

Also, you are assinging stuff to $delete and then checking if it is true. That will probably end up in always evaluating true. Where do you get $id from? Isn't that submitted by the form as well? Why are you using correct $_POST array for checking which button has been pressed but not using the array for accessing $url or $website? A bunch of problems that need be resolved.
 
Ok I fixed quotes now the second text input outputs.

Where do you get $id from? Isn't that submitted by the form as well? Why are you using correct $_POST array for checking which button has been pressed but not using the array for accessing $url or $website?

$id = $row[id]; //unique identifier for each record in the database.
Form recieves it supposedly ;)
I dont understand your third question. Thanks,
Code:
if ($_GET['action'] == edit) {
$delete = $_POST['delete'];
//if ($_GET['action'] == del) { mysql_query("delete from links where id=".$id." limit 1");  }
if ($delete) { mysql_query("delete from links where id=".$id." limit 1");}
while ($row = mysql_fetch_assoc($result)) {
$id = $row[id]; ?>
 <form method="post" action="links.php?action=edit">
<input type="text" value="<?=$row[url]?>" name="url">
<input type="text" value="<?=$row[website]?>" name="website">
<input type="submit" value="Edit" name="modify">
<input type="submit" value="Delete" name="delete">
<input type="hidden" value="<?=$id?>" name="id">
<a href="links.php?action=del&id=<?=$id?>">Delete</a><br>
<textarea name="description" rows="7" cols="40" style="margin:0;padding:0"><?=$row[description]?></textarea></form>
<?
if ($_POST['modify']) mysql_query("update links set url='".$url."', set website='".$website."', set description='".$description."' where id = '".$id."' limit 1");

print_r($_POST);}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top