Jump to content

Recommended Posts

I am trying to display data from a database from a form entry

 

here is the php

 

<?php

include('dbconnect.php');

 

@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT * FROM child_info";

$result=mysql_query($query);

 

$num=mysql_numrows($result);

 

mysql_close();

 

echo "<b><center>Database Output</center></b><br><br>";

 

$i=0;

while ($i < $num) {

 

$field1-name=mysql_result($result,$i,"file_number");

$field2-name=mysql_result($result,$i,"first_name");

$field3-name=mysql_result($result,$i,"middle_name");

$field4-name=mysql_result($result,$i,"last_name");

$field5-name=mysql_result($result,$i,"birthdate");

$field6-name=mysql_result($result,$i,"gender");

$field7-name=mysql_result($result,$i,"features");

$field8-name=mysql_result($result,$i,"diagnosis");

$field9-name=mysql_result($result,$i,"description");

echo "<b>$field1-name

$field2-name2</b><br>$field3-name<br>$field4-name<br>$field5-name<hr><br>";

 

$i++;

}

 

?>

 

here is the form I am using

 

<form name="child_info" action="selectdata.php" method="post"  id="child_info">

                <table width="444" align="center" >

      <tr>

                                    <td>

                                    Search by Name:

                                    </td>

                                    <td>

                                    First Name:<input type="text" class="form-textbox " id="first_name" name="first_name" size="20" /><br />

                                        Last Name:<input type="text" class="form-textbox " id="last_name" name="last_name" size="20" />

                                    </td>

                                </tr>

                            <tr>

                                <td width="208">

                                    Choose Male or Female:                                    </td>

                                <td width="224">

                                <input type="radio" name="gender" value="male" />

              Male

              <input type="radio" name="gender" value="Female" />

              Female                                  </td>

                            </tr>

                            <tr>

                            <td>

                                Choose age range:                               

                                </td>

                                <td>

                                  <select name="first_age" id="first_age">

                                  <option value="00">From</option>

                                  <option value="1">1</option>

                                  <option value="2">2</option>

                                  <option value="3">3</option>

                                  <option value="4">4</option>

                                  <option value="5">5</option>

                                  <option value="6">6</option>

                                  <option value="7">7</option>

                                  <option value="8">8</option>

                                  <option value="9">9</option>

                                  <option value="10">10</option>

                                  <option value="11">11</option>

                                  <option value="12">12</option>

                                  <option value="13">13</option>

                                  <option value="14">14</option>

                                  <option value="15">15</option>

                                  <option value="16">16</option>

                                  <option value="17">17</option>

                                  <option value="18">18</option>

                                </select>

                                <select name="second_age" id="second_age">

                                  <option value="00">To</option>

                                  <option value="1">1</option>

                                  <option value="2">2</option>

                                  <option value="3">3</option>

                                  <option value="4">4</option>

                                  <option value="5">5</option>

                                  <option value="6">6</option>

                                  <option value="7">7</option>

                                  <option value="8">8</option>

                                  <option value="9">9</option>

                                  <option value="10">10</option>

                                  <option value="11">11</option>

                                  <option value="12">12</option>

                                  <option value="13">13</option>

                                  <option value="14">14</option>

                                  <option value="15">15</option>

                                  <option value="16">16</option>

                                  <option value="17">17</option>

                                  <option value="18">18</option>

                                </select>

                              </td>

                            </tr>

                            <tr>

                            <td>

                                </td>

                                <td>

                                </td>

                            </tr>

                            <tr>

                            <td>

                                </td>

                                <td>

                                <div align="right">

                                  <input type="submit" name="submit" id="submit" value="submit" />

                                  <input type="reset" name="reset" id="reset" value="reset" />

                                  </div></td>

                            </tr>

                    </table>

                    </form>

 

first problem is getting the form to use the php

 

second problem is when i try to use the php alone is I get this error

 

Parse error: syntax error, unexpected '=' in /home/fathersh/public_html/selectdata.php on line 17  17 is highlighted above in the php

Link to comment
https://forums.phpfreaks.com/topic/258476-displaying-data-from-database/
Share on other sites

include('dbconnect.php');

@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT file_number, first_name, middle_name, last_name, birthdate
          FROM child_info";
$result = mysql_query($query);
mysql_close();

if(!$result)
{
    echo "There was a problem getting the data";
}
elseif(!$result)
{
    echo "There were no results";
}
else
(
    echo "<b><center>Database Output</center></b><br><br>\n";
    while($row = mysql_fetch_assoc($result))
    {
        echo "<b>{$row['file_number']}-name{$row['first_name']}-name2</b><br>\n";
        echo "{$row['middle_name']}-name<br>\n";
        echo "{$row['last_name']}-name<br>\n";
        echo "{$row['birthdate']}-name<hr><br>\n";

    }
}

Cleaned up form

<?php
$max_age = 18;

$ageOptions = "<option value='00'>From</option>\n";
for($age=1; $age<=$max_age; $age++)
{
    $ageOptions .= "<option value='{$age}'>{$age}</option>\n";
}

