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
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,063
    Thanks
    4
    Thanked 8 Times in 8 Posts

    Problem with MySQL squery

    I am having a problem on one page running a query. Similar code works connecting to other tables in the mySQL database. I have tried to echo the query on to the page to make sure that the variable in the WHERE clause has a value to it. Right now I am stumped. Any Ideas?

    my code
    PHP Code:
    <?php 
    session_start
    (); 
    header("Cache-control: private"); 
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/REC-html40/loose.dtd">
    <html>
    <head>
        <title>Add Match 3rd Page of 4</title>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
        <?php  include ("../common/color.php"); ?>
      <script language="JavaScript" src="../common/form.js" type="text/javascript"></script>
        <script language="JavaScript" src="../common/navigation.js" type="text/javascript"></script>
        <script language="Javascript" src="../common/djmb.js" type="text/javascript"></script>
    </head>
    <body>
    <?php 
    $sid 
    session_id();
    if(!isset(
    $_SESSION['username'])) {  
    include (
    "../common/main_menu.php");
    }else{
    include (
    "../common/main_menu_loggedin.php");
    }
    echo 
    "<br /><br /><br /><br /><br />\n"

    $userID $_SESSION['username'];
    $country $_POST["country"];
    $stateProv $_POST["state"];
    $title $_POST["title"];
    $myGender $_POST["myGender"];
    $myBirthday $_POST["myBirthday"];
    $myHair $_POST["myHair"];
    $myEyes $_POST["myEyes"];
    $myWhiskers $_POST["myWhiskers"];
    $myBuild $_POST["myBuild"];
    $tStatus $_POST["tStatus"];
    $myFeet $_POST["myFeet"];
    $myInches $_POST["myInches"];
    $myHeight = (($myFeet 12) + $myInches);
    $myDrink $_POST["MyDrink"];
    $mySmoke $_POST["mySmoke"];
    $myJob $_POST["myJob"];
    $aboutMe $_POST["AboutMe"];
    $myEthnic $_POST["myEthnic"];
    $myEducation $_POST["myEducation"];
    $myReligion $_POST["myReligion"];
    $myChurch $_POST["myChurch"];
    $myIncome $_POST["myIncome"];
    $myFood $_POST["myFood"];
    $myMarStat $_POST["myMarStat"];
    $myChildren $_POST["myChildren"];
    $myPolitics $_POST["myPolitics"];
    $live $_POST["Live"];
    $dreamHome $_POST["DreamHome"];
    $clean $_POST["Clean"];
    $freeTime $_POST["FreeTime"];
    $vacation $_POST["Vacation"];
    $movie $_POST["movie"];
    $myMusic $_POST["myMusic"];
    $cat $_POST["cat"];
    $dog $_POST["dog"];
    $fish $_POST["fish"];
    $reptile $_POST["reptile"];
    $bird $_POST["bird"];
    $exotic $_POST["exotic"];
    $rodent $_POST["rodent"];
    $horse $_POST["horse"];
    $other $_POST["other"];
    //get the age of the person
    $today getdate();
    $monthToday $today["mon"];
    $dayToday $today["mday"];
    $yearToday $today["year"];
    if ((
    $bMonth <= $monthToday) && ($bDay <= $dayToday)){ 
        
    $myAge = ($yearToday $bYear); 
    }else{
        
    $myAge = (($yearToday $bYear) -1);     
    }

    include (
    "common/dbconn.php");
    $query "SELECT myID FROM match WHERE myID = '$userID'";
    $query stripslashes($query);
    echo 
    $query."<br />";
    $result mysql_query($query) or die("Could not run query.");
    if (
    $row mysql_fetch_array($result)) {
    //record does exist
    //echo "record exists";
      
    $query "UPDATE match SET tStatus = '$tStatus',myGender= '$myGender',age= '$myAge',birthdate= '$myBirthdate',title= '$title',country= '$country',stateProv= '$stateProv',myHair= '$myHair',myEyes= '$myEyes',myWhiskers= '$myWhiskers',myBuild= '$myBuild',myFeet= '$myFeet',myInch= '$myInches',myHeight= '$myHeight',myDrink= '$myDrink',mySmoke= '$mySmoke',myJob= '$myJob',about= '$aboutMe',myEthnic= '$myEthnic',myEducation= '$myEducation',myReligion= '$myReligion', myAttend= '$myChurch',myIncome= '$myIncome',myFood= '$myFood',myMarStat= '$myMarStat',myChildren= '$myChildren',myPolitics= '$myPolitics',dreamHome= '$dreamHome',live= '$live',clean= '$clean',freeTime= '$freeTime',vacation= '$vacation',movie= '$movie',cat= '$cat',dog= '$dog',fish= '$fish',bird= '$bird',reptile= '$reptile',rodent= '$rodent',horse= '$horse',exotic= '$exotic',other= '$other',myMatch= '$myMatch' WHERE myID = '$userID'"
         
    $query stripslashes($query);
       
    //echo $query;
      
    $result mysql_query($query) or die("Unable to run query.");
      if(!
    $result){
           echo 
    "<center>Error updating the record: ".mysql_error()."</center>";
      }else{
      
      }
    }else{
      
    //record does not exist!!
        //echo "new record";
      
    $query "INSERT INTO match (myID,tStatus,myGender,age,birthdate,title,country,stateProv,myHair,myEyes,myWhiskers,myBuild,myFeet,myInch,myHeight,myDrink,mySmoke,myJob,about,myEthnic,myEducation,myReligion,myAttend,myIncome,myFood,myMarStat,myChildren,myPolitics,dreamHome,live,clean,freeTime,vacation,movie,myMusic,cat,dog,fish,bird,reptile,rodent,horse,exotic,other,myMatch) VALUES ('$userID', '$tStatus', '$myGender', '$myAge', '$myBirthday', '$title', '$country', '$stateProv', '$myHair', '$myEyes', '$myWhiskers', '$myBuild', '$myFeet', '$myInches', '$myHeight', '$myDrink', '$mySmoke', '$myJob', '$aboutMe', '$myEthnic', '$myEducation', '$myReligion', '$myChurch', '$myIncome', '$myFood', '$myMarStat', '$myChildren', '$myPolitics', '$dreamHome', '$live', '$clean', '$freeTime', '$vacation', '$movie', '$myMusic', '$cat', '$dog', '$fish', '$bird', '$reptile', '$rodent', '$horse', '$exotic', '$other', '$myMatch')";
      
    $query stripslashes($query);
       
    //echo $query;
      
    $result mysql_query($query) or die("Not able to run query.");
      if(!
    $result){
           echo 
    "<center>Error adding the record: ".mysql_error()."</center>";
      }else{

      }
    }
    ?>
    this result in the following :

    SELECT myID FROM match WHERE myID = 'Miranda'
    Could not run query.

  • #2
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    why don't you tell us the error you are experiencing...?

    this is how you can tell us the error so we can help you debug.
    Code:
      $result = mysql_query($query) or die(mysql_error());

  • #3
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,063
    Thanks
    4
    Thanked 8 Times in 8 Posts
    thanks it told me there was an error in the SQL statement. As you can see I had named the table match which must be a mySql keyword. I renamed the table in the database and it works now


  •  

    Posting Permissions

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