PDA

View Full Version : PHP - A Beginners Guide help


markc1822
06-09-2007, 04:51 PM
Hi how are you guys.
I have a question, i am following the tutorial "PHP - A Beginners Guide" great tutorial by the way. I made it to part 7, which is echoing the result. When i Hit F+12 to preview my result i get this error....

Parse error: syntax error, unexpected T_ECHO in C:\wamp\www\Web Root\Test\dwc.php on line 11

Any idea what may be causing this?
Also, in dreamweaver do i need to create a database connection from the application window?


at line 11: echo $row['field2'];

(http://www.dreamweaverclub.com/forum/../vtm/)

Mark_W
06-09-2007, 05:01 PM
Copy and paste the full code.

markc1822
06-09-2007, 05:08 PM
<?php
require_once("Connections/connection.php"); // database connection

///////////////////////////////////////////////
$query = sprintf("SELECT * FROM table1");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
//////////////////////////////////////////////

do (
echo $row['field2'];
?>

Mark_W
06-09-2007, 05:26 PM
Youve used the wrong bracket type '(', you want to be using the curly brackets '{'.

markc1822
06-09-2007, 05:53 PM
k, thanks. i fixed that but i am getting another error

error message.......

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Web Root\Test\dwc.php on line 7

Code.....

<?php
require_once("Connections/connection.php"); // database connection

///////////////////////////////////////////////
$query = sprintf("SELECT * FROM table1");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
//////////////////////////////////////////////

echo $row['field2'];

?>

Mark_W
06-09-2007, 06:00 PM
k, thanks. i fixed that but i am getting another error

error message.......

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Web Root\Test\dwc.php on line 7

Code.....

<?php
require_once("Connections/connection.php"); // database connection

///////////////////////////////////////////////
$query = sprintf("SELECT * FROM table1");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
//////////////////////////////////////////////

echo $row['field2'];

?>



That ones confused me. I'm new to this as well, but I have copied and pasted your code into a new PHP page, and changed the 'field2' and 'table1' to a database I've made and it runs perfectly.

I'm afraid I'm unable to help you with this one. But someone else on here I'm sure will be able to help

markc1822
06-09-2007, 06:11 PM
k thanks, Thanks for the fast replys and help

davidj
06-09-2007, 09:24 PM
its a warning.. Its ok because its reporting the warning correctly

to supress the warning just add an @
here...

///////////////////////////////////////////////
$query = sprintf("SELECT * FROM table1");
$result = @mysql_query($query);
$row = @mysql_fetch_array($result); //<< @ here
//////////////////////////////////////////////


pleased your both enjoying the tuts

markc1822
06-10-2007, 12:06 AM
it works :) thanks

davidj
06-10-2007, 01:40 PM
Mark_W

I noticed your answering questions when your still learning PHP and that you spotted a syntax error which i initialy missed.

can i just say this...

if your trying to become teachers pet then your pressing all the right buttons!!

your going to make a good programmer.

Mark_W
06-11-2007, 11:03 PM
Mark_W

I noticed your answering questions when your still learning PHP and that you spotted a syntax error which i initialy missed.

can i just say this...

if your trying to become teachers pet then your pressing all the right buttons!!

your going to make a good programmer.

Ha! Thank you Davidj.

I'm not trying to become a teachers pet...unless of course that has some hidden benefits.

I find that if I help people whilst I'm learning then it makes it easier for me to understand what it all means.