Jump to content

[SOLVED] Syntax Problem


will35010

Recommended Posts

I want to use echo instead of return in my function. I keep getting error about the syntax being wrong. It's saying the echo line is wrong.

function getDrivers1()
{
   $sql = "SELECT fname, lname, dl FROM drivers";

$rs = mysql_query($conn, $sql);

while($row = mysql_fetch_array($rs))
{
  echo "<option value=\"$row['dl']\">".$row['lname'].",".$row['fname']."</option>";
}

Link to comment
https://forums.phpfreaks.com/topic/160677-solved-syntax-problem/
Share on other sites

I keep getting error connecting to mysql. I know my $conn works, because my other scripts use it and it works. Here are the files:

 

functions.php

<?php

//db connection info
require('opendb.php');
require('config.php');

function getDrivers1()
{
   $sql = "SELECT fname, lname, dl FROM drivers";

$rs = mysql_query($sql, $conn);

while($row = mysql_fetch_array($rs))
{
  echo "<option value=\"" . $row['dl'] . "\">".$row['lname'].",".$row['fname']."</option>";
}
}

 

config.php:

<?php
//Database Settings
$dbhost = "localhost"; 
$dbuser = "root"; 
$dbpass = "test"; 
$dbname = "vehicles"; 
$prefix = ""; 
$user_prefix = ""; 
$dbtype = "MySQL"
?>

 

opendb.php

<?php
// This is opendb.php
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or die        
                     ('Error connecting to mysql');
?>

 

I'm using <?php echo getDrivers1() ?> within the html to call the function. I also have a require function.php.

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.