Portal Home > Knowledgebase > Articles Database > access database from php program


access database from php program




Posted by lauriedk, 05-31-2009, 11:11 AM
My program needs to select a username based on the criteria of the userid being 2. The database holds a table with fields userid and username. How do I access that table?

Posted by Robert vd Boorn, 05-31-2009, 11:14 AM
What database are you using?

Posted by lauriedk, 05-31-2009, 11:15 AM
The database is mysql.

Posted by lauriedk, 05-31-2009, 04:17 PM
Got the connect problem figured out. I was using the wrong host, user, and password. But now I can't get the frame to show using the code: >", "<>", "<>") or die(mysql_error()); mysql_select_db("<>") or die(mysql_error()); $id = (int)$_POST['ad']; $target = $db->query("SELECT target FROM ads WHERE id ='$id' LIMIT 1"); if($db->num_rows() < 1) {die('invalid ad id');} list($target) = $db->fetch_array($target); echo "database"; ?> Last edited by bear; 05-31-2009 at 04:58 PM.

Posted by Robert vd Boorn, 05-31-2009, 04:56 PM
I hope that that is not the real password btw?

Posted by bear, 05-31-2009, 05:00 PM
Let's hope not, but just in case, edited.

Posted by iEve, 06-02-2009, 01:32 PM
check if the $_POST variables are being sent, and if its the right variable which you are checking for

Posted by rasin, 06-03-2009, 03:07 AM
try intval() instead of int that is $id = intval($_POST['ad']);

Posted by horizon, 06-03-2009, 11:58 PM
Correct. The int function is usually used into database queries. As for the intval, it is usually seen in the REQUEST, POST or GET variables.



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read


Language: