Jump to content

mysql connect


flemingmike

Recommended Posts

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.

 

<?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>" . 

} 


?> 


Link to comment
Share on other sites

Your echo " ... ... "; statement is missing the closing semi-colon ; and would be producing a fatal parse error.

 

You should be developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that all the errors php detects will be reported and displayed. You will save a ton of time.

Link to comment
Share on other sites

thanks.  stupid mistake.  so now if i want to have a form with a drop down box displaying all of the company names, i tried this, but no go.

 

<?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);



$result = mysql_query("SELECT * FROM company");
while($row = mysql_fetch_array($result))
  {
  echo $row['company'] . " " . $row['address'];
  echo "<br />";
  }


?> 

<form method="POST" action="--WEBBOT-SELF--">
<p><select size="1" name="company">
<option>.'$row['company']'.</option>
</select></p>
<p><input type="submit" value="Submit" name="B1"></p>
</form>





Link to comment
Share on other sites

You need to be echoing the <option></option> tags from within your while loop. Give this a shot.

 

<?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);
if( $result = mysql_query("SELECT * FROM company") ) {
echo '<form method="POST" action="--WEBBOT-SELF--">
<p>
<select size="1" name="company">';
while($row = mysql_fetch_array($result)) {
	echo "<option value=\"{$row['company']}\">{$row['address']}</option>";
	echo "<br />";
}
}
?>
</select></p>
<p><input type="submit" value="Submit" name="B1"></p>
</form>

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.