Parse error: parse error, unexpected T_STRING on line 27

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DougieC
Forum Newbie
Posts: 18
Joined: Fri Jul 25, 2003 1:49 pm

Parse error: parse error, unexpected T_STRING on line 27

Post by DougieC »

Hello, I am trying to access mysql from a php form. I made a script that let me know that i was connected to it and I can. When i try to get information from the table i get the above error.

Line 26 $result = mysql_query("SELECT * FROM clienttable",$db);
Line 27 print("CompanyName: %s<br>\n" mysql_result
($result,0,"companyname"));

I am very new to Sql and php and am working through a tutorial so I am very confused why it doesn't work. 8O

Thnks alot
Ps any of you know any good tutorials that would help me access sql form a web form. :wink:
atari900
Forum Newbie
Posts: 3
Joined: Fri Jul 25, 2003 3:22 pm

Post by atari900 »

Personally I find the mysql_fetch_array function to be a little easier. It takes the results from a mysql query and puts them into an array which can the be accessed by using the column name as the array index.

example $myrow['username']

you could try something like this to print the information from a database

Code: Select all

$result = mysql_query ("SELECT * FROM table", $db);

while ($myrow = mysql_fetch_array($result)) &#123;
      printf("Company name: %s <br />", $myrow&#1111;'company_name']);
&#125;
The above code would print out "Company name: name from database" for each row in the database, so if you had 5 rows it would print five times with the Company name being the company name columen from that row in the database table.

In you're code, you're missing a comma between \n" and mysql_result ...
seperating the string from the variables, and I would suggest using printf rather then print.

Good luck[/i]
DougieC
Forum Newbie
Posts: 18
Joined: Fri Jul 25, 2003 1:49 pm

Post by DougieC »

when I try your code i get this badboy
mysql_query(): supplied argument is not a valid MySQL-Link resource
for $result = mysql_query ("SELECT * FROM client_table", $db);
I just dont think i,m suspose to play with php or Sql :cry:
atari900
Forum Newbie
Posts: 3
Joined: Fri Jul 25, 2003 3:22 pm

Post by atari900 »

what are you using for your mysql_connect code?

just try something like

Code: Select all

$dblink = mysql_connect("localhost", "username", "password");
$db = mysql_select_db("database_name", $dblink);
$result = mysql_query("SELECT * FROM table", $dblink);

while ($myrow = mysql_fetch_array($result)) &#123;

....
you can actually ommit the $dblink variable from the mysql_query function and it should still work just fine.

$result = mysql_query("SELECT * FROM table);

don't give up yet. With time this part will become simple, and overly repeated stuff, and you can concentrate on all kinds of other cool things.

I'm taking off for a while now, but if you need help right away you can always try #php on EFnet they're usually pretty helpful.
DougieC
Forum Newbie
Posts: 18
Joined: Fri Jul 25, 2003 1:49 pm

Post by DougieC »

ommiting the $dblink made it work :lol: :lol:
Thanks alot :P
Post Reply