prakash911 Posted March 14, 2010 Share Posted March 14, 2010 i am using a external php file called db_connect php. which has this: <?php function db_connect($db_name) { $host_name = "localhost:49648"; $user_name = "root"; $password = "chennupati"; $db_link = mysql_connect($host_name, $user_name, $password) or die("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>"); mysql_select_db("bookstore") or die("Could not select database $db_name"); return $db_link; } ?> and for my querys in my php code i am writing it like this: <?php require('db_connect.php'); ?> query to write to mysql table. <?php $query = mysql_query("insert into sign_up(userid,password,email,firstname,lastname,sex) values('$userid','$password','$email','$firstname','$lastname','$sex')"); $query2 = mysql_query("insert into members(username,password,email) values('$userid','$password','$email')"); ?> query to retrive data from mysql table <?php if(mysql_num_rows(mysql_query("SELECT userid FROM sign_up WHERE userid = '$userid'"))) { echo "<br/>\nThis User ID already exists. Please try another one<br/>\n"; $errors++; } ?> my problem is when i preview my code, my database seems to connect fine. but my query's arent writing anything or retrieving anything from the database. please help. Link to comment https://forums.phpfreaks.com/topic/195219-using-php-to-connect-to-mysql-server/ Share on other sites More sharing options...
GalaxyTramp Posted March 14, 2010 Share Posted March 14, 2010 Where does the variable ($db_name) get a value from? Link to comment https://forums.phpfreaks.com/topic/195219-using-php-to-connect-to-mysql-server/#findComment-1026018 Share on other sites More sharing options...
prakash911 Posted March 14, 2010 Author Share Posted March 14, 2010 would the function work properly if i just make it function db_connect(){ since the database that i want to connect to is only the bookstore database which has all the tables i need. Link to comment https://forums.phpfreaks.com/topic/195219-using-php-to-connect-to-mysql-server/#findComment-1026021 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.