I'm in the process of converting all of my code to mysqli instead of mysql. The pages seem to be doing their queries and inserts correctly. However, I cannot get functions to work. Based on the several sites, as well as this one, that I've looked at, my syntax should be correct. In addition, all of these worked prior to converting to mysqli.
I've tried having this directly in the php file (such as index.php) as well as in a separate file (which is where I want it to be). I get the same result. This example is a function for a dropdown list.
newserviceint.php:
<?php
include 'php/phpfunctions.php';
$con = mysqli_connect("mysql01", "jeremy","supersecret", "mycars");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
?>
<?php
$id = $_GET["id"];
$sql = " SELECT vehicles.VehicleID,
vehicles.VYear,
vmake.VMake,
vmodel.VModel
FROM vehicles
INNER JOIN mycars.vmake ON vehicles.VMakeID = vmake.VMakeID
INNER JOIN mycars.vmodel ON vehicles.VModelID = vmodel.VModelID
WHERE vehicles.VehicleID = '$id' ";
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_assoc($result)){
$year = $row['VYear'];
$make = $row['VMake'];
$model = $row['VModel'];
$vid = $row['VehicleID'];
}
?>
<body>
<div class="container">
<?php include ("layout/header.php"); ?>
<?php include ("layout/banner.php"); ?>
<div class="maininfo">
<h1>
New Service Interval
</h1>
<div class="profiletable">
<div class="previous">
<form action="php/newserviceintcode.php" method="post">
<table style="width:575px">
<tr>
<th style="width:175px">Vehicle</th>
<td style="width:375px"><input type="text" name="vehicle" style="width:40px" value="<?php echo $vid; ?>"> <?php echo $year; ?> <?php echo $make; ?> <?php echo $model; ?></td>
<td style="width:25px"></td>
</tr>
<tr>
<th>Service</th>
<td><select name="service" style="width:344px"><?php service() ?></select></td>
<td><a href="newservice.php"><img src="images/addnew.png" width="33px" height="25px"></a></td>
</tr>
<tr>
<th style="width:175px">Mileage Interval</th>
<td style="width:375px"><input type="text" name="miles" style="width:340px"></td>
<td></td>
</tr>
<tr>
<th style="width:175px">Time Interval</th>
<td style="width:375px"><input type="text" name="time" style="width:340px"></td>
<td></td>
</tr>
<tr>
<th style="height: 75px">Notes</th>
<td><textarea type="text" name="notes" style="width:340px" rows="4"></textarea></td>
<td></td>
</tr>
</table>
<br>
<input type="submit" value="Submit">
</form>
</div>
</div>
<br>
</div>
<?php include ("layout/footer.php"); ?>
</div>
<!-- end .container -->
</div>
</body>
</html>
About halfway down you see this line:
<td><select name="service" style="width:344px"><?php service() ?></select></td>
What worked in mysql was this would provide me a dropdown list that is provided by the function listed in:
php/phpfunctions.php
function service(){
$qservice = mysqli_query( "SELECT VServiceID, Title FROM vservice ORDER BY Title");
while($record = mysqli_fetch_array($qservice)){
echo '<option value="' . $record['VServiceID'] . '">' . $record['Title'] . '</option>';
}
}
There are several other functions on this page, but all of them are giving me the exact same results. I've even pretty much copied the connection function from this site but it just acts like there's nothing there. As stated above, I've tried this both locally within the pages and through the external file - both with identical results.
Is there something different you have to do with mysqli vs mysql when incorporated into a function? Based on what I've found searching, and the fact that it worked before, this should work.
Thanks in advance