showing mysql data on screen

Hello I am beginning php and trying to display my first mysql file on the crt. I am using wamp on windows xp. I have a mysql table with two records in it. The three field names are prino, prin1, and prin2. These are a customer number and the first two fields for name. I have tried to mimic a number of self help sites to no avail. can someone tell me what is wrong with $cxn. the message tells me that it is not a mysql resource. i am not really sure what that means. my code follows and thanks for any help.
[php]
$cxn = mysqli_connect (HOST, USER, PASSWORD, NAME) or die(“could not get database”.mysql_error());
$query = “SELECT * FROM primarys”;
$result = mysql_query ($query, $cxn) or die(“could not execute query”.mysql_error()); // this is error
$nrows = mysql_num_rows ($result);
echo “retrieved $nrows rows:\n\n”;
echo “Name\n-----------------------\n”;
while ($row = mysql_fetch_assoc ($result)) {
$data1 = $row[“prino”];
$data2 = $row[“prin1”];
echo “$data1\n$data2\n”;
}
mysql_close($cxn);
?>
[/php]

You need to actually add the host and the DB username and password, and database name

Hello Sorry, I just entered the code that caused the error. I filled the four parameters in and the connect worked, I believe , because I did not get that message. the message occurred on the line with the comment. it stated that it could not execute the query because $cxn is not a mysql resource.

the thing i left out was
[php]

<?php DEFINE ('USER', 'root'); DEFINE ('PASSWORD', 'bigskyBIGSKY'); DEFINE ('HOST', 'localhost'); DEFINE ('NAME', 'smed'); [/php]

Ok, two things, you have the letter o instead of a zero on the data1 result. Most important you are using mysqli to connect but your not using it for the rest of your code mysqli_query etc…

You just used mysql_query without the i

Here it is working WITHOUT mysqli…

[php]

<? DEFINE ('USER', 'root'); DEFINE ('PASSWORD', 'bigskyBIGSKY'); DEFINE ('HOST', 'localhost'); DEFINE ('NAME', 'smed'); $cxn = mysql_connect (HOST, USER, PASSWORD, NAME) or die("could not get database".mysql_error()); mysql_select_db("smed", $cxn); $query = "SELECT * FROM primarys"; $result = mysql_query ($query, $cxn) or die("could not execute query".mysql_error()); // this is error $nrows = mysql_num_rows ($result); echo "retrieved $nrows rows:\n\n"; echo "Name\n-----------------------\n"; while ($row = mysql_fetch_assoc ($result)) { $data1 = $row["prin0"]; $data2 = $row["prin1"]; echo "$data1\n$data2\n"; } mysql_close($cxn); ?>

[/php]

Hi That seems to fix it. thank you very much for your help.

Hello Now I am trying by using the quick tutorial on displaying sql query which is in the phphelp site and when I try to execute it. it tells me that make_sid() is not defined. I agree. Its in the third $content line in the function browse_users() part of the tutorial. anyone know where this function is defined??

Sponsor our Newsletter | Privacy Policy | Terms of Service