PHP - Connect To Mysql Database
Hi, I cant connect to my Mysql database. I get this problem: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'esolarch_databas'@'localhost' (using password: YES) in /home7/esolarch/public_html/new/storescripts/connect_to_mysql.php on line 21 could not connect to mysql Code: [Select] <?php /* 1: "die()" will exit the script and show an error statement if something goes wrong with the "connect" or "select" functions. 2: A "mysql_connect()" error usually means your username/password are wrong 3: A "mysql_select_db()" error usually means the database does not exist. */ // Place db host name. Sometimes "localhost" but // sometimes looks like this: >> ???mysql??.someserver.net $db_host = "localhost"; // Place the username for the MySQL database here $db_username = "esolarch_database"; // Place the password for the MySQL database here $db_pass = "Password"; // Place the name for the MySQL database here $db_name = "esolarch_admin2"; // Run the actual connection here mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql"); mysql_select_db("$db_name") or die ("no database"); ?> Similar TutorialsHello, I've been having trouble connecting to a MySQL database, I can't find the problem in the code, what am I doing wrong? Getting the database file in the config file : require_once("db_connect.php"); db_connect.php : <?php $db = mysql_connect('83.172.155.14:3306', 'username', 'password') or die(mysql_error()); mysql_select_db('databasename', $db) or die(mysql_error()); ?> I need to connect to a PhpMyAdmin database. I need this fixed asap since I'm doing this for someone and he wants the site done as quickly as possible. P.S: The database used to work in php4 and now I need it to work on php5 Thanks in advance, Hi there, I have this connect script I have made. I was wondering if it's secure or not, if not... What would be a good way to do so... Code: [Select] <?php class connect{ public $host = "localhost"; public $dbuser = ""; public $dbpass = ""; public $db = ""; } $connect = new connect(); mysql_connect($connect->host,$connect->dbuser,$connect->dbpass) or die("Could not connect!"); mysql_select_db($connect->db); ?> Hi, When i am trying to run one script on my web server, i get following error Cannot connect to the database using the info you provided Access denied for user 'My_Username'@'localhost' (using password: NO) I filled all info like Host(localhost) Database name(created in cpanel) Username(created in cpanel) Password(i kept blank dont know where to find this) You help will highly appreciate Thanks, Ravindra for some reason my database will not connect, here's the code: Code: [Select] <?php require("mstr_ref2.php"); function parseToXML($htmlStr) { $xmlStr=str_replace('<','<',$htmlStr); $xmlStr=str_replace('>','>',$xmlStr); $xmlStr=str_replace('"','"',$xmlStr); $xmlStr=str_replace("'",'&#39;',$xmlStr); $xmlStr=str_replace("&",'&',$xmlStr); return $xmlStr; } // Opens a connection to a MySQL server $connection=mysql_connect (localhost, $username, $password); if (!$connection) { die('Not connected : ' . mysql_error()); } // Set the active MySQL database $db_selected = mysql_select_db($database, $connection); if (!$db_selected) { die ('Can\'t use db : ' . mysql_error()); } // Select all the rows in the markers table $query = "SELECT * FROM markers WHERE 1"; $result = mysql_query($query); if (!$result) { die('Invalid query: ' . mysql_error()); } header("Content-type: text/xml"); // Start XML file, echo parent node echo '<markers>'; // Iterate through the rows, printing XML nodes for each while ($row = @mysql_fetch_assoc($result)){ // ADD TO XML DOCUMENT NODE echo '<marker '; echo 'name="' . parseToXML($row['name']) . '" '; echo 'address="' . parseToXML($row['address']) . '" '; echo 'lat="' . $row['lat'] . '" '; echo 'lng="' . $row['lng'] . '" '; echo 'type="' . $row['type'] . '" '; echo '/>'; } // End XML file echo '</markers>'; ?> I think there is something wrong with this line of code. Where it says 'locat host' im not too sure about that because im not connecting to a local host, so what can i put in there instead?i think that is the problem. Code: [Select] $connection=mysql_connect (localhost, $username, $password); This is the error I get: Code: [Select] Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'a2221438'@'localhost' (using password: NO) in /home/a2221438/public_html/map.php on line 44 hey I need this to connect to my database on my sybase sql server, but no matter what i try, it won't populate the plunum field. Any help would be appreciated. Here is my HTML code: Code: [Select] <html> <head> <title>helloscan</title> <meta http-equiv="refresh" content="18"> <meta http-equiv="scanner" content="javascript:doScan('%s');"/> <meta http-equiv="scanner" content="start"/> <META HTTP-Equiv="scanner" Content="enabled" /> <META HTTP-Equiv="scanner" Content="AutoEnter:Enabled"/> <meta http-equiv="keycapture" content="accelerate:all" /> <meta http-equiv="keycapture" content="keyvalue:0x0D; dispatch=true; keyevent:url('javascript:mykeypressed();')" /> <meta http-equiv="quitbutton" content="visibility: visible;"/> <script language="javascript" type="text/javascript"> function doScan(data){ var divEl = ("%s"); } function enablescanner(enable){ Generic.InvokeMetaFunction('scanner', 'start'); Generic.InvokeMetaFunction('scanner', 'enabled'); Generic.InvokeMetaFunction('scanner', 'autoenter:enabled'); } </script> <script> function get_plunum(){ xmlhttp=ajaxfunction(); if (xmlhttp==null) { alert ("no ajax support"); return; } var ae_xrefnum = document.getelementbyid('ae_xrefnum').value; var ae_plunum = document.getelementbyid('ae_plunum').value; var querystring = "?ae_xrefnum=" + xrefnum + "&ae_plunum="+ plunum"; xmlhttp.onreadystatechange = function (){ if (xmlhttp.readystate == 4 || xmlhttp.readystate=="comlete"){ document.myform.ae_plunum.value = xmlHttp.responseText; } } xmlhttp.open("GET", "helloscan2.php"+querystring, true); xmlhttp.send(null); } function ajaxfunction(){ var xmlhttp=null; try {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } catch (err) {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } return xmlhttp; } </script> </head> <body onload="enablescanner(true)"> <h3 align="center"><center><img src="ac moore" /></center>Please scan a barcode...</h3> <form name="myform"> ItemBarcode: <input type="text" id="ae_xrefnum" name="ae_xrefnum" itembarcode="divE1" oninput="get_plunum()" /> plunum: <input type="text" id="ae_plunum" name"ae_plunum" oninput="get_price()"/> </form> <script language=javascript> { document.myform.ae_xrefnum.focus(); } </script> </body> </html> And Here is my PHP code: Code: [Select] <?php //================================================================ // Configure connection parameters $db_host = "97.0.40.244, 1498"; $db_server_name = "ACMSQL036A"; $db_name = "backoff.db"; $db_file = 'd:\trvbkup\DB'; $db_conn_name = "php_script"; $db_user = "dba"; $db_pass = "sql"; //================================================================ $connect_string = "Driver={Adaptive Server Anywhere 8.0};". "CommLinks=tcpip(Host=$db_host);". "ServerName=$db_server_name;". "DatabaseName=$db_name;". "DatabaseFile=$db_file;". "ConnectionName=$db_conn_name;". "uid=$db_user;pwd=$db_pass"; // Connect to DB $conn = odbc_connect($connect_string,'',''); // Query $qry = "SELECT xrefnum, plunum FROM DBA.PLU_Cross_Ref where xrefnum = '$xrefnum'"; // Get Result $result = odbc_exec($conn,$qry); // Get Data From Result while ($row[] = odbc_fetch_array($result)); // Free Result odbc_free_result($result); // Close Connection odbc_close($conn); // Show data print_r($row[plunum]); //================================================================ ?> This is my first post so please correct me if somethings wrong Basically im creating a shopping cart with the help of a guide but there is no database written in the guide so i'm not sure how to proceed. My database wont work... Guide: https://jameshamilto...g-cart-tutorial Error message http://gyazo.com/a20...b096b7727410dfd Index: <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="description" content="PHP Shopping Cart Using Sessions" /> <meta name="keywords" content="shopping cart tutorial, shopping cart, php, sessions" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" media="all" href="/style/style.css" type="text/css" /> <title>Cart</title> <?php //connect to your database here $sql = 'SELECT * FROM books ORDER BY id'; $output[] = '<ul>'; $output[] = '<li>"'.$row['title'].'" by '.$row['author'].': £'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; //connect mysql mysql_connect($server, $user, $pass) or die ("Sorry, can't conect to mysql."); //select db mysql_select_db($db) or die ("Sorry cant select the db."); ?> </head> <body> <?php $product_id = $_GET[id]; //the product id from the URL $action = $_GET[action]; //the action from the URL //if there is an product_id and that product_id doesn't exist display an error message if($product_id && !productExists($product_id)) { die("Error. Product Doesn't Exist"); } switch($action) { //decide what to do case "add": $_SESSION['cart'][$product_id]++; //add one to the quantity of the product with id $product_id break; case "remove": $_SESSION['cart'][$product_id]--; //remove one from the quantity of the product with id $product_id if($_SESSION['cart'][$product_id] == 0) unset($_SESSION['cart'][$product_id]); //if the quantity is zero, remove it completely (using the 'unset' function) - otherwise is will show zero, then -1, -2 etc when the user keeps removing items. break; case "empty": unset($_SESSION['cart']); //unset the whole cart, i.e. empty the cart. break; } ?> <?php if($_SESSION['cart']) { //if the cart isn't empty //show the cart echo "<table border=\"1\" padding=\"3\" width=\"40%\">"; //format the cart using a HTML table //iterate through the cart, the $product_id is the key and $quantity is the value foreach($_SESSION['cart'] as $product_id => $quantity) { //get the name, description and price from the database - this will depend on your database implementation. //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection $sql = sprintf("SELECT name, description, price FROM php_shop_products WHERE id = %d;", $product_id); $result = mysql_query($sql); //Only display the row if there is a product (though there should always be as we have already checked) if(mysql_num_rows($result) > 0) { list($name, $description, $price) = mysql_fetch_row($result); $line_cost = $price * $quantity; //work out the line cost $total = $total + $line_cost; //add to the total cost echo "<tr>"; //show this information in table cells echo "<td align=\"center\">$name</td>"; //along with a 'remove' link next to the quantity - which links to this page, but with an action of remove, and the id of the current product echo "<td align=\"center\">$quantity <a href=\"$_SERVER[PHP_SELF]?action=remove&id=$product_id\">X</a></td>"; echo "<td align=\"center\">$line_cost</td>"; echo "</tr>"; } } //show the total echo "<tr>"; echo "<td colspan=\"2\" align=\"right\">Total</td>"; echo "<td align=\"right\">$total</td>"; echo "</tr>"; //show the empty cart link - which links to this page, but with an action of empty. A simple bit of javascript in the onlick event of the link asks the user for confirmation echo "<tr>"; echo "<td colspan=\"3\" align=\"right\"><a href=\"$_SERVER[PHP_SELF]?action=empty\" onclick=\"return confirm('Are you sure?');\">Empty Cart</a></td>"; echo "</tr>"; echo "</table>"; }else{ //otherwise tell the user they have no items in their cart echo "You have no items in your shopping cart."; } //function to check if a product exists function productExists($product_id) { //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection $sql = sprintf("SELECT * FROM php_shop_products WHERE id = %d;", $product_id); return mysql_num_rows(mysql_query($sql)) > 0; } ?> <a href="products.php">Continue Shopping</a> <?php /* products table: CREATE TABLE `products` ( `id` INT NOT NULL AUTO_INCREMENT , `name` VARCHAR( 255 ) NOT NULL , `description` TEXT, `price` DOUBLE DEFAULT '0.00' NOT NULL , PRIMARY KEY ( `id` ) ); */ ?> </body> </html>products.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="description" content="PHP Shopping Cart Using Sessions" /> <meta name="keywords" content="shopping cart tutorial, shopping cart, php, sessions" /> <link rel="stylesheet" media="all" href="/style/style.css" type="text/css" /> <title>Products</title> <?php //connect to your database here //connect to your database here $sql = 'SELECT * FROM books ORDER BY id'; $output[] = '<ul>'; $output[] = '<li>"'.$row['title'].'" by '.$row['author'].': £'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; //connect mysql mysql_connect($server, $user, $pass) or die ("Sorry, can't conect to mysql."); //select db mysql_select_db($db) or die ("Sorry cant select the db."); ?> </head> <body> <table border="1"> <?php $sql = "SELECT id, name, description, price FROM php_shop_products;"; $result = mysql_query($sql); while(list($id, $name, $description, $price) = mysql_fetch_row($result)) { echo "<tr>"; echo "<td>$name</td>"; echo "<td>$description</td>"; echo "<td>$price</td>"; echo "<td><a href=\"cart.php?action=add&id=$id\">Add To Cart</a></td>"; echo "</tr>"; } ?> </table> <a href="cart.php">View Cart</a> </body> </html> hi i m new to php and i m working on a project in which i m configuring a mail server using Mdeamon 9.5....... In Mdeamon 9.5 users are create by hand but i want to create user online as they sign up and their account will create as abc@mycompany.com and thier inbox created. So i want when user is sign up online and new entries will added to SQL database which trigger the Mdeamon to create a new user is it possible????? If YES then how can i do it..................... Thnx in advance for help.................. hello there.. i have a problem with my php coding where i want to keep date choose by user in the database. this is the drop down date Code: [Select] <select name="Date_Day"> <option> - Day - </option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <select name="Date_Month"> <option> - Month - </option> <option value="01">January</option> <option value="02">Febuary</option> <option value="03">March</option> <option value="04">April</option> <option value="05">May</option> <option value="06">June</option> <option value="07">July</option> <option value="08">August</option> <option value="09">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select name="Date_Year"> <option> - Year - </option> <option value="2010">2010</option> <option value="2011">2011</option> <option value="2012">2012</option> <option value="2013">2013</option> <option value="2014">2014</option> <option value="2015">2015</option> <option value="2016">2016</option> <option value="2017">2017</option> <option value="2018">2018</option> <option value="2019">2019</option> <option value="2020">2020</option> <option value="2021">2021</option> <option value="2022">2022</option> <option value="2023">2023</option> <option value="2024">2024</option> <option value="2025">2025</option> <option value="2026">2026</option> </select> the code to connect to the database Code: [Select] $date_year= ($_POST['Date_Year']); $date_month=($_POST['Date_Month']); $date_day=($_POST['Date_Day']); $date=$date_year."-".$date_month."-".$date_day; $query="INSERT INTO aduan (date) VALUES ('date($date)')"; $result=mysql_query($query); if($result){ echo 'Registration success.'; ?><script>window.location ='thanks.php'</script> <?php } else echo 'Registration failed';} when enter a value of date, the database will just show '0000-00-00'.. really hope for your help.. Hey... I was going through this sample that was given in the class, but got confused at the first point "//change this to include your own database connect script. include "../../dbconnect.php";" and the database connection code is "<?php if ($_POST['submit']) { // connect to your database $connection = pg_connect("port=5432 dbname=rr_ds user=nobody"); if (!$connection) { die("Connection has failed: " . pg_last_error()); }?> " the database connection code is from a previous assignment which i did, but that was for a login page. The current assignment is to connect to the database and have data on it. Hello I am creating a simple Discussion Forum, and I cant get past my IF Statement to verify topics exist? Please help? <?php //check for required info from the query string if (!$_GET[topic_id]) { header("Location: topiclist.php"); exit; } //connect to server and select database $link = mysql_connect('votpservicescom.ipagemysql.com', 'mantest', 'testman') or die(mysql_error()); mysql_select_db("learn2db",$link) or die(mysql_error()); Hey all, I'm sure this is a really basic question but I'd like a definite answer. I've been watching a tutorial and seeing some site references regarding connecting to a sql database using php. Since it contains a password to the database, my question is, how secure is this page on a webserver, or does it not even matter since the code is so specific to the website and the database it is connecting to.
Thank you in advance. I know the regular database connection, but this time i am provided with the SSH details. This guy game me the IP address of the database server to connect and 2 login details. SSH: Username and Password DB: Username and Password And i am using XAMPP for trying out the code. Is there any plugin i need to download for SSH connections? Could you please give me the connection snippet for SSH because i don't really know how to do that, i am also searching elsewhere on internet. Thanks in advance for help... Here is my code in admin_common.php. This is a website I had over at yahoo that I moved to Godaddy. define("EZSQL_DB_USER", "larryadmin"); // <-- mysql db user define("EZSQL_DB_PASSWORD", "mypassword"); // <-- mysql db password define("EZSQL_DB_NAME", "larryadmin"); // <-- mysql db pname define("EZSQL_DB_HOST", "mysql"); // <-- mysql server host I keep getting this error SQL/DB Error -- [ Error establishing a database connection! Are you sure you have the correct user/password? Are you sure that you have typed the correct hostname? Are you sure that the database server is running? ] SQL/DB Error -- [ Error selecting database larryadmin! Are you sure it exists? Are you sure there is a valid database connection? ] Please help thanks. Hello all, This is my first post in here, so go easy. I recently transferred my account from my local ISP to GoDaddy. And now my search criteria is not working. I am getting the follow error message on the page of my search box, instead of the graphics itself: Could not connect to MySQL:Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) I thought maybe this would be a simple error when I found out that GoDaddy does not use the "localhost" connect string. So I switched it to the local IP for GoDaddy still to no avail. I am lost after that. My PHP skills are limited. I was taught by a very advanced user who uses shortcuts and different strings self made for his ease. So looking online for solutions for the script was very hard(to me at least), because the lines of code do not match common scripts online. Is this a simple solution? Does the: global $dbc; @dbConnect(); function work with GoDaddy? Because I have seen maybe different ways to connect to a DB with PHP. Here's the script I am using to connect and extract results from the DB. Any and all help will be greatly appreciated. Thanks in advance. Using MySQL Version 4: <? @require("searchheader.php"); ?> <table cellpadding=10 cellspacing=0 border=0> <tr> <td align=left valign=top> <? displayMenu(); ?> </td> <td align=right valign=bottom> <? if($_GET["f_catid"]){ $num_cats = 5; for($i=1;$i<=$num_cats;$i++){ $where .= " or c".$i." = ".$_GET["f_catid"]; } $where = substr($where,4,strlen($where)); $sql = "select * from product where ".$where." order by product_name ASC LIMIT 0,20"; dbConnect(); $result = mysql_query($sql,$dbc); ?> <div class="search_results_menu"> <form action="[url=http://www.nexpart.com/extpart.php?part=]http://www.nexpart.com/extpart.php?part=[/url]<?=$r["part_number"]?>&linecode=<?=$row[" manufacturer"] ?>" method="GET"><input type="text" name="quantity" size="2" value="0" style="text-align: center;"><input type="button" name="submit_top" value="Check Out"> </form> <table class="search_results_found" bgcolor="#efefef" cellpadding=3 cellspacing=0 border=1 bordercolor="#000000" style="border:1px solid #000000;"> <tr bgcolor="#efefef"> <td class="search_results_title"><b>Manufacturer</b></td> <td class="search_results_title"><b>Part Number</b></td> <td class="search_results_title"><b>Part Name</b></td> <td class="search_results_title"><b>Price</b></td> <td class="search_results_title"><b>Image</b></td> <td class="search_results_title"><b>Add to Cart</b></td> </tr> <? if(mysql_num_rows($result) > 0){ while($row = mysql_fetch_assoc($result)){ ?> <tr bgcolor="#efefef"> <td><?=$row["manufacturer"]?></td> <td><a href="[url=http://www.nexpart.com/extpart.php?part=]http://www.nexpart.com/extpart.php?part=[/url]<?=$row["part_number"]?>&linecode=<?=$row["manufacturer"]?>"><?=$row["part_number"]?></a></td> <td><?=$row["product_name"]?></td> <td>$<?=$row["price"]?></td> <td><a href="[url=http://www.wlpsr.com/images/]http://www.wlpsr.com/images/[/url]"<?=$row["part_number"]?>".jpg " onClick="window.open('/images/<?=$row["part_number"]?>.jpg', '<?=$row["part_number"]?>', 'toolbar=yes, directories=no, location=no, status=yes, menubar=no, resizable=yes, scrollbars=yes, height=300, width=400'); return false">View</a></td> <td><form action="[url=http://www.nexpart.com/extpart.php?part=]http://www.nexpart.com/extpart.php?part=[/url]<?=$r["part_number"]?>&linecode=<?=$row["manufacturer"] ?>" method="GET"><input type="text" name="quantity" size="2" value="0" style="text-align:center;"> </form> </td> </tr> <? } } else{ ?> <tr> <td colspan=100 align="center"><b>No products in this category.</b></td> </tr> </table> <form action="[url=http://www.nexpart.com/extpart.php?part=]http://www.nexpart.com/extpart.php?part=[/url]<?=$r["part_number"]?>&linecode=<?=$row[" manufacturer"] ?>" method="GET"><input type="text" name="quantity" size="2" value="0" style="text-align: center;"><input type="button" name="submit_top" value="Check Out"> </form> </td> </tr> <? } ?> </td> </tr> </table> </div> <? } ?> <div class="form"> <form name="search" action="<? echo $_SERVER['PHP_SELF']; ?>" method="GET"> <input type="text" name="f_keywords" size="17" value="" maxlength="100"> <input type="image" src="gobutton.gif"> </form> </select> <br><br><br> <? $trimmed = trim(strip_tags($_GET["f_keywords"])); //Set the database access information as constants. if(strlen($trimmed) > 0){ define ('DB_USER', 'USERNAME'); define ('DB_PASSWORD', 'THEPASSWORD'); define ('DB_HOST', 'LOCALIP'); define ('DB_NAME', 'DBNAME'); define ('DB_TABLE', 'TABLE'); //Make the connection to the DB global $dbc; @dbConnect(); $query = "SELECT * FROM product WHERE manufacturer LIKE '%$trimmed%' OR part_number LIKE '%$trimmed%' OR price LIKE '%$trimmed%' OR product_name LIKE '%$trimmed%' order by manufacturer"; $result = mysql_query($query); $count = mysql_numrows($result); if ($trimmed == "") { echo "Please enter a search criteria..."; exit; } // check for a search parameter if (!isset($result)) { echo "<p>Please enter a search parameter!</p>"; exit; } $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>We are sorry <b>$trimmed</b> has returned zero results.</p></font>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $result = mysql_query($query,$dbc); if($numrows < 1){ $return= "results";} else{ $return = "result"; } if($numrows > 1){ $return = "results";} else{ $return = "result"; } // display what the person searched for echo "Your search for ", " <b>$trimmed</b> ", " found <br><b>$numrows $return.</b>"; // begin to show results set $count = 1 + $s ; } if(strlen($trimmed) > 0){ ?> </div> <div class="search_results"> <table cellpadding=0 cellspacing=0 border=0> <tr> <td align="right"> <form action="[url=http://www.nexpart.com/extpart.php?part=]http://www.nexpart.com/extpart.php?part=[/url]<?=$r["part_number"]?>&linecode=<?=$row[" manufacturer"] ?>" method="GET"><input type="text" name="quantity" size="2" value="0" style="text-align: center;"><input type="button" name="submit_top" value="Check Out"> </td> </tr> <tr> <td> <table class="search_results_found" bgcolor="#efefef" cellpadding=3 cellspacing=0 border=1 bordercolor="#000000" style="border:1px solid #000000;"> <tr> <td width="100" class="search_results_title" align="center"> Manufacturer </td><td width="70" class="search_results_title" align="center"> Part Num. </td><td width="115" class=" search_results_title" align="center"> Description </td><td width="60" class="search_results_title" align="center">Price</td><td width="45" class=" search_results_title" align="center"> Image </td><td width="105" align="center"><b>Add to Cart</b> </td> </tr> </td> </tr> <? while ($r= mysql_fetch_array($result)) { $manufacturer = $r["manufacturer"]; $part_number = $r["part_number"]; $product_name = $r["product_name"]; $price = $r["price"]; $count++; echo "<tr><td>$manufacturer</td><td>"; echo "<a href=\"[url=http://www.nexpart.com/extpart.php?part=]http://www.nexpart.com/extpart.php?part=[/url]".$r["part_number"]."&linecode=".$r["manufacturer"]."\">".$r["part_number"]."</a></td><td>"; echo "$product_name</td><td>"; echo "$ $price</td><td>"; echo "<a href=\"[url=http://www.wlpsr.com/images/]http://www.wlpsr.com/images/[/url]".$r["part_number"].".jpg \" onClick=\"window.open('/images/".$r["part_number"].".jpg', '".$r["part_number"]."', 'toolbar=yes, directories=no, location=no, status=yes, menubar=no, resizable=yes, scrollbars=yes, height=300, width=400'); return false \">View</a></td><td>"; echo "<form action=\"[url=http://www.nexpart.com/extpart.php?part=]http://www.nexpart.com/extpart.php?part=[/url]".$r["part_number"]."&linecode=".$r["manufacturer"]."\" method=\"GET\"><input type=\"text\" name=\"quantity\" size=\"2\" value=\"0\" style=\"text-align:center;\"></td></tr>"; } ?> </table> <tr> <td align="right"> <form action="[url=http://www.nexpart.com/extpart.php?part=]http://www.nexpart.com/extpart.php?part=[/url]<?=$r["part_number"]?>&linecode=<?=$row[" manufacturer"] ?>" method="GET"><input type="text" name="quantity" size="2" value="0" style="text-align: center;"><input type="button" name="submit_bottom" value="Check Out"> </td> </tr> <? } ?> </table> <br><br> </div> <? @require("footer3.php"); ?> Mod edit: [code] . . . [/code] tags added. Hello there, I'm using a Mac (10.5. and installed MAMP for PHP and MYSQL I trying to build a blog. I just setup a database in phpmyadmin. I created a php and start coding, everything works just fine, but when I tried to connect to the mysql it gives me a blank page I inserted this code Code: [Select] <?php session_start(); $connect = mysql_connect('localhost','root', 'root'); or die(mysql_error()); $db = mysql_select_db('blog',$connect); $session_name = $_SESSION['uid']; ?> but then the whole page turns to be blank page , but when I excluded this, it works just fine. I don't get it cause my database/phpmyadmin connected just fine. Any help is much appreciated. Been trying to figure this out for hours. hello, if i have an entry in a table called company on database cc, would the following be the propper code? im getting a blank page. Code: [Select] <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'mike'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'cc'; mysql_select_db($dbname); $query = "SELECT * FROM company"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "Name :{$row['compant']} <br>" . "Subject : {$row['address']} <br>" . } ?> Okay guys I have finished my db and I want to upload it to a live server but don't know exactly what to change in the code to get the ODBC_connect to open the path at the new server location please help. my database is located in a subfolder called Databases i.e. "www.mydomain.com/Databases/myEvents.mdb" what do i change in the connection string below to get it to open the file on the live server? Thanks in advance. $conn = odbc_connect('myEvents','',''); This topic has been moved to Microsoft SQL - MSSQL. http://www.phpfreaks.com/forums/index.php?topic=319147.0 I have created a function to connect to a required database with a username and password. I have called this db_openConnection() Now for each function that requires a select from a database is it ok just to call the db_OpenConnection() first within the function or should i be keeping open a db connection (using persist, i think) rather than keep creating a connection. I know that the connection ends when you have finished a query any how. Not sure if this is the correct forum or if it should be mysql forum Hi, I knew the way to connect to mysql but i don't know how to connect mssql. Is it the same? here's an example for mysql. please teach me the mssql. $con = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME); $sql = "SELECT COUNT(*) FROM numbers"; $result = $con->query($sql); $r = $result->fetch_row(); thanks |