Jump to content

[SOLVED] Updating db with a button


Lee-Bartlett

Recommended Posts

Lee-Bartlett:

<?php
echo <form action="'.basename($_SERVER['PHP_SELF']).'" method="POST">
echo '<input type="hidden" name="id" value="' . $row['id'] . '">';
echo "<td> <input type=\"submit\" value=\"update\" name=\"updatebutton\" > </td>" 
echo "<td> <input type=\"submit\" value=\"update\" name=\"updatebutton\" > </td>"
echo "<td><input type=\"submit\" value=\"delete\" name=\"deletebutton\" > </td>"
echo "</form></td>"
echo "</tr>"

 

CroNiX:

Your syntax is all messed up.  You are missing quotes and semicolons everywhere...

like your first echo doesn't start or end with a quote....you don't have a semicolon after each statement...

Is this more cleaned up ?

 

<?php 
echo "<form action="'.basename($_SERVER['PHP_SELF']).'" method="POST">"; (this is line 57)
echo "<input type=\"hidden\" name=\"id\" value=\" . $row['id'] . \">";
echo "<td> <input type=\"submit\" value=\"update\" name=\"updatebutton\" > </td>"; 
echo "<td> <input type=\"submit\" value=\"update\" name=\"updatebutton\" > </td>";
echo "<td><input type=\"submit\" value=\"delete\" name=\"deletebutton\" > </td>";
echo "</form></td>";
echo "</tr>";
?>

 

error message im getting is

 

 

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/nexodom/public_html/website/admin/du.php on line 57

Mostly cleaned up :)

This:

echo "<form action="'.basename($_SERVER['PHP_SELF']).'" method="POST">"; (this is line 57)

should be:

echo "<form action=\"".basename($_SERVER['PHP_SELF'])."\" method="POST">"; //some single quotes in there messing it up

Now i got

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/nexodom/public_html/website/admin/du.php on line 58

 

maybe i should chaqnge that line all together?

 

its this line here

 

echo "<input type=\"hidden\" name=\"id\" value=\" . $row['id'] . \">";

The problem is in this part:

value=\" . $row['id'] . \">";

You escaped the quote but didn't add an end quote here: value=\"

And same thing here, you didn't start the quote and then escape a quote, you just escaped a quote: $row['id'] . \">";

 

much simpler to do:

[echo '<input type="hidden" name="id" value="' . $row['id'] . '">';

or even better, do it in html and then add the php where you need it.  You are confusing yourself.

?> (end the php)
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
<?php //...continue php code

If i do it in html, how do i get it to automatically enter all these submit buttons so when a new entry is put in, there is one in that row to.

 

now im getting this error message, Parse error: syntax error, unexpected '[' in /home/nexodom/public_html/website/admin/du.php on line 58

 

i cant see these ending. How would you add an update button to a echoed database? so when i click that button, it pulls the data from the row it is and alows me to update it on my update page

I didnt see that, must be late, ok thats got all of the form showing, how would i go about making the update button actually take the record in the row and go to my update page. I really appreciate all the effort here, i know i must be a pain :(

Now that you've gone through all of that, let me say it would be easier to use a link instead of a form :)

 

If you replaced the whole form thing we were just working on with something like:

echo '<a href="http://mysite.com/process.php?action=update&id=' . $row['id'] . '">Update</a>';
echo " &nbsp";
echo '<a href="http://mysite.com/process.php?action=delete&id=' . $row['id'] . '">Delete</a>';

Obviously process.php should be changed to your script name.

Then in your process.php:

$action = isset($_GET['action']) ? $_GET['action'] : "";
$id = isset($_GET['id']) ? $_GET['id'] : "";

if(!empty($action) && !empty($id))  //check to see if $action and $id have values
{
    switch($action)
    {
        case "update":
            //grab the data from the db using the $id, create a form and populate the form 'values' with the data;
            //then when you submit the form have it 'UPDATE' the database where the id=$id
            break;
        case "delete":
            //prompt if user is sure they want to delete
            //then just DELETE it from the database using WHERE id=$id
            break;
    }
}

 

Those are the basics, I don't want to write it all out...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.