sql query

markl1988

New Member
Messages
8
Reaction score
0
Points
0
hi

i am trying to use an sql query which when you enter enter first or last name which excists in the table table, it should search the db and show the results id, first name, last name, and contratced_hoursmon_am fields from the record in database matching name entered on form and name field with a database record. however i am having huge problems executing this query, here is the code i am trying to use.

<?php // connects to database
require_once('Connections/mark.php');
error_reporting(E_ALL);
ini_set('display_errors', 'On');

if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){
$name=$_POST['name'];
// get variables
if(isset($_POST['ID'])){
$ID = $_POST['ID'];}
// Open an sql query

$sql = "SELECT* ID, FirstName, LastName, contracted_hoursmon_am, FROM staffmember tbl".;
$result=mysql_query($query);
$numrows=mysql_num_rows($result);
// Loop through the results of the query
while($row=mysql_fetch_array($result)){
// Get the variable results
$ID = $conn->$row['ID'];
$FirstName = $conn->row['FirstName'];
$LastName = $conn->row['LastName'];
$contraced_hoursmon_am = $conn->row['contracted_hoursmon_am'];

while($row=mysql_fetch_assoc($result))

echo $FirstName=$row["FirstName"];
echo $LastName=$row["LastName"];
echo $ID=$row["ID"];
echo $contracted_hoursmon_am=$row["contracted_hoursmon_am"];
// print the variables fields retrieved from the record in database from the record with name enterd on form matching a name filed from a record in database
print_r($var);"$v'ID' <br>$v'FirstName' <br> $v'LastName' <br>$v'contracted_hoursmon_am' <br> ";
?>
<option value="<?=$ID?>" selected><?=($FirstName." ".$LastName)?></option>
<?php

}
// Closes the query

// Closes connection to database
?>
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
Code:
$sql = "SELECT* ID, FirstName, LastName, contracted_hoursmon_am, FROM staffmember tbl"; // there's a . here that doesn't belong
$result=mysql_query($query);
//$numrows=mysql_num_rows($result); you should check if $result is valid before doing any operation on it
if (!$result) {
     exit(mysql_error());
}
if (mysql_num_rows($result) == 0) {
     exit('No rows found');
}
 

markl1988

New Member
Messages
8
Reaction score
0
Points
0
now its saying i have a parse error on line 275, not even next to the code next to the </body> for some reason.
 

markl1988

New Member
Messages
8
Reaction score
0
Points
0
thanks

i have found the parse error and solved the other problem howver when i upload page to testing server it has no errors but when i enter a name and submit the form, it displays no reuslts at all for that member name entered on the form for some reason.
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
echo $FirstName=$row["FirstName"];
echo $LastName=$row["LastName"];
echo $ID=$row["ID"];
echo $contracted_hoursmon_am=$row["contracted_hoursmon_am"];
It is quite normal that you don't see anything, as you are doing an echo not on the values, but on the result of the assignment.
 

markl1988

New Member
Messages
8
Reaction score
0
Points
0
thanks

so what do u suggest to use to be able to display the reuslts other than the echo fucntion
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
echo isn't the problem, the problem is PHP evaluates this:
Code:
echo $var = $array['index'];

in two steps:
Code:
$var = $array['index'];
Code:
echo ???

The ??? is what $var=$array['index'] is equal to. It's an expression, not a value. This would be what you want to do:
Code:
$var=$array['index'];
$var2=$array['index2'];
echo $var;
echo $var2;
echo 'text';
echo $var, $var2, 'text'; // or you can do it this way
 

markl1988

New Member
Messages
8
Reaction score
0
Points
0
i tried that solution but still not displaying any records, i dunno what else could be done to solve this.
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
Try changing your query to this:

Code:
$sql = "SELECT ID, FirstName, LastName, contracted_hoursmon_am, FROM staffmember";
 
Last edited:

markl1988

New Member
Messages
8
Reaction score
0
Points
0
That dont work its going to be some silly debugging error that can't see. It may be the reason that the php coding, wont retrieve and display record from the database due to me using a local host to test the site. I might try a ftp tetsing server using x10 i set up see if it work using that ettsing server.
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
Why don't you install mysql on your test server? XAMPP comes with Apache, MySQL, Perl, and a few other goodies in one easy to use package. It's what I use for my test server and I highly recommend it.

http://www.apachefriends.org/en/xampp.html

You can export your X10 databases then import them onto your computer.
 
Last edited:

markl1988

New Member
Messages
8
Reaction score
0
Points
0
At the moment i do currently use wamp with sql installed. I have the phpmyadmin database linked to the websiste currently,, the db is linked to the site properly but thats what i am having troubled with retriving the query results from the database.
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
X10's firewall will not let you access MySQL remotely. You have to export the databases and import them.
 

markl1988

New Member
Messages
8
Reaction score
0
Points
0
at the moment i've just used xamp using their database i have my database fully set up with that linked to me site properly. i've not fully set up x10 as an ftp instead of local testing maybe i should try that
 
Top