Jump to content

Jammokablammo

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Jammokablammo's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Brilliant! echoed the sql and discovered that i'd not declared $UnitID, so it wasn't a valid statement! Thank you very much ober!
  2. I don't really know what you mean... How do i echo the actual query? And what do you mean by "make sure that is the actual case of it as well."?
  3. Sorry folks, i went on holiday the day after i started this thread, and i was wrongly informed that there would be internet there! Now then... Sasa you little genius! It's always the little things i get wrong! That's fixed the redirect problem, but i'm still struggling with the data i'm accessing from the database. The idea is that for every checked checkbox, the sql statement will include that field. So if the checkbox is unchecked, it will just refer to an empty string. So the sql statement is built with the line: $sql = ("SELECT " . $SQLID . $SQLTE . $SQLS . $SQLCB . $SQLTC . $SQLP . " FROM Stages WHERE UnitID = '$UnitID'"); and i believe the query is then carried out by: $data = mysql_query($sql); Then the for loop: for ($i = 0; $i < $count; $i++) { $result = mysql_fetch_array( $data ); if (strcmp($SQLID,$blank) != 0) echo $result['UnitID']; and so on. So as far as i can tell, for every checked checkbox, the loop should run through once. and then the strings are compared, so in this case, if $SQLID isn't an empty string, then $result['UnitID'] should be echoed to the screen, which is where i get the problem. If i tell it to echo a normal string to screen, this works no problem, but echo $result['UnitID']; doesn't do a thing and i don't know why. UnitID is definately the name of the field in the database. Anyone got any ideas please?
  4. Hi, I'm having a bit of trouble with some code, was wondering if anyone could spot something obvious i'm missing? Code: <?php include_once('connection.php'); $username = $_POST['Username']; $paswd = $_POST['Password']; $count = 0; $SQLID = ''; $SQLTE = ''; $SQLS = ''; $SQLCB = ''; $SQLTC = ''; $SQLP = ''; $blank = ''; $i = 0; if ($_POST['UnitID']) { $SQLID = "UnitID"; $count++; echo $SQLID; } if ($_POST['TimeEntered']) { if ($count == 0) { $SQLTE = "TimeEntered"; } else { $SQLTE = ", TimeEntered"; } $count++; echo $SQLTE; } if ($_POST['Stage']) { if ($count == 0) { $SQLS = "Stage"; } else { $SQLS = ", Stage"; } $count++; echo $SQLS; } if ($_POST['CheckedBy']) { if ($count == 0) { $SQLCB = "CheckedBy"; } else { $SQLCB = ", CheckedBy"; } $count++; echo $SQLCB; } if ($_POST['TimeChecked']) { if ($count == 0) { $SQLTC = "TimeChecked"; } else { $SQLTC = ", TimeChecked"; } $count++; echo $SQLTC; } if ($_POST['Pass']) { if ($count == 0) { $SQLP = "Pass"; } else { $SQLP = ", Pass"; } $count++; echo $SQLP; } /*if (count == 0) { header("Location: reportManager.php"); }*/ $sql = ("SELECT " . $SQLID . $SQLTE . $SQLS . $SQLCB . $SQLTC . $SQLP . " FROM Stages WHERE UnitID = '$UnitID'"); $data = mysql_query($sql); for ($i = 0; $i < $count; $i++) { $result = mysql_fetch_array( $data ); if (strcmp($SQLID,$blank) != 0) echo $result['UnitID']; if (strcmp($SQLTE,$blank) != 0) echo $result['TimeEntered']; if (strcmp($SQLS,$blank) != 0) echo $result['Stage']; if (strcmp($SQLCB,$blank) != 0) echo $result['CheckedBy']; if (strcmp($SQLTC,$blank) != 0) echo $result['TimeChecked']; if (strcmp($SQLP,$blank) != 0) echo $result['Pass']; } ?> The if statements are definitely accessed, as if i change the echo $result['blah']; to just echo a string, it works no problem. So i'm pretty certain that there's a problem with $result, but all the things in the square brackets (teaching myself php so i don't really know what the technical term for anything is i'm afraid!) are the names of the fields in the database. Also, if i uncomment the if(count == 0) part, it always redirects to reportManager.php, even if count is equal to 6! I really can't get my head around that! Any help would be lovely!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.