[SOLVED] PHP database code issue

This is a discussion on "[SOLVED] PHP database code issue" within the PHP Forum section. This forum, and the thread "[SOLVED] PHP database code issue are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #41 (permalink)  
Old Mar 25th, 2008, 23:25
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 942
Blog Entries: 8
Thanks: 2
Thanked 22 Times in 22 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: PHP database code issue

when the page blank, look at the source. anything there?
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: More Cheat Sheets (Jul 12th, 2008)
Reply With Quote
  #42 (permalink)  
Old Mar 25th, 2008, 23:40
acrikey's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP database code issue

No but I think there is something wrong with the code, as the code is red after the last ?>
I'll upload code
Reply With Quote
  #43 (permalink)  
Old Mar 25th, 2008, 23:40
acrikey's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP database code issue

Code: Select all
<head>
<title>Account Details</title></head>


<html>
<style type="text/css">
<!--
@import url("default.css");
<!--
body {
    background-repeat: repeat-x;
}
-->
</style>
<body>
<div id="header">
<script>
var Digital=new Date()
var month=Digital.getMonth()
if (month <= 2){    // month is between jan and march    
    document.write("<IMG SRC='http://www.lightex.co.uk/fieldworks/images/img5.jpg'>");
} else if (month <= 5){
    // month is between april and june
    document.write("<IMG SRC='http://www.lightex.co.uk/fieldworks/images/img2.jpg'>");
} else if (month <= 8){    // july and september
    document.write("<IMG SRC='http://www.lightex.co.uk/fieldworks/images/img2.jpg'>");
} else {    // otherwise its between oct and dec
    document.write("<IMG SRC='http://www.lightex.co.uk/fieldworks/images/img3.jpg'>");
}
</script>
</div>
<div id="page">
  <div id="content">
        <div id="welcome" class="post">
            <h1 class="title">Account Details</h1>
            <div class="content"><img src="http://www.webforumz.com/images/420 copy.png" alt="" width="131" height="106" class="left" />
                <h3 align="center"><br />
                </h3>
                <h3 align="center">The professional approach to paddock maintenance.</h3>
          </div>
    </div>
        <div id="example" class="post">
            <h2 class="title">&nbsp;</h2>
            
<?php
ob_start()
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name

    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    m// issue the query
    $sql = "SELECT * FROM members WHERE
            username = '".$_POST["username"]."' AND
            password = '".$_POST["password"]."'; 
    $result = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli));
    if($info = mysqli_fetch_array($result)) { 
            //display string
       $display_block = "
    <p>".$info['f_name']." <p>
    <p>".$info['l_name']." <p>"; 

    echo $display_block; 
    } else {
       echo '<p>Wrong username and password!</p>';
    } 
    ?>


            
            <div class="content">
                                  
              
          </div>
        </div>
  </div>
    <div id="sidebar">
        <div id="menu">
            <ul>
              <li><a href="homepage.html" onclick="logout_confirm(); return false;">Homepage</a>
             <script> function logout_confirm() {
  if(confirm("You are about to logout?"))
    window.location = "homepage.html";
}</script></li>
                <li><a href="login_success.php" title="">Login Homepage</a></li>
              <li><a href="fieldworks/accountdetails.php" title="">Account Detail</a></li>
                <li><a href="lastbill.php" title="">Last Bill</a></li>
                <li><a href="estatedetails.php" title="">Estate Details</a></li>
                <li><a href="fieldworks/contactuslogin.php" title="">Contact Us</a></li>
            </ul>
        </div>
        <div id="login" class="boxed">
            <h2 class="title">Next Vistit</h2>
            <div class="content">
            
          </div>
        </div>
        <div id="updates" class="boxed">
            <h2 class="title">Time</h2>
            <div class="content">
                <!-- Paste this code into the BODY section of your HTML document  -->


            </div>
        </div>
    </div>
    <div style="clear: both;">&nbsp;</div>
</div>
<div id="footer">Copyright &copy; 2008 fieldworks.com. Designed by <a href="ttp://www.blanedesigns.com">Blane Designs</a>
  <p id="links"><br />
  <a href="#">Privacy Policy</a></p>
