Dear all, I have piece of code: $person_ID = array(); $day_ID = 0; for($i=0;$i<count($dayid);$i++){ echo "Day ID: ".$dayid[$i]."<br>"; $day_ID = $dayid[$i]; //$sql = "SELECT personID FROM time Where dayID=".$day_ID." AND frm=".$_POST['select_from']." AND to2=".$_POST['select_to']; //$sql = " SELECT personID FROM time Where dayID= ".$day_ID." AND frm=".$_POST['select_from']." AND to2= ".$_POST['select_to']; $sql = 'SELECT personID FROM time Where dayID="$day_ID" AND frm="$_POST[select_from]" AND to2="$_POST[select_to]"'; echo "SQL: ".$sql."<br>"; $selectPersonIDs = mysql_query($sql ); /* THIS LINE */ while($row = mysql_fetch_array($selectPersonIDs )) { echo "person id: ".$row['personID']."<br />"; $person_ID["$i"] = $row['personID']; echo "Person ID: ".$person_ID["$i"]."<br>"; } } PHP: and there is a problem in the line which have a comment with capital letters ... I don't know why? I don't know why BUT it's clearly that it doesn't accept substitution of variables which comes from the form using POST method or declared in the code
im not understanding ur question properly what is the issue can u explain in details its not captuing title wods ?
You have to clear up your syntax. The way it is now is pretty easy to make errors. Your error is that the $sql is using SINGLE QUOTES.. And you include variables in that, and single quoted strings DOES NOT parse variables. E.g.: <? $hey = "Elias"; echo 'Hey, $hey'; //Returns: Hey, $hey echo "Hey, $hey"; //Returns: Hey, Elias ?> Code (markup): $person_ID = array(); $day_ID = 0; for($i=0;$i<count($dayid);$i++){ echo "Day ID: ".$dayid[$i]."<br>"; $day_ID = $dayid[$i]; [B]$selectPersonIDs = mysql_query("SELECT * FROM time WHERE dayID = '".$day_ID."' AND frm = '".$_POST['select_from']."' AND to2 = '".$_POST['select_to']."'");[/B] while($row = mysql_fetch_array($selectPersonIDs )) { echo "person id: ".$row['personID']."<br />"; [B]$person_ID[$i][/B] = $row['personID']; echo "Person ID: ".[B]$person_ID[$i][/B]."<br>"; } } Code (markup): Furthermore, you might want to prepare your code against sql injections. As it is now, the code is VERY vulnerable for sql injections/hacking.
thank you all I modified the code to be: $person_ID = array(); $day_ID = 0; for($i=0;$i<count($dayid);$i++){ echo "Day ID: ".$dayid[$i]."<br>"; $day_ID = $dayid[$i]; //$sql = "SELECT personID FROM time Where dayID=".$day_ID." AND frm=".$_POST['select_from']." AND to2=".$_POST['select_to']; //$sql = " SELECT personID FROM time Where dayID= ".$day_ID." AND frm=".$_POST['select_from']." AND to2= ".$_POST['select_to']; /* New Line */ //$sql = "SELECT personID FROM time Where dayID='$day_ID' AND frm='$_POST[select_from]' AND to2='$_POST[select_to]'"; $sql = "SELECT personID FROM time Where dayID= ".$day_ID." AND frm= ".$_POST['select_from']." AND to2= ".$_POST['select_to']; echo "SQL: ".$sql."<br>"; $selectPersonIDs = mysql_query($sql ); /* new line */ while($row = mysql_fetch_assoc($selectPersonIDs )) { echo "person id: ".$row['personID']."<br />"; $person_ID["$i"] = $row['personID']; echo "Person ID: ".$person_ID["$i"]."<br>"; } } PHP: where the variables used are integers but the problem is: in the while loop I don't know what to do to solve this problem... thank you in advance
you dont have prob in while loop. There is some error in your query like you are using binding operator . while passing variable
Use this query instead: $sql = "SELECT personID FROM time WHERE dayID= '".$day_ID."' AND frm= '".$_POST['select_from']."' AND to2= '".$_POST['select_to']."'".; Code (markup): You HAVE to put strings into quotes - otherwise it will be treated as an int.
I run the following query: $sql = "SELECT personID FROM time WHERE dayID= '".$day_ID."' AND frm= '".$_POST['select_from']."' AND to2= '".$_POST['select_to']."'"; PHP: on MY SQL and it gave me the following error:
If dayID is expecting an integer then it's failing because if you look at the actual error you'll see the day is '23 ' not '23'. Also this line: $person_ID["$i"] = $row['personID']; should be: $person_ID[$i] = $row['personID'];
Finally I wrote the following $person_ID = array(); $day_ID = 0; for($i=0;$i<count($dayid);$i++){ echo "Day ID: ".$dayid[$i]."<br>"; $day_ID = $dayid[$i]; //$sql = "SELECT personID FROM time Where dayID=".$day_ID." AND frm=".$_POST['select_from']." AND to2=".$_POST['select_to']; //$sql = " SELECT personID FROM time Where dayID= ".$day_ID." AND frm=".$_POST['select_from']." AND to2= ".$_POST['select_to']; /* New Line */ //$sql = "SELECT personID FROM time Where dayID='$day_ID' AND frm='$_POST[select_from]' AND to2='$_POST[select_to]'"; //$sql = "SELECT personID FROM time Where dayID= ".$day_ID." AND frm= ".$_POST['select_from']." AND to2= ".$_POST['select_to']; // $sql = "SELECT personID FROM time WHERE dayID= '".$day_ID."' AND frm= '".$_POST['select_from']."' AND to2= '".$_POST['select_to']."'"; $sql = "SELECT personID FROM time WHERE dayID= ".$day_ID." AND frm= ".$_POST['select_from']." AND to2= ".$_POST['select_to']; echo "SQL: ".$sql."<br>"; $selectPersonIDs = mysql_query($sql ); /* new line */ while($row = mysql_fetch_array($selectPersonIDs )) { echo "person id: ".$row['personID']."<br />"; /* New Line ... */ // $person_ID[$i] = $row['personID']; $person_ID["$i"] = $row['personID']; echo "Person ID: ".$person_ID["$i"]."<br>"; } } PHP: and it gives me the following warring:
try this : $from = $_POST['select_from']; $to = $_POST['select_to']; $sql = "SELECT personID FROM time WHERE dayID='$day_ID' AND frm='$from' AND to2='$to' ";
Why don't you check for MySQL errors then? That will give you the exact reason on why it failed. $selectPersonIDs = mysql_query($sql)or die(mysql_error()); Code (markup):