-1

this is my code (full page: cust_edit.php):

<?
session_start(); 
ob_start();
include "../sql.php";
if (!$_SESSION['username']) {
    @include "login.php";
} else {
@include "top.php";
?>

<?
if (isset($_POST['submit'])) {
    $id = $_POST['id'];
    $name = $_POST['name'];
    $date = $_POST['date'];
    $text = $_POST['text'];

    mysql_query("UPDATE custs SET name='$name', date='$date', text='$text' WHERE id='$id'");
    echo '<p align="center"><b>Updated</b></p>';
}

$gid = $id;

if (!isset($gid)) { 
    $gid = addslashes($_GET['id']); 
}

$query = mysql_query("SELECT * FROM custs WHERE id='$gid'");
$x = mysql_fetch_array($query);
echo '
    <br />
    <form name="f" action="cust_edit.php?id='.$x['id'].'" method="post">
        <table border="0" cellspacing="1" width="100%">
            <tr>
                <td width="70%" id="submitright">
                    <input value="'.$x['name'].'" type="text" name="name" size="30" maxlength="50">
                </td>
            </tr>
            <tr>
                <td width="70%" id="submitright">
                    <input value="'.$x['date'].'" type="text" name="date" size="30" maxlength="50">
                </td>
            </tr>
            <tr>
                <td id="submitright">
                    <textarea class="ckeditor" name="text" dir="rtl" cols="80" style="width: 70%">'.$x['text'].'</textarea>
                </td>
            </tr>
            <tr>
                <td align="left" width="70%" id="submitright">
                    <input type="submit" value="Update">
                </td>
            </tr>
        </table>
        <input type="hidden" name="id" value="'.$gid.'">
    </form>';
}
?>
<?
@include "bottom.php";
?>

my problem is that when i'm running this script - and updating the page - the pages is showing up normally and the details shown up in the inputs - but when i click the "Update" button, nothing happens - the page is refreshing but the lines:

mysql_query("UPDATE custs SET name='$name', date='$date', text='$text' WHERE id='$id'");
echo '<p align="center"><b>Updated</b></p>';

are not running for some reason, can someone help me with that?

René Höhle
  • 26,716
  • 22
  • 73
  • 82

3 Answers3

2
<input type="submit" value="Update">

replace with

<input type="submit" name="submit" value="Update">
Patrick Aleman
  • 612
  • 6
  • 19
1

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

And also as others have mentioned don't use php short open tag. It will not support since PHP 5.4 and onward. Most of time it has discussed here also, php short_open_tag problem

Community
  • 1
  • 1
TNK
  • 4,263
  • 15
  • 58
  • 81
0
  1. Some webservers will not accept <?. Use <?php instead.
  2. Use mysqli (MySQL Improved Extension) instead of mysql
  3. Your submit don't have name attribute <input type="submit" name="submit" value="Update">. OR....

You can replace this line:

if (isset($_POST['submit'])) {

on this

if (isset($_POST['id'])) {
Jazi
  • 6,569
  • 13
  • 60
  • 92