PDA

View Full Version : PHP help.



Excellent
03-08-2008, 08:51 PM
Hey, I've just finished a little script I was creating. I submitted an entry to a database and on another file I displayed the contents of the database. I created a little file that deletes all entries from the database and it worked.. but now when I submit another entry to the database it doesn't display anything when I go to fetch the contents, just a white page.

This is the code I am using.

<?php
include 'database.php';
$fetch = mysql_query("SELECT * FROM database");
while ($display = mysql_fetch_array($fetch)) {
echo "
Blah: $display[blah]
";
}
?>Obviously I've taked out the function names and such but does anybody know why it's not displaying anything? (It used to work before I deleted the entries)

Calon
03-08-2008, 09:00 PM
Hey, I've just finished a little script I was creating. I submitted an entry to a database and on another file I displayed the contents of the database. I created a little file that deletes all entries from the database and it worked.. but now when I submit another entry to the database it doesn't display anything when I go to fetch the contents, just a white page.

This is the code I am using.

<?php
include 'database.php';
$fetch = mysql_query("SELECT * FROM database");
while ($display = mysql_fetch_array($fetch)) {
echo "
Blah: $display[blah]
";
}
?>Obviously I've taked out the function names and such but does anybody know why it's not displaying anything? (It used to work before I deleted the entries)


<?php
include "database.php"; // Hate single quotes. :P
$result = mysql_query("SELECT * FROM `database`"); // prefer result.
while($row = mysql_fetch_array($result)) {
echo "bla: ". $row[""] ."";
}
?>

[/php]

Excellent
03-08-2008, 09:03 PM
Thanks but it still isn't displaying anything. Nothing can be wrong with my submit code due to it working before I deleted all entries.

Calon
03-08-2008, 09:04 PM
Thanks but it still isn't displaying anything. Nothing can be wrong with my submit code due to it working before I deleted all entries.
Doubt it, paste all code but remove passwords etc.

Robbie
03-08-2008, 09:11 PM
Are you 100% sure there is data in the table?

Excellent
03-08-2008, 09:16 PM
Are you 100% sure there is data in the table?Is there anyway I could check in PMA?

Excellent
03-08-2008, 09:53 PM
*bump* still need help :D

Johno
03-08-2008, 10:01 PM
To check for data in phpMyAdmin select the database, then the table and then click browse?

If there is data there then its not outputting correctly, if not then its not submitting it correctly.

Excellent
03-08-2008, 10:07 PM
To check for data in phpMyAdmin select the database, then the table and then click browse?

If there is data there then its not outputting correctly, if not then its not submitting it correctly.Just displays all my rows.

iJoe
03-08-2008, 11:30 PM
when you see the rows, click browse :) should then show data (if any)

Protege
04-08-2008, 12:14 AM
<?php
include( 'database.php' );

if( $mysqlQuery = mysql_query( 'SELECT * FROM `database`' ) )
{
if( mysql_num_rows( $mysqlQuery ) <= 0 )
{
echo( 'No data in table' );
}
else
{
while( $mysqlFetch = mysql_fetch_array( $mysqlQuery ) )
{
echo( 'Blah: ' . $mysqlFetch[ 'blah' ] );
// print_r( $mysqlFetch );
// That will show you whats int he array etc ( field name etc )
}
}
}
else
{
echo( 'Mysql Error' );
}
?>


Checks rows etc before broadcasting data

Hypertext
04-08-2008, 03:56 AM
<?php
include 'database.php';

if($mysqlQuery = mysql_query('SELECT * FROM database.`table`')) {
if(mysql_num_rows($mysqlQuery) = 0 ) {
echo 'No data in table';
}
else {
while($mysqlFetch = mysql_fetch_array($mysqlQuery)) {
echo 'Blah: '.$mysqlFetch['blah'];
}
}
}
else {
echo 'Mysql Error';
}
?>

Tidied up version of protege's.

Calon what is


. '';
//Why would you concatenate an empty string :S

Jahova
04-08-2008, 06:37 AM
Looks like it has been fixed.
Anyway, it could've just appeared in phpmyadmin. So you should've checked their first.

Protege
04-08-2008, 07:14 AM
<?php
include 'database.php';

if($mysqlQuery = mysql_query('SELECT * FROM database.`table`')) {
if(mysql_num_rows($mysqlQuery) = 0 ) {
echo 'No data in table';
}
else {
while($mysqlFetch = mysql_fetch_array($mysqlQuery)) {
echo 'Blah: '.$mysqlFetch['blah'];
}
}
}
else {
echo 'Mysql Error';
}
?> Tidied up version of protege's.

Calon what is


. '';
//Why would you concatenate an empty string :S

You haven't fixed **** all mate, your just trying to be clever and again failing.


<?php
include_once( 'database.php' );

if( $mysqlQuery = mysql_query( 'SELECT * FROM `database`' ) )
{
if( mysql_num_rows( $mysqlQuery ) <= 0 )
{
echo( 'No data in table' );
}
else
{
while( FALSE === ( $mysqlFetch = mysql_fetch_array( $mysqlQuery ) ) )
{
echo( 'Blah: ' . $mysqlFetch[ 'blah' ] );
// print_r( $mysqlFetch );
// That will show you whats int he array etc ( field name etc )
}
}
}
else
{
echo( 'Mysql Error' ); // Using brackets, isn't wrong.
}
?>

Protege
04-08-2008, 07:50 AM
This is a better version:


<?php
include_once( 'database.php' );

if( $mysqlQuery = mysql_query( 'SELECT * FROM `database`' ) )
{
if( mysql_num_rows( $mysqlQuery ) >= 1 )
{
while( FALSE === ( $mysqlFetch = mysql_fetch_array( $mysqlQuery ) ) )
{
echo( 'Blah: ' . $mysqlFetch[ 'blah' ] );
// print_r( $mysqlFetch );
// That will show you whats int he array etc ( field name etc )
}
}
else
{
echo( 'No data in table' );
}
}
else
{
echo( 'Mysql Error' ); // Using brackets, isn't wrong.
}

?>

Calon
04-08-2008, 08:13 AM
What the hell Hypertext? Have you read my code..




<?php
include "database.php"; // Hate single quotes. :P
$result = mysql_query("SELECT * FROM `database`"); // prefer result.
while($row = mysql_fetch_array($result)) {
echo "bla: ". $row[""] ."";
}
?>


I left Lucas to put in the row, because some people are capable of doing that.

Excellent
04-08-2008, 01:01 PM
Thanks guys, I've checked in phpmyadmin and it's just not submitting any data to the database. Checked my submit code and nothing has been changed since it worked.

Invent
04-08-2008, 01:44 PM
Charlie, your version is a lot more messier than Protege's.


What the hell Hypertext? Have you read my code..


I left Lucas to put in the row, because some people are capable of doing that.

I think he means where you have:


echo "bla: ". $row[""] ."";


You should just have:


echo "bla: ". $row[""];

Excellent
04-08-2008, 01:58 PM
Charlie, your version is a lot more messier than Protege's.



I think he means where you have:


echo "bla: ". $row[""] ."";
You should just have:


echo "bla: ". $row[""];

Yeah, input the id's :P Fixed now, had to delete the whole database and make a new one with new names, weird :S

Calon
04-08-2008, 02:06 PM
Charlie, your version is a lot more messier than Protege's.



I think he means where you have:


echo "bla: ". $row[""] ."";
You should just have:


echo "bla: ". $row[""];

Oh, I leave it within the quotations.

Protege
04-08-2008, 02:23 PM
See the . (dot) as a + (plus) for example.

So you don't go in maths 10+5+

Hypertext
05-08-2008, 12:49 AM
My version is messier? How so? All I did was take out his ( )'s on the language constructs, as they don't need them. And took out useless concatenations. Calon, I meant what Invent! said, don't get snappy with me.

Ooh Protege, after reading your second response, it's even funnier.



while( FALSE === ( $mysqlFetch = mysql_fetch_array( $mysqlQuery ) ) )
Please tell me your not serious. Why on earth would you clarify a boolean value against something that automatically returns a boolean value.

In your query why would you check if the number of rows is SMALLER THAN or equal to 0, how would it be smaller than zero?

SELECT * FROM `database`

I won't be picky about that seeing as it would work, but seeing as you wrote 'database' it should be SELECT * FROM database.`table`

Why wouldn't you just put in an or die(mysql_error()) after your mysql_query, that way you can have some informative information upon error.

And your still using parentheses in your language constructs, which is bad practice.

I'll get flamed for this but whatever.

Invent
05-08-2008, 12:56 AM
My version is messier? How so?His coding is a lot more fluent and clean. He has used whitespace properly which makes his coding easy to read and understand. (Which will help immensly if debugging is needed).

Thats how and why I think your code is messier.

Calon
05-08-2008, 02:18 AM
His coding is a lot more fluent and clean. He has used whitespace properly which makes his coding easy to read and understand. (Which will help immensly if debugging is needed).

Thats how and why I think your code is messier.
He fixed it already.

Excellent
05-08-2008, 02:26 AM
My version is messier? How so? All I did was take out his ( )'s on the language constructs, as they don't need them. And took out useless concatenations. Calon, I meant what Invent! said, don't get snappy with me.

Ooh Protege, after reading your second response, it's even funnier.



while( FALSE === ( $mysqlFetch = mysql_fetch_array( $mysqlQuery ) ) )
Please tell me your not serious. Why on earth would you clarify a boolean value against something that automatically returns a boolean value.

In your query why would you check if the number of rows is SMALLER THAN or equal to 0, how would it be smaller than zero?

SELECT * FROM `database`

I won't be picky about that seeing as it would work, but seeing as you wrote 'database' it should be SELECT * FROM database.`table`

Why wouldn't you just put in an or die(mysql_error()) after your mysql_query, that way you can have some informative information upon error.

And your still using parentheses in your language constructs, which is bad practice.

I'll get flamed for this but whatever.
Well I appreciate your comments but this was a quick script for someone I do part-time work for, there wasn't really any need to make all the coding clean and use or die statements as I knew this couldn't have been a connection error due to the order being processed but not displayed. In the end I just deleted my whole database, created a fresh one and gave it new names. Seems the database got locked up when I originally deleted the whole lot of information - shouldn't have used a while statement on 1 order I guess, just fetch the array. All part of the learning curve I guess!

Calon
05-08-2008, 02:35 AM
I wasn't getting snappy, I was worrying if you would get your imaginary paycheck from IN VALID SOFTWARE, INC.

Sorry for caring.

Hypertext
05-08-2008, 04:42 AM
Oh stop being a ******* jealous pisshead mother****** as your like is just one big epic fail.

As soon as I prove your coding to be **** as, you make up some garble of a retort.

Invent!, my IDE was habbox forum quick-reply, you can't expect much in the way of whitespace. Also removing all whitespace and taking away parenthesis in his language constructs would still be cleaner code than his.

Protege
05-08-2008, 04:51 AM
Not really, I can read my code and code in that form much easier than yours, you put curley brackets on the same line as the statement, what for to make it even harder to read? They're on new lines so you can easily align start/end of each statement/function... so don't think you 'removing whitespaces' will in anyway will make it cleaner, cause really it won't.

Also for your little thing parenthesis on echos, dude your losing the battle to get your point across cause really = fails.



( $hText = 'noob' ) ? echo( 'true' ) : echo( 'false );


Result:
true
I could be compressing my PHP in my real version to 'save space', dude at this point I'd insult you.

Calon
05-08-2008, 05:02 AM
Oh stop being a ******* jealous pisshead mother****** as your like is just one big epic fail.

As soon as I prove your coding to be **** as, you make up some garble of a retort.

Invent!, my IDE was habbox forum quick-reply, you can't expect much in the way of whitespace. Also removing all whitespace and taking away parenthesis in his language constructs would still be cleaner code than his.
LOL CALM DOWN!

I am new to coding.

Protege
05-08-2008, 08:37 AM
epic fail, thats right when used against yourself. He's like Klydo, loolage - must be fegbrothers

Hypertext
05-08-2008, 01:16 PM
Well, don't be a smartass then.

Agnostic Bear
05-08-2008, 01:25 PM
You haven't fixed **** all mate, your just trying to be clever and again failing.


<?php
include_once( 'database.php' );

if( $mysqlQuery = mysql_query( 'SELECT * FROM `database`' ) )
{
if( mysql_num_rows( $mysqlQuery ) <= 0 )
{
echo( 'No data in table' );
}
else
{
while( FALSE === ( $mysqlFetch = mysql_fetch_array( $mysqlQuery ) ) )
{
echo( 'Blah: ' . $mysqlFetch[ 'blah' ] );
// print_r( $mysqlFetch );
// That will show you whats int he array etc ( field name etc )
}
}
}
else
{
echo( 'Mysql Error' ); // Using brackets, isn't wrong.
}
?>


cough your code is wrong too so don't go gay about it, it's


while( false !== ( mysql ******** in here ) )
not

while( false === ( mysql ******** in here ) )

Calon
05-08-2008, 01:46 PM
Well, don't be a smartass then.
Well, don't deem my code as wrong if you don't know how it works.

Protege
05-08-2008, 02:12 PM
I knew it was wrong after I posted it twice but you just had to notice lol ****.

NN-Dom
05-08-2008, 07:15 PM
Charlie, every thread i see you in your actin like a smartarse, calons cool, unless you get the wrong side of him (:D).

Redacted
05-08-2008, 07:16 PM
rename the database

Calon
05-08-2008, 07:18 PM
Charlie, every thread i see you in your actin like a smartarse, calons cool, unless you get the wrong side of him (:D).
um.. lol?

It's ok, lucas fixed the problem.. PMA usually screws up if you don't clear the entries properly.

Excellent
05-08-2008, 07:47 PM
rename the databaseIf you bothered to read back a page or so I already stated I fixed the problem..

Want to hide these adverts? Register an account for free!