Page 1 of 2

text area loading from mysql database

Posted: Tue Oct 07, 2008 8:46 pm
by warzo69
can anyone find the error in this code?

Code: Select all

         <select name="select1" id="select1" onChange='empsel()'/> q
<?php
$result = mysql_query("SELECT fullname FROM employee");
while ($row = mysql_fetch_array($result)) {
    echo "<option>".$row['fullname']."</option><br>";
};
?>
            <option>New Employee</option>
          </select>
          <br/>
          <br/>
          <br/>
          <br/>
 
          <textarea name="select2" rows="5" cols="15" id="select2"/>
<?php
$tmpVar = $_POST['select1'];
$result = mysql_query("SELECT ssn, dob, add1, add2, phone, empid, position, hiredate, termdate, status, salary, driverslicense FROM employee WHERE fullname = '$tmpVar' ");
while ($row = mysql_fetch_array($result)) {
    echo "".$row['ssn']."|"."".$row['dob']."|"."".$row['add1']."|"."".$row['add2']."|".
         "".$row['phone']."|"."".$row['empid']."|"."".$row['position']."|"."".$row['hiredate']."|".
         "".$row['termdate']."|"."".$row['status']."|"."".$row['salary']."|"."".$row['driverslicense']."|";
};
 
?>
          </textarea>
The textarea is loading with nothing in it. If I change FROM employee WHERE fullname = '$tmpVar' "); to FROM employee WHERE fullname = 'John Smith' ");
It loads john smith's information from the database into the textarea like it should.

Any ideas?

Re: text area loading from mysql database

Posted: Tue Oct 07, 2008 8:55 pm
by alex.barylski
Change:

[sql]FROM employee WHERE fullname = '$tmpVar' "; [/sql]

To:

[sql]FROM employee WHERE fullname = "$tmpVar"; [/sql]

And use single quotes for the SQL query itself.

Re: text area loading from mysql database

Posted: Tue Oct 07, 2008 9:04 pm
by warzo69
tried

Code: Select all

$result = mysql_query('SELECT ssn, dob, add1, add2, phone, empid, position, hiredate, termdate, status, salary, driverslicense FROM employee WHERE fullname = "$tmpVar"; ');
and

Code: Select all

$result = mysql_query('SELECT ssn, dob, add1, add2, phone, empid, position, hiredate, termdate, status, salary, driverslicense FROM employee WHERE fullname = "$tmpVar" ');
both gave me the same result, a blank textarea. If i manually put in a name like 'John Smith' the employee info is loaded from the database, so the syntax has to be correct. i dont have a clue why this isnt working.

Code: Select all

$result = mysql_query('SELECT ssn, dob, add1, add2, phone, empid, position, hiredate, termdate, status, salary, driverslicense FROM employee WHERE fullname = "John Smith" ');

Re: text area loading from mysql database

Posted: Wed Oct 08, 2008 3:30 am
by aceconcepts
Try:

Code: Select all

 
$result = mysql_query("SELECT ssn, dob, add1, add2, phone, empid, position, hiredate, termdate, status, salary, driverslicense FROM employee WHERE fullname = '$tmpVar' ");
 
Change the single quotes to double quotes and vice versa.

Also, you had a semi-colon immediately after WHERE fullname = "$tmpVar";');

The query i have re-written at the top is one correct method.

Re: text area loading from mysql database

Posted: Wed Oct 08, 2008 8:54 am
by warzo69
Try:

Line number On/Off | Expand/Contract

1.
2. $result = mysql_query("SELECT ssn, dob, add1, add2, phone, empid, position, hiredate, termdate, status, salary, driverslicense FROM employee WHERE fullname = '$tmpVar' ");
3.



Change the single quotes to double quotes and vice versa.

Also, you had a semi-colon immediately after WHERE fullname = "$tmpVar";');

The query i have re-written at the top is one correct method.

_________________
I have never let my schooling interfere with my education.
- Mark Twain
this is where i started at the beginning of the post. however I did try it again and it yielded an empty textarea.

Re: text area loading from mysql database

Posted: Wed Oct 08, 2008 9:05 am
by aceconcepts
Just looked through your first post and noticed that you have placed you while loop inside of the textarea.

