Jump to content

PHP & MySQL HELP!


bethaliz

Recommended Posts

Hi,

 

I've relatively new to the world of programming. I just started taking a course last year. I've learned a lot, unfortunately neither PHP or MySQL were taught to us. Now, we're in our 4th term and starting on project work. Our client wants a PHP & MySQL inventory management system, so we're learning on the fly.

 

MySQL, so far, hasn't turned out to be that difficult. It's mainly the same as SQL server, a few slight differences, but nothing worth talking about. We have our database, up and running, tested, all's well.

 

However, We're now starting to construct our PHP pages. My goal for the weekend, was simply to establish a connection to the database and run a query that returns a single value and output that value in a text box. Not exactly rocket science, but lets start easy.

 

Anyway. This is my code so far

 

<?php

 

$db_host = "localhost";

$db_user = "root";

$db_pass = "b123dw9WHT3";

$db_name = "company";

 

$db_cxnError = 'The connection to the database has failed: Please contact your System Administrator';

 

$cxn = mysql_connect($db_host, $db_user, $db_pass, $db_name)

or die($db_cxnError);

 

$query = "SELECT coName FROM contact WHERE coID=1";

$result_contact = mysql_connect($cxn, $query)

or die($db_cxnError);

 

?>

 

 

 

I have more in the HTML section, basically a textbox with the results of my query being echo'ed out as the value of the textbox.

 

When I try to run the page this is what I get

 

Warning: mysql_connect() expects parameter 1 to be string, resource given in C:\xampp\htdocs\signal\database_test.php on line 14

The connection to the database has failed: Please contact your System Administrator

 

parameter 1 is a string! So I'm not sure why it wont connect.

Any help you can provide would be great.

 

Also, I wasn't sure if this belongs here or in the SQL section, so feel free to move it if need be.

 

Thanks!

 

Link to comment
Share on other sites

<?php

$con = mysql_connect("localhost","root","b123dw9WHT3");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  
mysql_select_db("company", $con);

$result = mysql_query("SELECT coName FROM contact WHERE coID='1' ");

while($row = mysql_fetch_array($result))
  {
  $info=$row['coName'];
  
  echo "<input tpe="text" value="$info" />
  }
  
mysql_close($con);
?>

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.