Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
getting a blank page when running php/sql
Old 04-24-2005, 07:06 AM getting a blank page when running php/sql
HitRaj47's Avatar
Extreme Talker

Posts: 177
Location: GA
Trades: 0
I just get a blank page when i run this code:

PHP Code:
<?php

// Connect to database
mysql_connect('localhost''username''password'); // I put in my proper username and password, I just changed it here for security reasons

mysql_select_db('users');    // Select the database

$password "testpass";
$password crypt($password);

// Define and execute query
$query "INSERT INTO accounts (user_id, username, password, email) VALUES (0, 'testing', $password, 'webmaster@fnar.sytes.net')";
mysql_query($query);

// Define the query
$query2 'SELECT * FROM accounts ORDER BY user_id DESC';

if (
$r mysql_query($query2)) {    // Run the query

    // Retrieve every record
    
while ($row mysql_fetch_array ($r)) {
        print 
"<table><tr><td>user_id</td><td>username</td><td>password</td><td>email</td></tr>
        <tr><td>
{$row['user_id']}</td><td>{$row['username']}</td><td>{$row['password']}</td><td>{$row['email']}</td></tr></table>";
    }

} else {
die (
'<p>query did not run</p>');
}

mysql_close();    // Close Db connection

?>
HitRaj47 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-24-2005, 07:30 AM
Bloodsyne's Avatar
Skilled Talker

Posts: 52
Trades: 0
Hmm...

PHP Code:
<?php
$password 
"testpass";
$password crypt($password);

// Define and execute query
$query " INSERT INTO `accounts` (`user_id`, `username`, `password`, `email`) VALUES ('0', 'testing', '$password', 'webmaster@fnar.sytes.net'); ";
mysql_query($query);

// Define the query
$query2 " SELECT * FROM `accounts` ORDER BY user_id DESC ";

$r mysql_query($query2);

if (!
$r) {
   die (
"<p>query did not run</p>");
} else {
    while (
$row mysql_fetch_array($rMYSQL_ASSOC)) {        print("<table><tr><td>user_id</td><td>username</td><td>password</td><td>email</td></tr>
        <tr><td>" 
$row['user_id'] . "</td><td>" $row['username'] . "</td><td>" $row['password'] . "</td><td>" $row['email'] . "</td></tr></table>");
    }
}

mysql_close();    // Close Db connection

?>
Try that... if it works, tell me and I'll explain what I did. (Just make sure to include the connection variables and all that, too, I excluded them here.)

By the way, for the record: you're getting a blank page because the browser sees nothing to display, meaning that the "while" statement isn't executing (and thusly, the if returned false), meaning that a) that code in the IF just doesn't work or b) there is nothing in the table to be returned by the query.

Last edited by Bloodsyne; 04-24-2005 at 07:33 AM..
Bloodsyne is offline
Reply With Quote
View Public Profile
 
Old 04-24-2005, 07:56 AM
HitRaj47's Avatar
Extreme Talker

Posts: 177
Location: GA
Trades: 0
that code worked!

so what was it you did?
HitRaj47 is offline
Reply With Quote
View Public Profile
 
Old 04-24-2005, 08:13 AM
Bloodsyne's Avatar
Skilled Talker

Posts: 52
Trades: 0
Quite a bit, actually.

PHP Code:
<?php
$password 
"testpass";
$password crypt($password);

$query " INSERT INTO `accounts` (`user_id`, `username`, `password`, `email`) VALUES ('0', 'testing', '$password', 'webmaster@fnar.sytes.net'); "/* added tilde's (`) to the first values and apostrophe's to all the rest (also added the final ); in the query)
mysql_query($query); */

$query2 " SELECT * FROM `accounts` ORDER BY user_id DESC "// same thing--just a little more formatting

$r mysql_query($query2); // ran the query seperately (as to get easier output)

if (!$r) { // changed it so that instead of checking to see if the query ran, it checks to see if the query was a success
   
die ("<p>query did not run</p>"); // switched the order in which things occured. Errors usually go first, then the success actions
} else {
    while (
$row mysql_fetch_array($rMYSQL_ASSOC)) { /* added MYSQL_ASSOC, which means that the values of $row will be arrayed with the associated table name (which may be auto, but I wasn't sure)  */

print("<table><tr><td>user_id</td><td>username</td><td>password</td><td>email</td></tr>
        <tr><td>" 
$row['user_id'] . "</td><td>" $row['username'] . "</td><td>" $row['password'] . "</td><td>" $row['email'] . "</td></tr></table>"); /* changed the actual display variables ($row['user_id']) so that they were included with " . XX . " rather than what you originally had, {XX} (which I've never seen before. When including variables in a print function, I think you have to use print("Rawr: " . $var); */
    
}
}

mysql_close();

?>
Just take a look at all the comments. I deleted all others and wrote new ones based on what I did.

Last edited by Bloodsyne; 04-24-2005 at 08:15 AM..
Bloodsyne is offline
Reply With Quote
View Public Profile
 
Old 04-24-2005, 08:28 AM
HitRaj47's Avatar
Extreme Talker

Posts: 177
Location: GA
Trades: 0
thanks alot

im learning php and i have a book. the tutorials in the book dont use the tilde's and they didnt put the ; at the end of the queries. yet they still work
HitRaj47 is offline
Reply With Quote
View Public Profile
 
Old 04-24-2005, 08:34 AM
Bloodsyne's Avatar
Skilled Talker

Posts: 52
Trades: 0
I picked that up from phpMyAdmin, actually.

But yeah, you'll find that that's a major downside to PHP books. They're not entirely up-to-date and don't always have the most streamlined code (not like mine is streamline, but I've seen what they have examples for sometimes). It's always good to reconcile with the php.net documentary (extremely useful).
Bloodsyne is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to getting a blank page when running php/sql
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28518 seconds with 12 queries