Instead of doing it that way, try storing you loop result as a variable. i.e. instead of echoing your data store it in a variable.

e.g.

Code: Select all

 
while ($row = mysql_fetch_array($result)) {
     $textarea_content=$row['ssn']."|"."".$row['dob']."|"."".$row['add1']."|"."".$row['add2']."|".
          "".$row['phone']."|"."".$row['empid']."|"."".$row['position']."|"."".$row['hiredate']."|".
          "".$row['termdate']."|"."".$row['status']."|"."".$row['salary']."|"."".$row['driverslicense']."|";
};
 
Now you can simply echo this variable inside the textarea.

Code: Select all

 
<textarea><? echo $textarea_content; ?></textarea>
 

Re: text area loading from mysql database

Posted: Wed Oct 08, 2008 9:21 am
by warzo69

Code: Select all

<?php
$tmpVar = $_POST['select1'];
$result = mysql_query("SELECT ssn, dob, add1, add2, phone, empid, position, hiredate, termdate, status, salary, driverslicense FROM employee WHERE fullname = '$tmpVar' ");
while ($row = mysql_fetch_array($result)) {
     $textarea_content=$row['ssn']."|"."".$row['dob']."|"."".$row['add1']."|"."".$row['add2']."|".
         "".$row['phone']."|"."".$row['empid']."|"."".$row['position']."|"."".$row['hiredate']."|".
         "".$row['termdate']."|"."".$row['status']."|"."".$row['salary']."|"."".$row['driverslicense']."|";
};
 
?>
 
        <textarea>
<?php 
echo $textarea_content;
?>
        </textarea>
Same result, blank textarea. If anyone can fix this i am willing to pay for a working answer to this problem.

Re: text area loading from mysql database

Posted: Wed Oct 08, 2008 9:40 am
by aceconcepts
With textareas try not to break the lines. Write it like this:

Code: Select all

 
<textarea name="something"><? echo $textarea_content; ?></textarea>
 
This is just good practice and probably will not solve ur current dilemma.

Try this:

Code: Select all

 
$tmpVar=$_POST['select1'];
$result = mysql_query("SELECT ssn, dob, add1, add2, phone, empid, position, hiredate, termdate, status, salary, driverslicense FROM employee WHERE fullname = '$tmpVar' ");
 
$textarea_content=mysql_num_rows($result);
 
echo'<textarea name="something">' . $textarea_content . '</textarea>';
 
This should tell you if any records have been found.

Re: text area loading from mysql database

Posted: Wed Oct 08, 2008 9:55 am
by warzo69
the textarea now is showing a 0. The information is there, I. If i change the variable

Code: Select all

WHERE fullname = '$tmpVar' ");
 
to

Code: Select all

WHERE fullname = 'John Smith' ");
it works. however if I change the variable here

Code: Select all

$tmpVar=$_POST['select1'];
 
to

Code: Select all

$tmpVar="John Smith"
I get an empty textarea again.

Re: text area loading from mysql database

Posted: Wed Oct 08, 2008 10:57 am
by aceconcepts
Try changing $tmpVar to $tmp_var

Re: text area loading from mysql database

Posted: Wed Oct 08, 2008 11:32 am
by warzo69
same result, an empty textarea.

Re: text area loading from mysql database

Posted: Thu Oct 09, 2008 4:47 am
by aceconcepts
Try turning on the error reporting:

Code: Select all

 
$result = mysql_query("SELECT ssn, dob, add1, add2, phone, empid, position, hiredate, termdate, status, salary, driverslicense FROM employee WHERE fullname = '$tmpVar' ") or die(mysql_error());
 
Worth checking :D

Re: text area loading from mysql database

Posted: Thu Oct 09, 2008 8:18 am
by warzo69
same result :banghead: , thanks again.

Re: text area loading from mysql database

Posted: Thu Oct 09, 2008 8:29 am
by aceconcepts
Did you get an error message from it? Thats the reason for mysql_error()

Re: text area loading from mysql database

Posted: Thu Oct 09, 2008 8:15 pm
by warzo69
no error message. the page loads with a blank textarea.