?>

<form name="child_info" action="selectdata.php" method="post"  id="child_info">
<table width="444" align="center" >
    <tr>
        <td>Search by Name:</td>
        <td>
            First Name:<input type="text" class="form-textbox " id="first_name" name="first_name" size="20" /><br />
            Last Name:<input type="text" class="form-textbox " id="last_name" name="last_name" size="20" />
        </td>
    </tr>
    <tr>
        <td width="208">Choose Male or Female:</td>
        <td width="224">
            <input type="radio" name="gender" value="male" /> Male
            <input type="radio" name="gender" value="Female" /> Female
        </td>
    </tr>
    <tr>
        <td>Choose age range:</td>
        <td>
            <select name="first_age" id="first_age">
            <?php echo $ageOptions; ?>
            </select>
            <select name="second_age" id="second_age">
            <?php echo $ageOptions; ?>
            </select>
        </td>
    </tr>
    <tr>
        <td></td>
        <td>
            <div align="right">
            <input type="submit" name="submit" id="submit" value="submit" />
            <input type="reset" name="reset" id="reset" value="reset" />
            </div>
        </td>
    </tr>
</table>
</form>

<?php

$con = mysql_connect("localhost","fathersh_search","blanked out");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("fathersh_childsearch", $con);

@mysql_select_db($database) or die( "Unable to select database");

$query = "SELECT file_number, first_name, middle_name, last_name, birthdate

          FROM child_info";

 

$result = mysql_query($query);

 

mysql_close();

 

if(!$result)

{

  echo "There was a problem getting the data";

}

elseif(!$result)

{

echo "There were no results";

}

else

(

    "<b><center>Database Output</center></b><br><br>\n";

    while($row = mysql_fetch_assoc($result))

    {

echo "<b>{$row['file_number']}-name{$row['first_name']}-name2</b><br>\n";

echo "{$row['middle_name']}-name<br>\n";

echo "{$row['last_name']}-name<br>\n";

echo "{$row['birthdate']}-name<hr><br>\n";

 

}

}

?>

 

this is the new code but now giving me new error :

 

Parse error: syntax error, unexpected ';' in /home/fathersh/public_html/selectdata.php on line 27 in bold

ok i fixed the parse error  there was a ) instead of a }      but now it says I cant select the database I know the database details are correct

<?php

$con = mysql_connect("localhost","fathersh_search","");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("fathersh_childsearch", $con);

@mysql_select_db($database) or die( "Unable to select database");

$query = "SELECT file_number, first_name, middle_name, last_name, birthdate

          FROM child_info";

 

$result = mysql_query($query);

 

 

if(!$result)

{

  echo "There was a problem getting the data";

}

else if(!$result)

{

echo "There were no results";

}

else

{

    echo "<b><center>Database Output</center></b><br><br>\n";"<b><center>Database Output</center></b><br><br>\n";

    while($row = mysql_fetch_assoc($result))

    {

echo "<b>{$row['file_number']}-name{$row['first_name']}-name2</b><br>\n";

echo "{$row['middle_name']}-name<br>\n";

echo "{$row['last_name']}-name<br>\n";

echo "{$row['birthdate']}-name<hr><br>\n";

 

}

}

mysql_close();

?>

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/fathersh/public_html/selectdata.php on line 29 in bold

 

<?php

$con = mysql_connect("localhost","fathersh_search","f33321rh");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("fathersh_childsearch", $con);

@mysql_select_db($database) 'or die ("Unable to select database: " . mysql_error())"

$query = "SELECT file_number, first_name, middle_name, last_name, birthdate

          FROM child_info";

 

$result = mysql_query($query);

 

 

if(!$result)

{

  echo "There was a problem getting the data";

}

else if(!$result)

{

echo "There were no results";

}

else

{

    echo "<b><center>Database Output</center></b><br><br>\n";"<b><center>Database Output</center></b><br><br>\n";

    while($row = mysql_fetch_assoc($result))

    {

echo "<b>{$row['file_number']}-name{$row['first_name']}-name2</b><br>\n";

echo "{$row['middle_name']}-name<br>\n";

echo "{$row['last_name']}-name<br>\n";

echo "{$row['birthdate']}-name<hr><br>\n";

 

}

}

mysql_close();

?>

this are 2 lines in your posted code:

 

mysql_select_db("fathersh_childsearch", $con);
@mysql_select_db($database) 'or die ("Unable to select database: " . mysql_error())"

 

seems ok to you?  ... mysql_select_db() twice? and the second with more than evident errors?

this are 2 lines in your posted code:

 

mysql_select_db("fathersh_childsearch", $con);
@mysql_select_db($database) 'or die ("Unable to select database: " . mysql_error())"

 

seems ok to you?  ... mysql_select_db() twice? and the second with more than evident errors?

 

toney what are you using to edit your php? even a simple editor that color codes would give you a better idea of where you are messing up quotes.

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.