SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Update Table Problem

    I have created 2 pages. The first page there is code on there that grabs some data from the database and displays in it a table. The purpose of this is to allow the user to update the data if there is any change. Here is the code for that page called "update_club.php"

    Update_club.php

    Code:
    <?
    session_start();
    $_SESSION['userid']=$userid;
    echo "$_SESSION[userid]'s Account";
    include "config.php";
    include "footer.inc.html.php";
    $mytitle = $_SESSION[userid];
    $pagetitle = $mytitle;
    include "menu.php";
    ?>
    
    <?php
       
    $data = "SELECT * FROM create_club WHERE `userid` = '$_SESSION[userid]'";;
    
    $query = mysql_query($data);
      
    $data2 = mysql_fetch_array($query);
     
    ?>
    
    <html>
    <head>
    <title>Update Club</title>
     </head>
    
    <body>
    
    <br>
    <form name="form" method="POST" action="update_club2.php"> 
      League: <input type="text" value="<?php echo $data2['category']?>"/> </br>
      Club: <input type="text" value="<?php echo $data2['subcategory']?>"/> </br>
      Version: <input type="text" value="<?php echo $data2['version']?>"/> <br>
      Year: <input type="text" value="<?php echo $data2['start_year']?>"/> <br>
    Console: <input type="text" value="<?php echo $data2['console']?>"/> <br>
    Difficulty: <input type="text" value="<?php echo $data2['difficulty']?>"/> <br>
    Half Length: <input type="text" value="<?php echo $data2['half_length']?>"/> <br>
    Club Prestige: <input type="text" value="<?php echo $data2['club_prestige']?>"/> <br>
     <input type="submit"  value="Update">
    </form>
    
    </body>
    
    </html>
    Upon clicking "Update" the intent is to update the data in the database. Here is the code that is supposed to do so, called "update_club2.php"

    Update_club2.php

    Code:
    <?
    session_start();
    $_SESSION['userid']=$userid;
    echo "$_SESSION[userid]'s Account";
    include "config.php";
    include "footer.inc.html.php";
    $mytitle = $_SESSION[userid];
    $pagetitle = $mytitle;
    include "menu.php";
    ?>
    <?
    
    $league=$_POST['category'];
    $club=$_POST['subcategory'];
    $fifaversion=$_POST['version'];
    $startyear=$_POST['start_year'];
    $console=$_POST['console'];
    $difficulty=$_POST['difficulty'];
    $halflength=$_POST['half_length'];
    $clubprestige=$_POST['club_prestige'];
    
    mysql_connect('****','****','****');
    @mysql_select_db(TABLE_Name) or die( "Unable to select database");
    
    $qry = "UPDATE create_club SET League = '$league', Club = '$club', Version = '$fifaversion', Year = '$startyear', Console = '$console', Difficulty = '$difficulty', Half Length = '$halflength', Club Prestige = '$clubprestige' WHERE userid = '$userid'"; 
      $query = mysql_query($data) or die("Couldn't execute query. ". mysql_error()); 
    echo "Record Updated";
    
    ?>
    Every update I have attempted has resulted in the following message

    "Couldn't execute query. Query was empty"

    Can anyone help me out with this?

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $query = mysql_query($data);

    you haven't set $data

    shouldn't it be:
    $query = mysql_query($qry);

    ??

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    In the second code snippet, the string containing the query is called $qry, yet you're trying to execute the query stored in $data (which is nothing).
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  4. #4
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the catch but now I get the following message:

    "Couldn't execute query. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Length='', Club Prestige='' WHERE userid='XXXXX'' at line 1"

    Any suggestions?

  5. #5
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    Half Length = '$halflength'
    Is the field actually 'Half Length'? In that case, backtick it:
    Code:
    `Half Length` = '$halflength'
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  6. #6
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks ark that worked.

    Now, after fixing another issue to ensure that the table names match up with the database I am getting blank data whenever I hit update.

    update_club2.php

    Code:
    <?
    session_start();
    $_SESSION['userid']=$userid;
    echo "$_SESSION[userid]'s Account";
    include "config.php";
    include "footer.inc.html.php";
    include "menu.php";
    ?>
    <?
    
    $league=$_POST['category'];
    $club=$_POST['subcategory'];
    $fifaversion=$_POST['version'];
    $startyear=$_POST['start_year'];
    $console=$_POST['console'];
    $difficulty=$_POST['difficulty'];
    $halflength=$_POST['half_length'];
    $clubprestige=$_POST['club_prestige'];
    
    mysql_connect('****','****','****');
    @mysql_select_db(kgx2thez_TEST) or die( "Unable to select database");
    
    $qry = "UPDATE create_club SET category='$league', subcategory='$club',Version='$fifaversion', start_year='$startyear', Console='$console', Difficulty='$difficulty', `half_length` ='$halflength', `club_prestige`='$clubprestige' WHERE userid='$userid'"; 
      $query = mysql_query($qry) or die("Couldn't execute query. ". mysql_error());
    echo "Record Updated";
    
    ?>
    Basically I am able to enter in a new club on a page. On the update club page I am able to successfully pull the same club data but when I click "Update" it sets all of my data for that row to 0.

    Any suggestions?

  7. #7
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any help.


Bookmarks

Posting Permissions

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