Jump to content


Photo

NEED DATABASE HELP


  • Please log in to reply
5 replies to this topic

#1 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 30 March 2006 - 03:22 AM

ok so far heres my script

<?php
$link = mysql_connect('localhost', 'user', 'pass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br>';
?>


know i want it to display information from the database "test" on table "people" please help me with the code!
"Syntax error" .. WHERE THE **** IS IT?!

#2 warewolfe

warewolfe
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts
  • LocationOtago, NZ

Posted 30 March 2006 - 03:49 AM

Hej, try

<?php
$link = mysql_connect('localhost', 'user', 'pass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br>';

mysql_select_db("test",$link");
$result = mysql_query(SELECT * FROM people",$link);
while($row = mysql_fetch_array($result,MYSQL_NUM))
{
foreach($row as $val)
{
echo'<p>$val</p>';
}
}
?>



#3 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 30 March 2006 - 03:49 AM

Please be more specific of what you need help with as it relates to databases. For basic connect, select, and fetch see tutorials and code example at the FAQ page link bellow. Look for my post there related to MySQL data retrieval.

[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=31047\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=31047[/a]


#4 sambib

sambib
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 30 March 2006 - 04:00 AM

[!--quoteo(post=359883:date=Mar 30 2006, 01:22 PM:name=legohead6)--][div class=\'quotetop\']QUOTE(legohead6 @ Mar 30 2006, 01:22 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
ok so far heres my script

<?php
$link = mysql_connect('localhost', 'user', 'pass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br>';
?>
know i want it to display information from the database "test" on table "people" please help me with the code!
[/quote]


<?php 
{
    //attempt to connect to the database server
    //if the attempt was successful
    if (@mysql_connect('localhost', 'user', 'pass))) {
    
        //attempt to select the mycms databse
        //if the attempt was successful
        if (@mysql_select_db("test")) {
    
        //return true
        return TRUE;
        
        //Or if the selection was unsuccessful
        } else {
        
            //display error message
            echo "<p>Unable to select the database .</p>";
            
            //Return False
            return FALSE;
        }
        
    } else {
    
        //Display the error message
        echo "<p>Unable to connect to the database server</p>";
    
        //return false
        return FALSE;
    }
}

$query = "SELECT * FROM people"; //put some other criteria in to refine your query
$result = mysql_query ($query);

// check to see how many rows we have. if we have 0 rows then nothing has returned
if(mysql_num_rows($result) < 1) {

    echo('<p>the is no data in the table!</p>');

} else {
         
         //run through the results of the query and put the result into an array called $row
    while ($row = mysql_fetch_assoc($result)) { 

?>//stop the while loop and display the records

<p>here are the details of the field name<?= $row['fieldName'] ?></p> <!--change field name and fieldName for the correct names of the table fields. -->

<?php
     
} //end the while loop

?>

that should get you started

#5 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 30 March 2006 - 04:15 AM

[!--quoteo(post=359886:date=Mar 29 2006, 10:49 PM:name=warewolfe)--][div class=\'quotetop\']QUOTE(warewolfe @ Mar 29 2006, 10:49 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hej, try

<?php
$link = mysql_connect('localhost', 'user', 'pass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br>';

mysql_select_db("test",$link");
$result = mysql_query(SELECT * FROM people",$link);
while($row = mysql_fetch_array($result,MYSQL_NUM))
{
foreach($row as $val)
{
echo'<p>$val</p>';
}
}
?>
[/quote]

parse errors came up.....i dont really know the script so its hard for me to try to correct....

[!--quoteo(post=359890:date=Mar 29 2006, 11:00 PM:name=sambib)--][div class=\'quotetop\']QUOTE(sambib @ Mar 29 2006, 11:00 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
<?php 
{
    //attempt to connect to the database server
    //if the attempt was successful
    if (@mysql_connect('localhost', 'user', 'pass))) {
    
        //attempt to select the mycms databse
        //if the attempt was successful
        if (@mysql_select_db("test")) {
    
        //return true
        return TRUE;
        
        //Or if the selection was unsuccessful
        } else {
        
            //display error message
            echo "<p>Unable to select the database .</p>";
            
            //Return False
            return FALSE;
        }
        
    } else {
    
        //Display the error message
        echo "<p>Unable to connect to the database server</p>";
    
        //return false
        return FALSE;
    }
}

$query = "SELECT * FROM people"; //put some other criteria in to refine your query
$result = mysql_query ($query);

// check to see how many rows we have. if we have 0 rows then nothing has returned
if(mysql_num_rows($result) < 1) {

    echo('<p>the is no data in the table!</p>');

} else {
         
         //run through the results of the query and put the result into an array called $row
    while ($row = mysql_fetch_assoc($result)) { 

?>//stop the while loop and display the records

<p>here are the details of the field name<?= $row['fieldName'] ?></p> <!--change field name and fieldName for the correct names of the table fields. -->

<?php
     
} //end the while loop

?>

that should get you started
[/quote]

wow....umm this came up

Parse error: parse error, unexpected T_STRING in /var/www/html/PHP/data.php on line 42

[!--quoteo(post=359887:date=Mar 29 2006, 10:49 PM:name=toplay)--][div class=\'quotetop\']QUOTE(toplay @ Mar 29 2006, 10:49 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Please be more specific of what you need help with as it relates to databases. For basic connect, select, and fetch see tutorials and code example at the FAQ page link bellow. Look for my post there related to MySQL data retrieval.

[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=31047\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=31047[/a]
[/quote]

Thanks i found the stuff...but how do i set up a query..(im new to databases and php)

"Syntax error" .. WHERE THE **** IS IT?!

#6 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 31 March 2006 - 07:15 AM

<?php

$link = mysql_connect('localhost', 'user', 'pass') or die(mysql_error());
mysql_select_db('test') or die(mysql_error());

$query = mysql_query("SELECT * FROM people") or die(mysql_error());

if (mysql_num_rows($query) > 0) {
  while($row=mysql_fetch_assoc($query)) {
    print_r($row);
    echo "\r\n<br /><br />\r\n";
  }
}

mysql_close($link);

?>

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users