-3

I inherited a WordPress website a while back that had some custom code added via the insert_php plugin. It had been running fine and apparently was an important part of their website I didn't realize. I'm not a programmer, just the jack of all trades IT person. Anyway, I noticed the most basic MySQL commands can be fixed with "i" and that the mysqli_connect command will now accept a 4th parameter of the dbname. I'm not sure where to truncate the code It's very small and uses a WordPress shortcode (Which I will create a (real snippet). I also read the query and fetch_array are way off. Any advice? Heres what I have:

$con = mysql_connect("127.0.0.1","123xxxxxxx","4444444444444");
if (!$con) {
die("Can not connect:" . mysql_error());
}

mysql_select_db("dbxxxxx",$con);
$sql = 'SELECT * FROM EmployeeTable where PrimaryCampusPerson="Yes" order by SchoolDistrict, Site';

$myData = mysql_query($sql,$con);

echo "

";
while($record = mysql_fetch_array($myData)){
echo "

";
echo "";
echo "

";
echo "

";
echo "

";
}
echo "

Campus  District    Program Manager
" . "" . $record['Site'] . "" . "
" . $record['WorkAddress'] . "
" . $record['WorkCity'] . $record['WorkState'] . $record['WorkZip'] ."
" . $record['SchoolMainPhone'] ."   " . $record['SchoolDistrict'] . "   " . "" . $record['LastName'] . ", " . $record['FirstName'] . "" . "
" . $record['WorkCISPhone'] ."
" . "". $record['Email'] . "" ."
";

[/insert_php]````
Jaydeep Galani
  • 4,842
  • 3
  • 27
  • 47

2 Answers2

0
 $con = mysqli_connect("127.0.0.1", "123xxxxxxx", "4444444444444", "dbxxxxx");
    // if there's an error connecting to db
 if (mysqli_connect_errno()) {
    echo "Failed to connect: " . mysqli_connect_errno();
 }

 $sql = "SELECT * FROM EmployeeTable
         WHERE PrimaryCampusPerson = "Yes"
         ORDER BY SchoolDistrict, Site";
 $myData = mysqli_query($con, $sql);

 while ($record = mysqli_fetch_array($myData)) {
    // echo db output
 }
Darcy
  • 575
  • 2
  • 8
  • 21
  • thank you. Ive added this to my snippet but it isnt producing results. I will keep looking for the hangup – Rick R0ss Apr 02 '19 at 22:46
0
$con = mysql_connect("127.0.0.1","123xxxxxxx","4444444444444");
mysql_select_db("dbxxxxx",$con);

Above two lines can be combined as

$con=mysqli_connect("127.0.0.1","123xxxxxxx","4444444444444","dbxxxxx")

For mysql query mysql_query($sql,$con);

mysqli _query takes conncetion as first parameter

mysqli_query($con,$sql);

And for mysql_fetch_array($myData) you can use

mysqli_fetch_array($myData)

SachinPatil4991
  • 774
  • 6
  • 13