</div>
</body>
</html>

Last edited by acrikey; Mar 26th, 2008 at 11:08.
Reply With Quote
  #44 (permalink)  
Old Mar 25th, 2008, 23:42
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 942
Blog Entries: 8
Thanks: 2
Thanked 22 Times in 22 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: PHP database code issue

is it saved as a .php file?
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: More Cheat Sheets (Jul 12th, 2008)
Reply With Quote
  #45 (permalink)  
Old Mar 25th, 2008, 23:42
acrikey's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP database code issue

yes
Reply With Quote
  #46 (permalink)  
Old Mar 25th, 2008, 23:46
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 942
Blog Entries: 8
Thanks: 2
Thanked 22 Times in 22 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: PHP database code issue

is this on your local machine or a host? Does your host support PHP?
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: More Cheat Sheets (Jul 12th, 2008)
Reply With Quote
  #47 (permalink)  
Old Mar 25th, 2008, 23:46
acrikey's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP database code issue

http://www.lightex.co.uk/fieldworks/accountdetails.php

Alert Box UN: test
Alert box PW: webforumz

site UN: webforumz
site PW: webforumz
Reply With Quote
  #48 (permalink)  
Old Mar 25th, 2008, 23:46
acrikey's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP database code issue

host and yes they can support php5
Reply With Quote
  #49 (permalink)  
Old Mar 26th, 2008, 00:00
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 942
Blog Entries: 8
Thanks: 2
Thanked 22 Times in 22 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: PHP database code issue

PHP: Select all

<?php
ob_start
()
$host="localhost"// Host name
$username="fieldworks"// Mysql username
right there. Get rid of that ob_start(). You don't need it and that most likely is whats causing the problems.
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: More Cheat Sheets (Jul 12th, 2008)
Reply With Quote
  #50 (permalink)  
Old Mar 26th, 2008, 11:11
acrikey's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP database code issue

Still blank and the ob is removed
Reply With Quote
  #51 (permalink)  
Old Mar 26th, 2008, 14:14
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 942
Blog Entries: 8
Thanks: 2
Thanked 22 Times in 22 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: PHP database code issue

just as a test, insert this somewhere in your PHP code:

PHP: Select all

