View Full Version : Problem with MySQL squery

09-23-2004, 11:53 PM
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

header("Cache-control: private");
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<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>
$sid = session_id();
if(!isset($_SESSION['username'])) {
include ("../common/main_menu.php");
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);
$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.");
echo "<center>Error updating the record: ".mysql_error()."</center>";

//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,myFoo d,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.");
echo "<center>Error adding the record: ".mysql_error()."</center>";


this result in the following :

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

09-24-2004, 01:35 AM
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.

$result = mysql_query($query) or die(mysql_error());

09-24-2004, 06:16 AM
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 :thumbsup:

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum