Jump to content

Recommended Posts

Hi ALL

Can someone please tell me why isn't my select query working properly, there are NO errors but its bringing out all the records even those are NOT user_id = id.

Same query I'm checking it with phpMyAdmin and it works like charm.Its been three whole days can some take me out of this misery.

 

Thanks

Zed

function validation(){

$job_id = $_POST['job_id'];
$user_id = $_POST['user_id'];
$typeOfcustomer = $_POST['typeOfcustomer'];
$typeOfvehicle = $_POST['typeOfvehicle'];
$noOfVehicle = $_POST['noOfVehicle'];
$regul = $_POST['regul'];
$cust_name = $_POST['cust_name'];
$cust_address = $_POST['cust_address'];
$post_code = $_POST['post_code'];
$cust_tel = $_POST['cust_tel'];
$des = $_POST['des'];
$dateDay = $_POST['dateDay'];
$dateMO = $_POST['dateMO'];
$dateYr = $_POST['dateYr'];
$timeHr = $_POST['timeHr'];
$timeMin = $_POST['timeMin'];

$query = "INSERT INTO blockbook  VALUES
(NULL,'$user_id','$typeOfcustomer',
'$typeOfvehicle','$noOfVehicle','$regul','$cust_name','$cust_address','$post_code','$cust_tel',
'$des','$dateDay','$dateMO','$dateYr','$timeHr','$timeMin')";

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

/*****************************************************************************************/

$query = "SELECT * FROM blockbook, user WHERE  blockbook.user_id = user.id ";
   $result = mysql_query($query)or die(mysql_error());
?>
<div class="smallerText">
<TABLE BORDER=0 WIDTH=100% CELLSPACING=3 CELLPADDING=3 ALIGN=CENTER bgcolor="#99CC99">
<TR ALIGN=CENTER bgcolor="#CCFF66">
<td><font color=red><b>C/A</b></font></TD>
<td><font color=red><b>JN</b></font></TD>
<td ><font color=red><b>TOC</b></font></TD>
<td ><font color=red><b>TOV</b></font></TD>
<td ><font color=red><b>NOV</b></font></TD>
<td ><font color=red><b>Regu</b></font></TD>
<td ><font color=red><b>Multi Days Book</b></font></TD>
<td ><font color=red><b>Cust Name</b></font></TD>
<td ><font color=red><b>Pick Address</b></font></TD>
<td ><font color=red><b>Destination</b></font></TD>
<td ><font color=red><b>Tel</b></font></TD>
<td ><font color=red><b>WR</b></font></TD>
<td ><font color=red><b>Date</b></font></TD>
<td ><font color=red><b>Time</b></font></TD>
<td ><font color=red><b>Comments</b></font></td>
</tr>
<?
	while ($row = mysql_fetch_array($result))  {
    extract($row);
	echo "<tr align=center>
	<td>" . $row['user_id'] . "</td>
	<td>" . $row['job_id'] . "</td>
	<td>" . $row['typeOfcustomer'] . "</td>
	<td>" . $row['typeOfvehicle'] . "</td>
	<td>" . $row['noOfVehicle'] . "</td>
	<td>" . $row['regul'] . "</td>
	<td>" . $row['mon'] . "," . $row['tue'] . "," . $row['wed'] . ",
	" . $row['thur'] . "," . $row['fri'] . "," . $row['sat'] . ",
	" . $row['sun'] . "</td>
	<td>" . $row['cust_name'] . "</td>
	<td>" . $row['cust_address'] . "</a></td>
	<td>" . $row['des'] . "</td>
	<td>" . $row['cust_tel'] . "</td>
	<td>" . $row['reqVehicle'] . "</td>
	<td>" . $row['dateDay'] . "/" . $row['dateMO'] . "/" . $row['dateYr'] . "</td>
	<td>" . $row['timeHr'] . ":" . $row['timeMin'] . "</td>
	<td>" . $row['comment'] . "</td>
	</tr>";
 }
?></table></div><?
}
/*****************************************************************************************/
function blockBook(){
?>

<center>
  <h1>Block Bookings facility is only available for registered customers 
  and Account holders. </h1>
</center>
<div class="smallerText2">

<form name="blockbook" method="post" action="<?php echo $PHP_SELF ?>">
<table width="100%" border="0" cellspacing="1" cellpadding="0">
  <tr>
    <td></td>
    <td><input name="Job_id" type="hidden" id="id" size="40" /></td>
  </tr>
  <tr>
    <td width="13%">User ID</td>
    <td width="14%"><input name="user_id" type="text" id="user_id" size="7" /></td>
    <td width="6%">Date:</td>
    <td width="22%"><?php
/********************************   Dropdown box for Date  ******************/

  $today = Time();                     //stores today's date
  $f_today = date("d-M-Y",$today);     //formats today's date

   echo "<div align='center'>\n"; 
  echo "<div align='center'>\n"; 

  /* create form containing date selection list */
  //echo "<form action='processform.php' method='post'>\n";

  /* build selection list for the day */
  $todayDay= date("d",$today);    //get the day from $today
  echo "<select name='dateDay' > \n";
  for ($n=1;$n<=31;$n++)  
  {
    echo " <option value=$n";
    if ($todayDay == $n ) 
    {
      echo " selected";
    }
    echo "> $n\n";
  }
  echo "</select>";

  /* create an array of months*/
  $monthName = array(1=> "January", "February", "March", "April",
                         "May", "June", "July", "August",
                         "September", "October", "November",
                         "December");

  /* build selection list for the month */
  $todayMO = date("m",$today);             //get the month from $today
  echo "<select name='dateMO' >\n";
  for ($n=1;$n<=12;$n++) 
  {
    echo "<option value=$n\n";
    if ($todayMO == $n)
    {
      echo " selected";
    }
    echo "> $monthName[$n]\n";
  }
  echo "</select>";

  /* build selection list for the year */
  $startYr = date("Y", $today);         //get the year from $today
  echo "<select name='dateYr' >\n";
  for ($n=$startYr;$n<=$startYr+5;$n++)
  {
    echo " <option value=$n";
    if ($startYr == $n )
    {
      echo " selected";
    }
    echo "> $n\n";
  }
  echo "</select>\n";
?></td>
    <td width="13%">Name:</td>
    <td width="32%"><input name="cust_name" type="text" id="cust_name" size="40" /></td>
  </tr>
  <tr>
    <td>Type of Customer:</td>
    <td><select name="typeOfcustomer" onchange="accountCust('parent',this,0)">
      <option value="cash"  selected="selected">Cash</option>
      <option value="authAc.php">Account</option>
    </select></td>
    <td>Time</td>
    <td> Hr <select  name="timeHr"  > 
    <option>00</option>
    <option>01</option>
    <option>02</option>
    <option>03</option>
    <option>04</option>
    <option>05</option>
    <option>06</option>
    <option>07</option>
    <option>08</option>
    <option>09</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>
    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>
    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
  </select>
Min <select name="timeMin" >
    <option>00</option>
    <option>05</option>
    <option>10</option>
    <option>15</option>
    <option>20</option>
    <option>25</option>
    <option>30</option>
    <option>35</option>
    <option>40</option>
    <option>45</option>
    <option>50</option>
    <option>55</option>
  </select></td>
    <td>Pick up Address:</td>
    <td><input name="cust_address" type="text" id="cust_address" size="50" /></td>
  </tr>
  <tr>
    <td>Type of Vehicle Req:</td>
    <td><select name="typeOfvehicle" >
      <option value="4Seater">4 Seater Vehicle</option>
      <option value="7Seater">7 Seater Vehicle</option>
    </select></td>
    <td> </td>
    <td> </td>
    <td>Post Code:</td>
    <td><input name="cust_postCode" type="text" id="cust_postCode" size="15" /></td>
  </tr>
  <tr>
    <td>No. of Vehicles Req:</td>
    <td><select name="noOfVehicle" >
      <option value="1" selected="selected">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
      <option value="6">6</option>
      <option value="7">7</option>
      <option value="8">8</option>
      <option value="9">9</option>
      <option value="10">10</option>
    </select></td>
    <td> </td>
    <td> </td>
    <td>Tel / Mobile:</td>
    <td><input name="cust_tel" type="text" id="cust_tel" size="20" /></td>
    <tr>
    <td>Booking Regularity:</td>
    <td><select name="regul" >
      <option value="0" selected="selected">Select</option>
      <option value="once">Once</option>
      <option value="daily">Daily</option>
      <option value="weekly">Weekly</option>
      <option value="monthly">Monthly</option>
    </select></td>
    <td> </td>
    <td> </td>
    <td>Destination:</td>
    <td><input name="des" type="text" id="des" size="50" /></td>
</tr>
</table>

<hr>
  <tr>
  <td>
       <input name="submit" type="submit" value="Submit" />
  </td>
  <td>
        <input name="reset" type="reset" value="Reset" />
   </td></form>
</tr></div>
<?
}
if (! isset($_POST['submit'])){
blockBook();
}else{
validation();
}	
?>

