Page 1 of 1
Parse error: parse error, unexpected T_STRING on line 27
Posted: Fri Jul 25, 2003 1:49 pm
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.
Thnks alot
Ps any of you know any good tutorials that would help me access sql form a web form.

Posted: Fri Jul 25, 2003 3:22 pm
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)) {
printf("Company name: %s <br />", $myrowї'company_name']);
}
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]
Posted: Fri Jul 25, 2003 3:42 pm
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

Posted: Fri Jul 25, 2003 3:51 pm
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)) {
....
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.
Posted: Fri Jul 25, 2003 5:32 pm
by DougieC
ommiting the $dblink made it work
Thanks alot
