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 3 of 3
  1. #1
    tek
    tek is offline
    New Coder
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    update mysql using a form

    I'm messing up. Tried some options, but I think I made it even worse...

    The update query won't work for my form.

    PHP Code:
    <html>
    <head>
    </head>
    <body>
    <form enctype="multipart/form-data" action="edit.php" method="POST">
    Id to edit: <input type="text" name="id"><br />
    New src: <input type="text" name="src"><br />
    New name: <input type="text" name="name"><br />
    New count: <input type="text" name="count"><br />
    New image: <input type="text" name="image"><br />
    Change category: <input type="text" name="cat"><br />
    <input type="submit" name="edit" value="edit"></form> <br>

    <?

    $location 
    'host';
    $database 'db'
    $username 'username'
    $password 'password'

    $conn mysql_connect("$location","$username","$password"); 
    if (!
    $conn) die ("Could not connect MySQL"); 
    mysql_select_db($database,$conn) or die ("Could not open database"); 

    if(isset(
    $_POST['edit']))
      {
        
    $sid            =    addslashes($_POST['id']);
        
    $ssrc        =    addslashes($_POST['src']);
        
    $sname        =    addslashes($_POST['name']);
        
    $scount        =    addslashes($_POST['count']);
        
    $simage        =    addslashes($_POST['image']);
        
    $scat        =    addslashes($_POST['cat']);
        
        
    mysql_query('UPDATE games SET src=$ssrc, name=$sname, count=$scount, image=$simage, cat=$scat WHERE id=$sid') or die (mysql_error());

        echo 
    'Je gegevens zijn succesvol ge-update<br>';
      }

    $query "select * from games order by id";
    $result mysql_query($query);
    ?>

    <?
             
    while ($link=mysql_fetch_array($result))
             {
             echo 
    '&nbsp;&nbsp;'.$link[id].' <a href="'.$PHP_SELF.'/games.php?id='.$link[id].'">'.$link[name].'</a> - '.$link[src].' - '.$link[name].' - '.$link[imgsrc].' - '.$link[cat].'<br>';
             }
    ?>
    </body>
    </html>

  • #2
    New Coder
    Join Date
    Feb 2006
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this instead, you have to put '' around varibles being entered into databases unless they are numbers!!



    PHP Code:
    mysql_query("UPDATE games SET src='$ssrc', name='$sname', count='$scount', image='$simage', cat='$scat' WHERE id='$sid'") or die (mysql_error()); 
    I think that will work for ya!!

  • #3
    tek
    tek is offline
    New Coder
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I knew it was some small thing... thanks


  •  

    Posting Permissions

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