Link to comment
https://forums.phpfreaks.com/topic/129443-select-query-not-working/
Share on other sites

is your problem with this query?

$query = "SELECT * FROM blockbook, user WHERE  blockbook.user_id = user.id ";

 

That query will select all rows from blockbook where there is a matching id in user table. There is no WHERE clause to select a specific id.

 

You need to change everything related to that Query.

 

<?
/*****************************************************************************************/

$query2 = "SELECT * FROM blockbook, user WHERE  blockbook.user_id = user.id ";
   $result2 = mysql_query($query2)or die(mysql_error());
?>
<div class="smallerText">
<TABLE BORDER=0 WIDTH=100% CELLSPACING=3 CELLPADDING=3 ALIGN=CENTER bgcolor="#99CC99">
<TR ALIGN=CENTER bgcolor="#CCFF66">
<td><font color=red><b>C/A</b></font></TD>
<td><font color=red><b>JN</b></font></TD>
<td ><font color=red><b>TOC</b></font></TD>
<td ><font color=red><b>TOV</b></font></TD>
<td ><font color=red><b>NOV</b></font></TD>
<td ><font color=red><b>Regu</b></font></TD>
<td ><font color=red><b>Multi Days Book</b></font></TD>
<td ><font color=red><b>Cust Name</b></font></TD>
<td ><font color=red><b>Pick Address</b></font></TD>
<td ><font color=red><b>Destination</b></font></TD>
<td ><font color=red><b>Tel</b></font></TD>
<td ><font color=red><b>WR</b></font></TD>
<td ><font color=red><b>Date</b></font></TD>
<td ><font color=red><b>Time</b></font></TD>
<td ><font color=red><b>Comments</b></font></td>
</tr>
<?
	while ($row2 = mysql_fetch_array($result2))  {
    extract($row2);
	echo "<tr align=center>
	<td>" . $row2['user_id'] . "</td>
	<td>" . $row2['job_id'] . "</td>
	<td>" . $row2['typeOfcustomer'] . "</td>
	<td>" . $row2['typeOfvehicle'] . "</td>
	<td>" . $row2['noOfVehicle'] . "</td>
	<td>" . $row2['regul'] . "</td>
	<td>" . $row2['mon'] . "," . $row2['tue'] . "," . $row2['wed'] . ",
	" . $row2['thur'] . "," . $row2['fri'] . "," . $row2['sat'] . ",
	" . $row2['sun'] . "</td>
	<td>" . $row2['cust_name'] . "</td>
	<td>" . $row2['cust_address'] . "</a></td>
	<td>" . $row2['des'] . "</td>
	<td>" . $row2['cust_tel'] . "</td>
	<td>" . $row2['reqVehicle'] . "</td>
	<td>" . $row2['dateDay'] . "/" . $row['dateMO'] . "/" . $row['dateYr'] . "</td>
	<td>" . $row2['timeHr'] . ":" . $row['timeMin'] . "</td>
	<td>" . $row2['comment'] . "</td>
	</tr>";
}
?></table></div><?
}
/*****************************************************************************************/

This is where the user post his/her own ID (Primary key of user table (id)). Basiclly what I'm saying is if posted number is equel to user.id bring out those records but the devil's bring me everything from other user's records too.

 

    <td width="13%">User ID</td>
    <td width="14%"><input name="user_id" type="text" id="user_id" size="7" /></td>

 

Thanks

Zed

That should be

 

$query = "SELECT * FROM blockbook, user WHERE  blockbook.user_id = '$user_id'";

 

Now you have remove the join condition - not a good idea.

 

$query = "SELECT * FROM blockbook
        INNER JOIN user ON blockbook.user_id = user.id
        WHERE  blockbook.user_id = '$user_id'";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.