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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.