Jump to content

need help in retrieving data from database


doforumda

Recommended Posts

hi i have written a code through i want to select all the data from mysql database and display it in html table but when i run that code it displays following output

 

".$myRowRes["firstname"]." ".$myRowRes["lastname"]." ".$myRowRes["region"]." "; } echo ""; ?>

 

how can i solve this problem?

Link to comment
Share on other sites

<?

 

        $db_connect = mysql_connect("localhost","username","password");

        mysql_select_db("cs",$db_connect);

$selectQuery = "select * from statusvalues order by lastname ASC";

$resultName = mysql_query($selectQuery);

 

echo "<table width='400' border='1' cellspacing='0' cellpadding='0'>

  <tr>

    <td>ID</td>

    <td>First Name</td>

    <td>Last Name</td>

    <td>Region</td>

  </tr>";

  while($myRowRes = mysql_fetch_assoc($resultName))

  {

  echo "<tr>

    <td>".$myRowRes["statVal_id"]."</td>

    <td>".$myRowRes["firstname"]."</td>

    <td>".$myRowRes["lastname"]."</td>

    <td>".$myRowRes["region"]."</td>

    </tr>";

  }

  echo "</table>";

?>

Link to comment
Share on other sites

this is my whole code

 

<?php

$db_connect = mysql_connect("localhost","username","password");

mysql_select_db("cs",$db_connect);

 

$table = "statusValues";

 

if(isset($function) && $function == "add")

{

echo "This is the value - $regionNumber<br>";

$sql_query = "insert into statusvalues (firstname,lastname,region,ssn) values ('".$fname."','".$lname."','".$regionNumber."','".$ssn."')";

$exe_query = mysql_query($sql_query);

}

 

$sql_reg = "select * from region";

$sqlQuery = mysql_query($sql_reg);

 

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Untitled Document</title>

</head>

 

<body>

<form name="form1" method="post" action="indexxx.php?function=add">

  <p>First Name:

    <input type="text" name="fname" id="fname">

</p>

  <p>Last Name:

    <input type="text" name="lname" id="lname">

</p>

  <p>Select Region Number:

  <?php

    echo "<select name='regionNumber' id='regionNumber'>";

    while($record = mysql_fetch_array($sqlQuery))

{

    echo "<option value = '".$record['regionNumber']."'>".$record['regionNumber']."-".$record['regionName']."</option>";

    }

echo "</select>";

?>

 

  </p>

  <p>Enter SSN No Dashes:

    <input type="text" name="ssn" id="ssn">

  </p>

  <p>

    <input type="submit" name="button" id="button" value="OK">

  </p>

</form>

<?

 

$selectQuery = "select * from statusvalues order by lastname ASC";

$resultName = mysql_query($selectQuery);// or die(mysql_error());

 

echo "<table width='400' border='1' cellspacing='0' cellpadding='0'>

  <tr>

    <td>ID</td>

    <td>First Name</td>

    <td>Last Name</td>

    <td>Region</td>

  </tr>";

  while($myRowRes = mysql_fetch_array($resultName))

  {

  echo "<tr>

    <td>".$myRowRes["statVal_id"]."</td>

    <td>".$myRowRes["firstname"]."</td>

    <td>".$myRowRes["lastname"]."</td>

    <td>".$myRowRes["region"]."</td>

    </tr>";

  }

  echo "</table>";

?>

 

</body>

</html>

 

Link to comment
Share on other sites

Don't forget to put [ code ] before and [ /code ] after your code please (without the spaces).

From what I could see, this should work. You forgot the php after ?

<?php
$db_connect = mysql_connect("localhost","username","password");
mysql_select_db("cs",$db_connect);

$table = "statusValues";

if(isset($function) && $function == "add")
{
   echo "This is the value - $regionNumber<br>";
   $sql_query = "insert into statusvalues (firstname,lastname,region,ssn) values ('".$fname."','".$lname."','".$regionNumber."','".$ssn."')";
   $exe_query = mysql_query($sql_query);
}

$sql_reg = "select * from region";
$sqlQuery = mysql_query($sql_reg);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>

<body>
<form name="form1" method="post" action="indexxx.php?function=add">
  <p>First Name:
    <input type="text" name="fname" id="fname">
</p>
  <p>Last Name:
    <input type="text" name="lname" id="lname">
</p>
  <p>Select Region Number:
  <?php
    echo "<select name='regionNumber' id='regionNumber'>";
     while($record = mysql_fetch_array($sqlQuery))
    {
       echo "<option value = '".$record['regionNumber']."'>".$record['regionNumber']."-".$record['regionName']."</option>";
     }
    echo "</select>";
?>

  </p>
  <p>Enter SSN No Dashes:
    <input type="text" name="ssn" id="ssn" />
  </p>
  <p>
    <input type="submit" name="button" id="button" value="OK" />
  </p>
</form>
<?php // Edited here. Don't forget the "php" after the question mark. 

   $selectQuery = "select * from statusvalues order by lastname ASC";
   $resultName = mysql_query($selectQuery);// or die(mysql_error());

echo "<table width='400' border='1' cellspacing='0' cellpadding='0'>
  <tr>
    <td>ID</td>
    <td>First Name</td>
    <td>Last Name</td>
    <td>Region</td>
  </tr>";
  while($myRowRes = mysql_fetch_array($resultName))
  {
  echo "<tr>
    <td>".$myRowRes["statVal_id"]."</td>
       <td>".$myRowRes["firstname"]."</td>
       <td>".$myRowRes["lastname"]."</td>
       <td>".$myRowRes["region"]."</td>
        </tr>";
  }
  echo "</table>";
?>

</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.