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
https://forums.phpfreaks.com/topic/213779-mysql-connect/
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
https://forums.phpfreaks.com/topic/213779-mysql-connect/#findComment-1112680
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
https://forums.phpfreaks.com/topic/213779-mysql-connect/#findComment-1112682
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
https://forums.phpfreaks.com/topic/213779-mysql-connect/#findComment-1112694
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.