• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

New to PHP, what am I doing wrong?? pointers??

I have a url called test.php?user=me&subject=you

here's my code... i connect to the database fine, but my variables are all empty.. any pointers as to what is going wrong?

<?php

$user = $_REQUEST['user'];
$subject = $_REQUEST['subject'];

$link = mysql_connect('localhost', 'mailer', 'mailer321')
   or die('Could not connect: ' . mysql_error());

mysql_select_db('mailer') or die('Could not select database');

$query = "SELECT * FROM email where name = '$user' and subject = '$subject' order by id desc limit 1";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

while ($rows = mysql_fetch_array($result))  {
$name = $rows[name];
$email = $rows[email];
$content = $rows[content];

print "name=$name";
print "email=$email";
print "content=$content";

}

mysql_free_result($result);

mysql_close($link);

?>
0
jmingo
Asked:
jmingo
1 Solution
 
RoonaanCommented:
Try adding error_reporting(E_ALL) to the top of your php section: eq:

<?php
 error_reporting(E_ALL);
 ..rest of code
?>

I expect an error on the $rows[name] part (should be $rows['name']), but this should not kill your script or cause empty outputs.

Try the error_reporting first

Regards

-r-
0
 
jmingoAuthor Commented:

this is what came up.


Warning: Undefined variable: _REQUEST in /var/www/html/php/test.php on line 18

Warning: Undefined variable: _REQUEST in /var/www/html/php/test.php on line 19

Warning: Use of undefined constant name - assumed 'name' in /var/www/html/php/test.php on line 30

Warning: Use of undefined constant subject - assumed 'subject' in /var/www/html/php/test.php on line 31

Warning: Use of undefined constant content - assumed 'content' in /var/www/html/php/test.php on line 32
name=email=content=
0
 
RoonaanCommented:
then you have to use either $_GET or $_POST in stead of $_REQUEST
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
jmingoAuthor Commented:
When i change it to

$user = $_GET['user'];
$subject = $_GET['subject'];

it returns

Warning: Undefined variable: _GET in /var/www/html/php/test.php on line 18

Warning: Undefined variable: _GET in /var/www/html/php/test.php on line 19

and this

$user = $_POST['user'];
$subject = $_POST['subject'];

returns

Warning: Undefined variable: _POST in /var/www/html/php/test.php on line 18

Warning: Undefined variable: _POST in /var/www/html/php/test.php on line 19
0
 
RoonaanCommented:
And $http_post_vars/$http_get_vars?

Try <?php phpinfo();?> and tell us which version of php you have installed, because it sounds either pretty odd, or pretty old..

Regards

-r-
0
 
jmingoAuthor Commented:
PHP Version 4.0.4pl1

i'm using $http_get_vars now and here's what comes up...

Warning: Use of undefined constant name - assumed 'name' in /var/www/html/php/test.php on line 31

Warning: Use of undefined constant subject - assumed 'subject' in /var/www/html/php/test.php on line 32

Warning: Use of undefined constant content - assumed 'content' in /var/www/html/php/test.php on line 33
name=test@test.caemail=testcontent=here is content
0
 
mattjp88Commented:
change:

$name = $rows[name];
$email = $rows[email];
$content = $rows[content];

to:

$name = $rows['name'];
$email = $rows['email'];
$content = $rows['content'];
0
 
jmingoAuthor Commented:
there... no more errors...

what i'm trying to do is load this data into a flash file but that isn't working....
0
 
jmingoAuthor Commented:
if you can help me out with the flash ascept, i'll up the points some... if not, i'll just accept your answer.


thanks
0
 
suresh_aspCommented:
try this,

replace the below

$name = $rows['name'];
$email = $rows['email'];
$content = $rows['content'];

instead of

$name = $rows[name];
$email = $rows[email];
$content = $rows[content];

0
 
jmingoAuthor Commented:
here's my php code now.

<?php

error_reporting(E_ALL);

$user = $HTTP_GET_VARS['user'];
$subject = $HTTP_GET_VARS['subject'];

$link = mysql_connect('localhost', 'mailer', 'mailer321')
   or die('Could not connect: ' . mysql_error());

mysql_select_db('mailer') or die('Could not select database');

$query = "SELECT * FROM email where name = '$user' and subject = '$subject' order by id desc limit 1";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

while ($rows = mysql_fetch_array($result))  {

$name = $rows['name'];
$email = $rows['subject'];
$content = $rows['content'];

print "name=$name";
print "email=$email";
print "content=$content";

}

mysql_free_result($result);

mysql_close($link);

?>
0
 
RoonaanCommented:
What is the "flash aspect"?

To my understanding, Flash can only communicate using xml. But this is a whole other issue and requires a second thread/topic.

Regards

-r-
0
 
jmingoAuthor Commented:
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now