flemingmike Posted September 19, 2010 Share Posted September 19, 2010 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>" . } ?> Quote Link to comment https://forums.phpfreaks.com/topic/213779-mysql-connect/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 19, 2010 Share Posted September 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/213779-mysql-connect/#findComment-1112680 Share on other sites More sharing options...
flemingmike Posted September 19, 2010 Author Share Posted September 19, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/213779-mysql-connect/#findComment-1112682 Share on other sites More sharing options...
Pikachu2000 Posted September 19, 2010 Share Posted September 19, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/213779-mysql-connect/#findComment-1112694 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.