some pointers on a php mysql connection

376

I am trying to start connecting php to my sql. I have a database created in phpmyadmin named 'snr' and that has a table named 'donate' which has four columns named 'user_ID', 'first_Name', 'last_Name' and donate_TOTAL.

When i run the following script in a browser I get the while loop showing and therefore nothing is returned via the echo statements. I want to show first_Name + last_Name.

<html>
<body>

<?php
$con = mysql_connect("localhost","root","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("snr", $con);

$result = mysql_query("SELECT * FROM donate WHERE user_ID > 0");

while($row = mysql_fetch_array($result))
{
echo $row['first_Name'] . " " . $row['last_Name'];
echo "<br />";
}

mysql_close($con);
?>

</body>
</html>

This is what is returned when i run it in a broswer.

0"); while($row = mysql_fetch_array($result)) { echo $row['first_Name'] . " " .     $row['last_Name']; echo "
"; } mysql_close($con); ?>
724

Answer

Solution:

try this

<html>
<body>

<?php
$con = mysql_connect("localhost","root","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("snr", $con);

$result = mysql_query("'SELECT * FROM donate WHERE user_ID > 0'");

while($row = mysql_fetch_array($result))
{
echo $row['first_Name'] . " " . $row['last_Name'];
echo "<br />";
}

mysql_close($con);
?>

</body>
</html>

People are also looking for solutions to the problem: parse twitter status with json php

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.