Jump to content

Difficulty with first database table query


edwind

Recommended Posts

I cannot get past this error code;Parse error: syntax error, unexpected T_LNUMBER, expecting ',' or ';' in C:\Inetpub\vhosts\weekdayweddings.net\httpdocs\asptestquerypage\Index.php on line 34The code I've used is

<?php$user_name = "";$password = "";$database = "";$server = "localhost:3306";$con = mysql_connect($server, $user_name, $password);if (!$con)  {  die('Could not connect: ' . mysql_error());  }mysql_select_db("testcall", $con);$result = mysql_query("SELECT * FROM Stock No");$result = mysql_query("SELECT * FROM Price");while($row = mysql_fetch_array($result))	echo "<table border='1'><tr><th colspan="2" align="center"><img src="images/A0001.jpg"></th><th colspan="2" align="center"><img src="images/A0002.jpg"></th></tr>";while($row = mysql_fetch_array($result))  {  echo "<tr>";  echo "<td align="left">" . $row['Price WHERE Listed="1" '] . "</td>";  echo "<td align="right">" . $row['Stock No WHERE Listed="1" '] . "</td>";  echo "<td align="left">" . $row['Price WHERE Listed="2" '] . "</td>";  echo "<td align="right">" . $row['Stock No WHERE Listed="2" '] . "</td>";  echo "</tr>";  }echo "</table>";	mysql_close($con);?>

Line 34 is the first line that begins................ echo and is all on one line in the codeI have checked and rechecked the quote marks but they all seem to follow the proper 'pairing' rules.I assume that I am making the right connection to the database?The page can be found at www weekdayweddings net website in the root folder asptestquerypage (Sorry if I should not post this, I couldn't find the rules on u r l s.grateful for any help,edwind

Link to comment
Share on other sites

in this:

echo "<td align="left">"

the " before the word left is ending the string early, as you want the " after the > to end the string.you can escape the ones in the string with a backslash:

echo "<td align=\"left\">"

or change them to apostrophes:

echo "<td align='left'>"

same for the other 3 like that, and also the echo "<table border='1'><tr><th colspan="2" line.

$result = mysql_query("SELECT * FROM Stock No");$result = mysql_query("SELECT * FROM Price");

in that code, you are storing the second mysql_query() call in the same variable, which will override the first query's result.you should remove the first occurrence you have of this:

while($row = mysql_fetch_array($result))

if the connection to SQL fails, you will get the output "Could not connect: (error here)".also where you have the 4 rows like this:

$row['Price WHERE Listed="1" ']

you can't use the SQL where statement in PHP array keys to make use of it, the where statement should be in the string which is sent to SQL with mysql_query().after calling "$row = mysql_fetch_array($result)", the $row array contains keys which are the field names of the SQL table, also you can use integers with mysql_fetch_array() (where 0 is the first field returned, 1 is the next, etc)

Link to comment
Share on other sites

Thankyou JamesB. I had come to realise the error with the quotes but I had no idea about the missuse of the WHERE attribute. Thanks for that too but the problem I have is to call captions and prices to accompany their images placements in a table. They will not always follow an array numerically so the integer method will be unsuitable I guess.Also, having corrected all the instances of double quotes, I now get denied access because of;[error]Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Inetpub\vhosts\weekdayweddings.net\httpdocs\asptestquerypage\Index.php on line 18Could not connect: Access denied for user 'ODBC'@'localhost' (using password: NO)[/error]The question here is how do I find my server path. I've tried using the same path as I use for ftp transfer but that doesn't work (which is why I resorted to the generic 'localhost:3306')?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...