Page 1 of 1

Form Selection Help Needed

Posted: Wed Aug 05, 2009 4:47 pm
by VVal
Good afternoon to everyone, I have a dilemma on my hands, well to me it is, can anyone be so kind as to assist me.
Below is my statement for a form for which I need the user to input the date and select a user and return the records that the user have inputted over a period of time.
I got the portion for the date to work fine, however I am not sure how I go about collecting the selection made from the form in order to return the desired result.
Please help if you can.

Thank you

Code: Select all

 
<?php
$dbcon = mysql_connect("localhost", "common", "admin");
if (!$dbcon)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("inventory", $dbcon);
 
 
if($_POST["execsearch"] != "" && $_POST["fr_date"] != "" && $_POST["to_date"] != "")
    {
#$result = mysql_query("SELECT * FROM customer" );
 
$query = "SELECT fname, lname, (SELECT CONCAT_WS(' ', fname, lname) FROM queuser WHERE username = createdby) AS createdby, createdtime, updatedtime, purpose, (SELECT CONCAT_WS(' ', fname, lname) FROM queuser WHERE username = updatedby) AS updatedby, comments, (SELECT description FROM branch WHERE customer.branchid = branch.branchid) AS branchid FROM customer WHERE updatedtime >= '".$_POST["fr_date"]."' AND updatedtime <= '".$_POST["to_date"]."'ORDER BY branchid";
    $result=mysql_query($query, $dbcon);
 
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo strtoupper("<td>" . $row['fname'].' '. $row['lname']) . "</td>";
  echo strtoupper("<td>" . $row['createdby']) . "</td>";
  echo strtoupper("<td>" . $row['starttime']) . "</td>";
  echo strtoupper("<td>" . $row['endtime']) . "</td>";
  echo strtoupper("<td>" . $row['purpose']) . "</td>";
  echo "<td>" . $row['updatedby'] . "</td>";
  echo "<td>" . $row['comments'] . "</td>"; 
  echo "<td>" . $row['branchid'] . "</td>"; 
  echo "</tr>";
  }
echo "</table>";mysql_close($dbcon);
 
}
 
?>

Re: Form Selection Help Needed

Posted: Thu Aug 06, 2009 4:54 am
by towerspl
looks like your posting the data, using it in sql and then looping out the results, nothing wrong with what i can see although the following is annoying:

the code is messy hard to read and use mysql_real_escape_string or i could delete your database in about 2 seconds(sry just very annoying that you dont know that as you are writting php code should be fundamental!)

Re: Form Selection Help Needed

Posted: Thu Aug 06, 2009 5:08 pm
by VVal
My apologies for annoying you towerspl I am basically new to this and trying, I would think that as someone who knows the topic you could at least point out where I have gone wrong and not try to tear me down.
I would want to think that people come to these forums to seek help and the genuine person who wants to help would point them in the right direction.

Re: Form Selection Help Needed

Posted: Thu Aug 06, 2009 5:14 pm
by aceconcepts
So where exactly do you need help?

Re: Form Selection Help Needed

Posted: Fri Aug 07, 2009 8:41 am
by towerspl
sry if i was so blunt but if you read any book or tutorial on mysql in php the real_escape will be in the basics. I am not sure exactly what the problem is with your code after scanning it it looks to me like it is working fine(except what i pointed out lol)

Couple of good places to learn from w3schools.com, php.net and also a good book to learn from is the php 5 zend certified training book which I am currently reading through, it start from the basics and goes to advanced. I have learnt a lot after reading that book.