nonexistant("asdfasd); 

See if that returns any sort of error.
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: More Cheat Sheets (Jul 12th, 2008)
Reply With Quote
  #52 (permalink)  
Old Mar 26th, 2008, 14:23
acrikey's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP database code issue

Still blank, nothing returned
Reply With Quote
  #53 (permalink)  
Old Mar 26th, 2008, 14:26
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 942
Blog Entries: 8
Thanks: 2
Thanked 22 Times in 22 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: PHP database code issue

are any other PHP pages working?
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: More Cheat Sheets (Jul 12th, 2008)
Reply With Quote
  #54 (permalink)  
Old Mar 26th, 2008, 14:36
acrikey's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP database code issue

none with this code but others yes
Reply With Quote
  #55 (permalink)  
Old Mar 26th, 2008, 14:38
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 942
Blog Entries: 8
Thanks: 2
Thanked 22 Times in 22 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: PHP database code issue

hmmmm

contact your host. tell them nothing is displaying, including errors.
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: More Cheat Sheets (Jul 12th, 2008)
Reply With Quote
  #56 (permalink)  
Old Mar 26th, 2008, 14:43
acrikey's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP database code issue

But surely it must be the code because, it displays until I put the db code in the script
Reply With Quote
  #57 (permalink)  
Old Mar 26th, 2008, 14:46
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 942
Blog Entries: 8
Thanks: 2
Thanked 22 Times in 22 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: PHP database code issue

im pretty sure it is the code also, but the code must have a fatal error if its not displaying anything, and its not showing the fatal error. so contact your host about its PHP error settings.
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: More Cheat Sheets (Jul 12th, 2008)
Reply With Quote
  #58 (permalink)  
Old Mar 26th, 2008, 14:49
acrikey's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP database code issue

hang on I'll just run a quick test, bare with me
Reply With Quote
  #59 (permalink)  
Old Mar 26th, 2008, 14:49
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 942
Blog Entries: 8
Thanks: 2
Thanked 22 Times in 22 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: PHP database code issue

yep, there were several errors in the code. I debugged em, so use this code:

PHP: Select all

<html>
<head>
<title>Account Details</title></head>


<html>
<style type="text/css">
<!--
@import url("default.css");
<!--
body {
    background-repeat: repeat-x;
}
-->
</style>
<body>
<div id="header">
<script>
var Digital=new Date()
var month=Digital.getMonth()
if (month <= 2){    // month is between jan and march    
    document.write("<IMG SRC='http://www.lightex.co.uk/fieldworks/images/img5.jpg'>");
} else if (month <= 5){
    // month is between april and june
    document.write("<IMG SRC='http://www.lightex.co.uk/fieldworks/images/img2.jpg'>");
} else if (month <= 8){    // july and september
    document.write("<IMG SRC='http://www.lightex.co.uk/fieldworks/images/img2.jpg'>");
} else {    // otherwise its between oct and dec
    document.write("<IMG SRC='http://www.lightex.co.uk/fieldworks/images/img3.jpg'>");
}
</script>
</div>
<div id="page">
  <div id="content">
        <div id="welcome" class="post">
            <h1 class="title">Account Details</h1>
            <div class="content"><img src="http://www.webforumz.com/images/420 copy.png" alt="" width="131" height="106" class="left" />
                <h3 align="center"><br />
                </h3>
                <h3 align="center">The professional approach to paddock maintenance.</h3>
          </div>
    </div>
        <div id="example" class="post">
            <h2 class="title">&nbsp;</h2>
            
<?php
$host
=""// Host name
$username=""// Mysql username
$password=""// Mysql password
$db_name=""// Database name
$tbl_name=""// Table name

    // Connect to server and select databse.
    
mysql_connect("$host""$username""$password")or die("cannot connect");
    
mysql_select_db("$db_name")or die("cannot select DB");

    
// issue the query
    
$sql "SELECT * FROM members WHERE
            username = '"
.$_POST["username"]."' AND
            password = '"
.$_POST["password"]."'"
    
$result mysqli_query($mysqli$sql) or die(mysqli_error($mysqli));
    if(
$info mysqli_fetch_array($result)) { 
            
//display string
       
$display_block "
    <p>"
.$info['f_name']." <p>
    <p>"
.$info['l_name']." <p>"

    echo 
$display_block
    } else {
       echo 
'<p>Wrong username and password!</p>';
    } 
    
?>


            
            <div class="content">
                                  
              
          </div>
        </div>
  </div>
    <div id="sidebar">
        <div id="menu">
            <ul>
              <li><a href="homepage.html" onclick="logout_confirm(); return false;">Homepage</a>
             <script> function logout_confirm() {
  if(confirm("You are about to logout?"))
    window.location = "homepage.html";
}</script></li>
                <li><a href="login_success.php" title="">Login Homepage</a></li>
              <li><a href="fieldworks/accountdetails.php" title="">Account Detail</a></li>
                <li><a href="lastbill.php" title="">Last Bill</a></li>
                <li><a href="estatedetails.php" title="">Estate Details</a></li>
                <li><a href="fieldworks/contactuslogin.php" title="">Contact Us</a></li>
            </ul>
        </div>
        <div id="login" class="boxed">
            <h2 class="title">Next Vistit</h2>
            <div class="content">
            
          </div>
        </div>
        <div id="updates" class="boxed">
            <h2 class="title">Time</h2>
            <div class="content">
                <!-- Paste this code into the BODY section of your HTML document  -->


            </div>
        </div>
    </div>
    <div style="clear: both;">&nbsp;</div>
</div>
<div id="footer">Copyright &copy; 2008 fieldworks.com. Designed by <a href="ttp://www.blanedesigns.com">Blane Designs</a>
  <p id="links"><br />
  <a href="#">Privacy Policy</a></p>
</div>
</body>
</html>
But still contact your host about its error settings.
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: