Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help me regarding update

    <?
    $con= mysql_connect("localhost","root","root");
    if(!$con)
    {
    die("connection failed:".mysql_error());
    }
    mysql_select_db("saran",$con);
    if($_POST['submit'] == 'Insert')
    {
    move_uploaded_file($_FILES["file"]["tmp_name"],"images/".$_FILES['file']['name']);
    $query = "INSERT INTO `student` (`name` ,`marks`, `image`) VALUES ('".$_POST['name']."', '".$_POST['marks']."','".$_FILES['file']['name']."')";
    mysql_query($query)or die(mysql_error());
    header('Location: all.php');
    }
    if($_POST['submit'] == 'Update')
    {
    if($_FILES['file']['name']=""||$_FILES['file']['name']=null)
    {
    move_uploaded_file($_FILES["file"]["tmp_name"],"images/".$_FILES['file']['name']);
    $query = "update student set name='".$_POST['name']."',marks=".$_POST['marks']." where id=".$_GET['id'] ;
    mysql_query($query)or die(mysql_error());
    header('Location: all.php');
    }
    else
    {
    $query = "update student set name='".$_POST['name']."',marks=".$_POST['marks']." ,image='".$_FILES['file']['name']."' where id=".$_GET['id'] ;
    mysql_query($query)or die(mysql_error());
    header('Location: all.php');
    }

    }
    if($_GET['action'] == 'delete')
    {
    mysql_query("DELETE FROM `student` WHERE `id` = ".$_GET['id'])or die(mysql_error());
    header('Location: all.php');
    }

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <body>
    <? if(($_GET["action"] == 'edit') || ($_GET['action'] == 'insert')){

    if($_GET["action"] == 'edit'){
    $sql = mysql_query("SELECT * FROM student WHERE id =".$_GET['id']);
    $sql_f = mysql_fetch_array($sql);
    }
    ?>
    <form action="" method="post" name="form2" enctype="multipart/form-data">
    <table align="center">
    <tr>
    <td>name</td>
    <td><input type="text" name="name" id="name" value="<?=$sql_f["name"]?>" /></td>
    </tr>
    <tr>
    <td>marks</td>
    <td><input type="text" name="marks" id="marks" value="<?=$sql_f["marks"]?>" /></td>

    </tr>
    <? if($_GET["action"] == 'edit'){ ?>
    <tr>
    <td colspan="2"><input type="file" id="file1" name="file1"/> </td>
    <td><img src="images/<?=$sql_f["image"]?>" height="20" width="20"/></td>
    <td colspan="2"><input type="submit" name="submit" value="Update" /></td>
    </tr>
    <? } ?>
    <? if($_GET["action"] == 'insert'){ ?>
    <tr>
    <td colspan="2"><input type="file" id="file" name="file"></td>
    <td colspan="2"><input type="submit" name="submit" value="Insert" /></td>
    </tr>
    <? } ?>
    </table>
    </form>
    <? } else {

    $result = mysql_query("select * from student order by Id DESC");
    ?>
    <form method="post" name="form1" action="">
    <table align="center" border="2">
    <tr>
    <td>Id</td>
    <td>name</td>
    <td>marks</td>
    <td>image</td>
    <td>Action</td>
    </tr>
    <?
    while($rec = mysql_fetch_array($result)){
    ?>
    <tr>
    <td><?=$rec["id"]?></td>
    <td><?=$rec["name"]?></td>
    <td><?=$rec["marks"]?></td>
    <td><img src="images/<?=$rec[image]?>" height="20" width="20"/></td>
    <td><a href="all.php?action=edit&id=<?=$rec["id"]?>" >Edit</a> &nbsp <a href="all.php?action=delete&id=<?=$rec["id"]?>" >delete</a></td>
    </tr>
    <?
    } ?>
    <tr>
    <td colspan="2"><a href="all.php?action=insert">Insert</a></td>
    </tr>
    <? }
    ?>
    </table>
    </form>
    </body>
    </html>
    this is my code to insert , update, delete data im db. but when i update image after clicking edit old image erasses but new image is not displayed. plz help me

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,700
    Thanks
    80
    Thanked 4,659 Times in 4,621 Posts
    So what does your DEBUG show you?

    What are the actual queries you are using, after substituting in values?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    So what does your DEBUG show you?

    What are the actual queries you are using, after substituting in values?
    there is no errors bro but image not updated

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,700
    Thanks
    80
    Thanked 4,659 Times in 4,621 Posts
    I didn't say there were any errors. I said what does your DEBUG show you?

    FOr example:
    Code:
    ...
        $query = "update student set name='".$_POST['name']."',marks=".$_POST['marks']." ,image='".$_FILES['file']['name']."' where id=".$_GET['id'] ;
        echo "<hr>DEBUG: " . $query . "<hr>\n";
        mysql_query($query)or die(mysql_error());
        // suppress the change to location while debugging
        // header('Location: all.php')
    ...
    I am guessing that maybe $_FILES['file']['name'] is not what it should be. So this will find out if I'm right. Or do the debugging however you choose. Use a debugger to step through the code, if you prefer. But do DEBUG.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,994
    Thanks
    120
    Thanked 76 Times in 76 Posts
    Allso you might click refresh a couple of times in browser & clear cache.
    If all the rest is working OK.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #6
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank u its working


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •