Jump to content
xisto Community
psychiccyberfreak

Problem With Php anything that accesses a mySQL database

Recommended Posts

Hey.I'm having a problem with PHP, when I have a script access a database, it comes back blank... I was wondering why this happens and what I could do to fix it or if any of you could fix it. Yes, everything else in PHP works, Yes, I have tested this on multiple computers.Thanks for the help :D

Share this post


Link to post
Share on other sites

I will try to help you out the best I can. What is it that you are trying to run exactly and is it happening with every query or just on one peticular query.It could be a problem as simple as it is not connecting to the database because of a user or pass error. Have you tried simply connecting to the database from a terminal(i dont know if you use linux) but i believe windows has a proggy to do it as well. If you are unable to connect to your database, then there is your problem. That is what it usually means when it spits back blank data. It could also be a problem with the php coding on the page that you are trying to access the sql database with. Please let me know if this helps, if not we can move on to the next troubleshooting. I would help me out a lot however if i could get my hands on the scripts that you are trying to execute that way i could take a look at the code.Thanks,JT

Share this post


Link to post
Share on other sites

Is there any particular reason why you haven't posted the script that's giving you trouble? Pretty hard for people to diagnose accurately the problem when they don't even know what you're working with.

Share this post


Link to post
Share on other sites

The thing a lot of people seem to get wrong on Trap 17 is that when you enter the database name, you have to prefix it with your username. For example, if you created a database called info the database name would be psychiccyberfreak_info. This only applies for T17. If you're running it on your own PC then you don't need to prefix it.

 

Also, make sure you have done everything in the 'step-by-step' process.

Connect to MySQL

Select the database

Carry out the query

Loads of people miss out one of the first two, or both, and just expect it to intuitively know all your MySQL login data.

 

As many people have said, having a copy of the script would be helpful.

Share this post


Link to post
Share on other sites

Also, make sure you have done everything in the 'step-by-step' process.

Connect to MySQL

 

Select the database

 

Carry out the query


I agree, these 3 points are required!

This is example for 1st point:

<?php   $link = mysql_connect("localhost", "mysql_user", "mysql_password")       or die("Could not connect: " . mysql_error());   print ("Connected successfully");   mysql_close($link);?>

Where "mysql_user", "mysql_password" U must create in Your myPHPadmin Console.

 

This is example for 2nd point:

<?phpmysql_select_db('DB_name', $link);?>

This is example for 3rd point:

<?php$res = mysql_query("SELECT my_col FROM my_tbl")   or die("Invalid query: " . mysql_error());$row = mysql_fetch_array($res);print_r($row); // Result: still return Array()?> 

And simple code for all points.

The following query is not valid as expected:

 

<?php$username = 'dicteworld';$username{4} = '';$sql = "SELECT * FROM `user` WHERE `User` = '$username'";print($sql); // Result: SELECT * FROM `user` WHERE `User` = 'dictworld'$res = mysql_query($query);$row = mysql_fetch_array($res);print_r($row);// Result: still return Array(), supposed that the user 'dictworld' exists.?>

Pay more attention that null string '' is equivalent to '\0',therefore SQL statement above is equivalent to SELECT * FROM `user` WHERE `User` = 'dict\0world',though printing string is right.

 

I find this on http://php.net/

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.