Jump to content

using php to connect to mysql server


prakash911

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.