broj1 356 Humble servant Featured Poster

Seems to be possible doing this using Javascript. And use PHP to pepare the HTML part. See http://msdn.microsoft.com/en-us/library/office/fp161148%28v=office.15%29.aspx

broj1 356 Humble servant Featured Poster

Seems to be possible doing this using Javascript. See http://msdn.microsoft.com/en-us/library/office/fp161148%28v=office.15%29.aspx. And use PHP to pepare the HTML part.

broj1 356 Humble servant Featured Poster

If you replace the following code:

list($ip, $netmask) = split("/", $ipNetmask );
$ip_elements_decimal = split("[.]", $ip );

with this one (for IPv4 addresses):

list($ip, $netmask) = explode("/", $ipNetmask );
$ip_elements_decimal = explode(".", $ip );

you should not get the depreciated notice. In fact I think you do not need regular expressions (with their overhead) for this.

broj1 356 Humble servant Featured Poster

If I got your question right you want to know whether a special character is required in PHP to write a statement on multiple lines. The code in PHP would be:

$query = "INSERT INTO table(field1," .
"field2)VALUES(value1," .
"Value2)";

or

$query  = "INSERT INTO table(field1,";
$query .= "field2)VALUES(value1,";
$query .= "Value2)";

or simply

$query = "INSERT INTO table(field1,
field2)VALUES(value1,
Value2)";

You use a dot (.) to concatenate strings or use any whitespace (line break, spaces) within a string to format the code.

diafol commented: That was my take as well +15
broj1 356 Humble servant Featured Poster

If you know the structure will be exactly like the above:

function convertDate($oldDate) {
    $months = array('Jan' => 1,'Feb' => 2,'Mar' => 3,'Apr' => 4, 'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12);
    $temp = explode('/', $oldDate);
    return $temp[2] . '-' . $months[$temp[1]] . '-' . $temp[0];
}
arafath077 commented: thanks.itz worked +0
broj1 356 Humble servant Featured Poster

The main error was in the fact that you should not send any output to the browser before the header function. In your second alternative coding example above you broke this requirement. In the first example you actualy made a redirection before outputting the script code so the script code never run I suppose.

broj1 356 Humble servant Featured Poster

Welcome to php and hopefully you will get plenty of joy in programming. If this question is answered please mark the thread as solved.

broj1 356 Humble servant Featured Poster

Your script seems to be OK. Check your configuration (php.ini -> [mail function] section) which depends on your environment. In my Windows XAMP on localhost all mail is written to the C:\xampp\mailoutput directory (not really sent out).

broj1 356 Humble servant Featured Poster

See OWASP Top Ten especially the A1 - Injection. Probably all the web developer needs to know about the security. It is a lot of stuff to read and you do not have to digest it all at once. But make sure you bookmark it.

broj1 356 Humble servant Featured Poster

Kool. Solved?

broj1 356 Humble servant Featured Poster

Is the server running IIS or XAMP? IIS has different document root path from XAMP as far as I know. XAMP is really only ment for local development.

broj1 356 Humble servant Featured Poster

What is the server OS? If it is one of the Linux distros the path for html documents would not be the same as in Windows. A couple of examples:

/var/www/html
/var/www
/srv

So you might want to reference the web path which is not suppose to change and hardcode the rest or check for the OS: for the later you could use some info from the $_SERVER superglobal variable, maybe $_SERVER['SCRIPT_FILENAME'] or $_SERVER['SERVER_SOFTWARE'] but I don't know how reliable this is. Example:

// use this in Windows
define('BASE_PATH', 'c://xampp/htdocs/');
// use this in Ubuntu
define('BASE_PATH', '/var/www/html/')

define('DESTINATION_FOLDER', BASE_PATH . 'squprime/administrator/admin/materialstorage/');
broj1 356 Humble servant Featured Poster

You have 5 rows of select element and checkboxes so you have to keep track of which row a user has selceted / checked. You can do this if you add row number to the name attributes. So for row No. 1 the attribute would be:

<select name="lang[1]">
<input name="speak[1]" type="checkbox" value="yes" />
...

The easiest way to keep the code manageable is to store languages into an array and then loop through this array and construct all the elements. here is my version of code:

// array of languages
$languages = array(1 => 'Hindi', 2 => 'English', 3 => 'Tamil', 4 => 'Telugu', 5 => 'Kannada');

// the form
// note the action has been set to # to test the output
// adapt this to your needs
echo '<form method="post" action="#">';

// table head
echo '<div align="center">
  <table width="434" border="0">
    <tr>
      <td>Languages Known</td>
      <td>Speak</td>
      <td>Read</td>
      <td>Write</td>
      <td>Delete</td>
      </tr>';

// table rows
for($i = 1; $i <= count($languages); $i++) {
    echo '<tr><td>';

    // select element
    echo '<select name="lang[' . $i . ']">';
    echo '<option value="0">- Select -</option>';
    foreach($languages as $key => $lang) {
        echo '<option value="' . $key . '">' . $lang . '</option>';
    }
    echo '</select></td>';

    // checkboxes
    echo '<td><input name="speak[' . $i . ']" type="checkbox" value="yes" /></td>';
    echo '<td><input name="read[' . $i . ']" type="checkbox" value="yes" /></td>';
    echo '<td><input name="write[' . $i . ']" type="checkbox" value="yes" /></td>';

    // delete button
    echo '<td><input type="button" name="button5" id="button5" value="Delete" onclick="delete(this)" /></td>';

    echo '</tr>';
}
echo '</table>';
// submit butoon …
broj1 356 Humble servant Featured Poster

On lines 26 and 27 you assign strings to $uname and $pword variables:

$uname = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_SPECIAL_CHARS);
$pword = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_SPECIAL_CHARS);

On lines 38 and 39 you assign values to the $_SESSION but now you treat the above strings as arrays:

$_SESSION['User'] = $uname['username'];
$_SESSION['Passw'] = $pword['password'];

To me logical code would be:

$_SESSION['User'] = $uname;
$_SESSION['Passw'] = $pword;

except if you had something else in mind?

broj1 356 Humble servant Featured Poster

What is the code in the welc.php?

Is $uname['username'] a username (usually just one word) or users real name (like first and last name)?

broj1 356 Humble servant Featured Poster

No worries, mate. If this is it, please mark it as solved.

broj1 356 Humble servant Featured Poster

aND WHY YOU jad used # on action what if we used <?php $PHP_SELF ?>

They both work since they both mean about the same thing. So it is fine if you use any of these two options.

Well need one more favor from you if you be so kinds engough and let me know where I was mistaken and how it worked

There were few issues:
- line 7: while($record6 = mysql_fetch_array($recordset6)) is not OK since you assign a row to a resultset.
- line 24 and below: you did not check if the form has been submitted, since only then you can do the reading of user data and displaying it. Before the form is submitted you basicaly display nothing about the user.
- line 44: the </form> closing tag should be somewhere on line 20
- the label tags should not enclose elements (at least I think so), but that should not stop the script to do its work anyway

Now you can style the form to look nicer :-)

broj1 356 Humble servant Featured Poster

An improvement: once you selected a value and the data gets displayed your select element is set to the last selected value.

while($row = mysql_fetch_array($recordset6)) {
    echo "<option value=", $row["uid"];
    if(isset($_POST['button']) && $row["uid"] == $_POST['select3']) {
        echo ' selected';
    }
    echo ">", $row["ulogin"], "</option>";
}
broj1 356 Humble servant Featured Poster

Yeah, I had a few errors (like int_val instead of intval function name) in the code, sorry. This should work:

<?php 
// check if form was submitted
if(isset($_POST['button'])) {
    // select user profile data
    // $uid is forced to the integer type to make sure no ugly data enters the database
    // you could also use mysql_real_escape_string() function
    // now read a record for a selected user ID and store values in variables
    $result3 = mysql_query("SELECT * FROM users WHERE uid='" . intval($_POST['select3']) . "'");
    $row3 = mysql_fetch_array($result3);
    $fname = $row3['fname'];
    $lname = $row3['lname'];
    $uaddress = $row3['uaddress'];
    $uphone = $row3["uphone"];
    $uemail = $row3["uemail"];
    $desig = $row3["udesignation"];
    $empstat = $row3["empstat"];
    $jdate = $row3["jdate"];
}
?>
<form method="post" action="#">
<label for="select3">Select User</label>
<select name="select3">
<?php
$recordset6 = mysql_query("SELECT uid, ulogin FROM users");

while($row = mysql_fetch_array($recordset6)) {
    echo "<option value=", $row["uid"], ">", $row["ulogin"], "</option>";
}
?>
</select><br>
<input type="submit" value="Show" name="button" class="button"><br>
</form>

<?php 
// here you display user data if exists
if(isset($_POST['button'])) {
    echo "$fname<br>$lname <br>$uaddress<br>$uphone <br>$uemail<br>$desig<br>$empstat<br>$jdate";
    // you can unset the post variable so you are back to initial state
    unset($_POST);
}
?>
broj1 356 Humble servant Featured Poster

You posted the database structure instead of data. But never mind I will make up the data and check the code.

broj1 356 Humble servant Featured Poster

Can you send me some data from the users table. In phpmyadmin run the following query:

SELECT * FROM users LIMIT 10

and paste result here so I can test with the real data.

The code I posted was not tested, more just to show the concept.

broj1 356 Humble servant Featured Poster

Failed to load resource: net::ERR_CACHE_MISS
this eror is coming up in the console

I doubt this has any connection with the script. See:
http://stackoverflow.com/questions/26408931/bizarre-error-in-chrome-developer-console-failed-to-load-resource-neterr-ca

broj1 356 Humble servant Featured Poster

Here you go. See the comments in the code. If anything is not clear, just ask.

<?php 
// check if form was submitted
if(isset($_POST['button'])) {
    // select user profile data
    // $uid is forced to the integer type to make sure no ugly data enters the database
    // you could also use mysql_real_escape_string() function
    // now read a record for a selected user ID and store values in variables
    $result3 = mysql_query("SELECT * FROM users WHERE uid='" . int_val($_POST['$uid']) . "'");
    $row3 = mysql_fetch_array($result3);
    $fname = $row3['fname'];
    $lname = $row3['lname'];
    $uaddress = $row3['uaddress'];
    $uphone = $row3["uphone"];
    $uemail = $row3["uemail"];
    $desig = $row3["udesignation"];
    $empstat = $row3["empstat"];
    $jdate = $row3["jdate"];
}
?>
<form method="post" action="#">
<label for="select3">Select User</label>
<select name="select3">
<?php
$recordset6 = mysql_query("SELECT uid, ulogin FROM users");
while($record6 = mysql_fetch_array($recordset6)) {
    echo"<option value=",$record6["uid"],">",$record6["ulogin"],"</option>";
}
?>
</select><br>
<input type="submit" value="Show" name="button" class="button" style="float:left;margin-left:25%;"><br>
</form>

<?php 
// here you display user data if exists
if(isset($_POST['button'])) {
    echo "$fname<br>$lname <br>$uaddress<br>$uphone <br>$uemail<br>$desig<br>$empstat<br>$jdate";
    // you can unset the post variable so you are back to initial state
    unset($_POST);
}
?>

It would be good idea to replace al mysql* functions with mysqli* functions. mysql extension is deprecated, it was replaced with mysqli. However, in future think of switching to PDO.

broj1 356 Humble servant Featured Poster

So if I understood it right, you want to select a user name and have profile of the selected user displayed on the same page. I did not quite understand though, whether you want a submit button or not (but that does not matter so much, since javascript can triger form submission instead of a submit button).

There are two approaches:

  1. The simple one - You select a user and the page reloads with the same form and with user data displayed
  2. The more advanced one - You select user and the page does not reload, only the element displaying user data gets updated using AJAX

It depends on the level of your familiarity with these things which one to chose. The second approach is used in modern web apps.

In the page you refer to as an example some other approach is used. All the values are being coded in the HTML page and Javascript selects the appropriate value of the second dropdown based on the value in the first dropdown. But with a database of users usualy this approach is not appropriate (especialy if you have a lot of users).

Nevertheless, I will try to find some time today to code an example for the first approach above. Meanwhile you can google a bit for ajax and check out jquery especialy the ajax part of it.

If you however wish to tahe the second approach, let me know and I'll prepare an example …

broj1 356 Humble servant Featured Poster

I have tried the while loop but still I am unsuccessfull

Can you specify in what way you were unsuccessful, eg. what was expected outcome and what really came out?

A few comments on your code:

  • You should enclose your form elements within <form> tags and set appropriate form attributes (method and action)
  • in the php part you should catch the submitted form data using something like if(isset($_POST['submit'])) and only then process the data
  • I presume there would be only one record in the recordset if you search by user ID, so while loop is unnecessary
  • I am not sure if is OK that form elements are enclosed within the <label> tags (but I might be wrong about that). It is still safer to use <label for="..."> way of coding it
  • I will repeat an old tune: sanitize the input form users before using it in a db query (google for sql injection)
  • think of switching from mysql extension and using something more modern (and secure) like pdo
broj1 356 Humble servant Featured Poster

Try using result->num_rows instead (it returns number of rows found):

if($result->num_rows == 0){
    echo "invalid username" ;
} else {
    echo "welcome";
}
broj1 356 Humble servant Featured Poster

Maybe line 23: while($row=$result->fetch_assco()){...

It should probably be:

while($row=$result->fetch_assoc()){...

assoc stands for associative; this method returns a row in an associative array where field names are keys.

broj1 356 Humble servant Featured Poster

It is a lot of code but as it seems the $image[photos] is an array of photos that you should iterate through, something like:

foreach($cleaned_response as $image){
    foreach($image[photos] as $oneImage) {
        echo'<img height="100" width="100" src="'.$oneImage['fullsize'].'"/>'
    }
}
broj1 356 Humble servant Featured Poster

If no event has been selected from the dropdown, you are in trouble since $_POST['events'] possibly does not exist and you get a notice (the script obviously gets executed anyway). What you have to do is to check for existence and act appropriately:

if(isset($_POST['events'])) {
    $event = $_POST['events'];
} else {
    // do something (get user to provide the data or provide a default value yourself...)
}

You might use this technique for all fields that might be empty but are mandatory. or even better do a client side check first using javascript.

broj1 356 Humble servant Featured Poster

Maybe you post a little bit more code. At least to see where is the information about the ommittee member that has taken the book in.

broj1 356 Humble servant Featured Poster

It works perfectly well in my browser (Firefox 30 on Win7). Clicking on a View page source it shows 5 tabs.

broj1 356 Humble servant Featured Poster

The option that should be selected has to have a selected="selected" attribute. To find out which one it is, you do a check in each iterration. Suppose that com_FirstName is the criteria as in your example:

// committee member that has taken the book in
$comiteMemeber = 'John';
while($row_com = mysql_fetch_assoc($res_com)) {
    $dropdown .= "\r\n<option value='{$row_com['com_FirstName']}'>{$row_com['com_FirstName']}";
    // here you do the check
    if($row_com['com_FirstName'] == $comiteMemeber) {
        $dropdown .= ' selected="selected"';
    }
    $dropdown .= ">{$row_com['com_FirstName']}</option>";
    </option>";
}
broj1 356 Humble servant Featured Poster

I tried that in begining, it execute 2 echo's for text and for = 0 so its like Points can't be text.Clean 0

What did you input to get these two echo statemens?

I tested my code and it works OK. It is important to have the exact series of if statements.

hey broj1, long time no seen, glad to see you!

:-) Thank you. Same here.

broj1 356 Humble servant Featured Poster

Why don't you do it simple way:

// first check if it is or isn't a number
if(!is_numeric($points)) {
    echo "Points can't be text";
// then try all possible values
} elseif($points == 0) {
    echo "Clean 0";
} elseif($points > 0 && $points <= 50) {
    echo "You did not pass";
} elseif($points > 50 && $points < 100) {
    echo "You passed test";
} elseif($points == 100) {
    echo "You finished with best result"; }
}

And beware: on line 20 you are using two variables for comparison: $points and $bodovi. Seems like a typo.

broj1 356 Humble servant Featured Poster

After looking closer at your code I figured out that you do not need neither javascript nor ajax. Before posting my version of code I have to warn you that deleting records using GET method is a bad practice considering the semantics and security. Make sure only authenticated users can get to this script. Here is the code (take it as a concept):

// connect to the database
include 'Connect.php';

// confirm that the 'student_id' variable has been set
if (isset($_GET['student_id']) && is_numeric($_GET['student_id']))
{
    // if user clicked on a Delete buttton, then delete the record and redirect
    if(isset($_POST['confirm-delete'])) {

        // first remove the delete element form the $_POST
        unset($_POST['confirm-delete']);

        // get the 'student_id' variable from the URL
        $student_id = intval($_GET['student_id']);

        // delete record from database
        if ($stmt = $mysql->prepare("DELETE FROM student_information WHERE student_id = ? LIMIT 1"))
        {
            $stmt->bind_param("i",$student_id);
            $stmt->execute();
            $stmt->close();
            $mysql->close();

            header("Location: Admin_Home.php");
            exit();           
        }
        else
        {
            $mysql->close();
            // if error redirect to the error page
            header("Location: Error.php");
            exit();
        }
    }

    // prompt and a form containing the confirm button
    echo "<p>Do you realy want to delete the record?</p>";
    echo '<form action="#" method="post">';
    echo '<input type="submit" name="confirm-delete" value="Delete">';
    echo '</form>';
}
else
    // if the 'student_id' variable isn't set, redirect the user
{
    header("Location: Admin_Home.php");
}

As you see I used a form with a button and a POST method, so I can first check whether a button was clicked. You should add a cancel button as well and redirect without deleting if pressed.

broj1 356 Humble servant Featured Poster

If you wish to use the above soultion by ehpratah you will have to use ajax since queries can not be performed by javascript itself. You can use a jquery Ajax method.

broj1 356 Humble servant Featured Poster

You will have to check for values of each of the fields and build the query accordingly. Something like:

$query = "SELECT Schedule.Channel_Number, StationInformation.Station_Name, Schedule.Program_Name, Schedule.Date, Schedule.Time FROM Schedule INNER JOIN StationInformation ON Schedule.Channel_Number=StationInformation.Channel_Number INNER JOIN TVShows ON Schedule.Program_Name=TVShows.Program_Name WHERE 1 ";

If(isset($_POST['date']) && !empty($_POST['date']))  {
    $date = mysql_real_escape_string($_POST['date']);
    $query .= " AND Schedule.Date='$date'";
}

    If(isset($_POST['startime']) && !empty($_POST['startime']))  {
    $startime = mysql_real_escape_string($_POST['startime']);
    $query .=  " AND Schedule.Date='$startime'";
}

etc.

As You can see I also added a bit of security escaping the input. You can enhance it even more. And start thinking of dropping the old mysql extension and maybe start using PDO.

broj1 356 Humble servant Featured Poster

Yes, I was a bit quick, sory. The thing is you want to use ajax to send a request to another php page which then sends a response which is a html code for a table containing results. You send a ServiceOrders category parameter along to use it as a filter in the query. Maybe the best would be to use the jquery post() method which sends a request along with the parameter and puts the response in the div you wanted. Mind you, the called php page does not have to have all the html stuff (like head tags etc) only the php code querying the database and echoing the html table displaying the results. Also I would use data in a JSON instead of string and I moved the script to the bottom of the html. I tested the code below and it works .

<!DOCTYPE html>
<html>

<head>   

<link rel='stylesheet' type='text/css' href='styles.css' />
<link rel="stylesheet" href="grid.css" type="text/css" />
<link rel="stylesheet" href="backgroundcss.css" type="text/css" />
<style>
form { width: 700px; }
label { float: left; width: 100px; }
input[type=text] { float: left; width: 200px; }
.clear { clear: both; height: 0; line-height: 0; }
.floatright { float: right; }

</style>
    <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
    <script type='text/javascript' src='menu_jquery.js'></script>
    <script type="text/javascript" src="jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>      
<script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });


 $(function() {
     $("#refresh").on("click", function() {
        $("#mydiv").load("http://192.241.175.69/ServiceOrderReport.php");
        return false;
    })
  })

</script>

</head>
  <body  class="container">
  <br>
<div id='cssmenu'>
<ul> …
broj1 356 Humble servant Featured Poster

Why don't you use the second parameter of the load() function for sending it over to the theServiceOrderReport.php. You basically do not need a session var for that.

First add an ID to the select element:

<select name="ServiceOrders" id="ServiceOrders">

Then read its value and send it over with the load():

$("#refresh").on("click", function() {
    // selected value
    var categoryVal = $("#ServiceOrders").val();
    $("#mydiv").load("http://192.241.175.69/ServiceOrderReport.php", categoryVal);
return false;
})

Read it from the $_POST array and use it in the query (you can also store it in session var here):

$ServiceOrders= $_POST["ServiceOrders"];
broj1 356 Humble servant Featured Poster

in simple words this code works fine

Does that mean that the code works fine now?

broj1 356 Humble servant Featured Poster

Sory for late reply, I was away. Can you post the contents of the $this->wp_selected_rar_roles and $wp_roles->roles arrays. You can use this code:

<?php
// show contents of $this->wp_selected_rar_roles
echo '<pre>$this->wp_selected_rar_roles' . print_r($this->wp_selected_rar_roles, 1) . "</pre>";

foreach($this->wp_selected_rar_roles as $role) {

    // show contents of $wp_roles->roles
    echo '<pre>$wp_roles->roles' . print_r($wp_roles->roles, 1) . "</pre>";

?>
<input type="radio" name="wp_rar_user_role" id="wp_rar_user_role" class="input select" value="<?php echo $role; ?>" /> <label>
<?php echo $wp_roles->roles[$role]['name']; ?>
</label>
<?php
}
?>
broj1 356 Humble servant Featured Poster

Ups, I wrongly interpreted your code, I am sory for that. Please disregard my post above.

Can you post the html code for both radio buttons that gets generated, please.

broj1 356 Humble servant Featured Poster

Seems like $role is an array and therefore won't display as a string. Can you post the contents of the $role - you do this by using print_r($role).

Edit: I forgot to mention I am not a WP expert.

broj1 356 Humble servant Featured Poster

Adapted from the PHP site example:

// path to the directory with files (relative to the script)
$path = '.';
// URL to the above path from the browser
$url = 'http://www.example.com/download/';
if ($handle = opendir($path)) {
    // loop through directory entries
    while (false !== ($entry = readdir($handle))) {
        // skip . and ..
        if ($entry != "." && $entry != "..") {
            // construct a link and display it
            echo "<a href=\"$url$entry\">$entry</a><br>";
        }
    }
    closedir($handle);
}
broj1 356 Humble servant Featured Poster

I tested both my suggestions in my environment and they work. But please note, you have an extra space in one of the elements of the $fields array. I also simplified the code since there is no need to have intermediate $wheres array. Also see how I changed the name attributes of the select elements. So this is the code (see also the comments in the code):

<?php
// first check if $_POST is set and not empty
if(isset($_POST) && !empty($_POST)) {

    $fields = array('eventID','eventTitle', 'te_events.venueID', 'te_events.catID', 'eventStartDate', 'eventEndDate', 'eventPrice');

    // start building the query
    $sql = "SELECT eventID, eventTitle, te_events.catID, te_events.venueID, te_category.catDesc, te_venue.venueName, te_venue.location,  eventStartDate, eventEndDate, eventPrice 
    FROM te_events INNER JOIN te_category ON te_category.catID=te_events.catID 
    INNER JOIN te_venue ON te_venue.venueID=te_events.venueID
    WHERE 1";

    // loop through the POSTed array,
    // and add WHERE clauses to the query
    foreach ($_POST as $key => $val) {

        // check if the $_POST key (form field name) exists in the $fields array
        // and has allowed value
        if(in_array($key, $fields) && ($val != '' && $val != 'Select')) {

            $sql .= " AND $key='$val'";
        }
    }

    // add sorting to the query
    $sql .=  " ORDER BY eventTitle";

    // DEBUG: display the query
    echo $sql;
}

?>
<form action="#" method="post">

<p><label class="label1">Event Title:</label><input type='text' class="input_personal" name='eventTitle' id ='eventTitle'/></p>
<p><label class="label1">Venue Name:</label></p> 
    <p><select class="select" name="te_events.venueID" id ='te_events.venueID' >
      <option>Select</option>
      <option  value='v1'>Theatre Royal</option>
      <option  value='v2'>BALTIC Centre for Contemporary Art</option>
      <option  value='v3'>Laing Art Gallery</option>
      <option  value='v4'>The Biscuit Factory</option>
      <option  value='v5'>Discovery Museum</option>
      <option  value='v6'>HMS Calliope</option>
      <option  value='v7'>Metro Radio Arena</option>
      <option …
broj1 356 Humble servant Featured Poster

My previous post were not tested, only conceptual. Tonight I will simulate/test the code in real environment and let you know how I went.

broj1 356 Humble servant Featured Poster

Yet another approach. Do not use table name in the array:

$fields=array('eventID','eventTitle','venueID','catID ',
'eventStartDate','eventEndDate','eventPrice');

Prepend table name to all $wheres:

// add to array of WHERE clauses only if value is not FALSE
if (${$field}) { $wheres[]="$field='" . 'te_events.' . ${$field}."'"; }

Again, not very flexible (and I am not sure if this is correct since I do not know all the logic).

broj1 356 Humble servant Featured Poster

Depends on the situation. So the venueID and catID are from another table. You could code it this way:

...

  // add to array of WHERE clauses only if value is not FALSE
  if (${$field}) { 
      $wheres[] $field = venueID || $field = catID ? "$field='" . 'te_events.' . ${$field}."'" : "$field='" . ${$field}."'"; 
  }
}
...

The above code checks if the fields need to be prepended with the table name. But this code is not very flexible. Other approach would be to have select names contain table names (with dots) but I am not sure if this is valid in HTML:

<select class="select" name="te_events.catID" id ='catID'>
broj1 356 Humble servant Featured Poster

Select element names are venueID and catID but the field names in the array are te_events.venueID and te_events.catID so you do not get a match here (isset($_POST[$field]) returns false).

broj1 356 Humble servant Featured Poster

Describe your tables in a way that you can create forms and generate queries. A simple way of doing it would be to have table fields stored in an associative array where keys would be field names and values would be field types. That way you can tell whether to use nput field or textarea in the form.

$table = array(
    'tablename' => 'table1',
    'filed11' => 'varchar',
    'field12' => 'smallint',
    'field13' => 'text',
)


$table2 = array(
    'filed21' => 'integer',
    'field22' => 'smalint',
)

// form for the selected table (i.e.table1)
echo "<form>";
foreach($table1 as $key => $value) {
    if($key == 'tablename') {
        echo "<input type=\"hidden\" value=\"$value\">";
    } else {
        switch($value) {
            case 'varchar':
            case 'smallint':
                echo "<input type=\"text\" name=\"$key\">"; break;
            case 'text':
                echo "<textarea name=\"$key\"></textarea>"; break;
        }
    }
}
echo '<input type="submit" name="submit" value="Insert data">';
echo "</form>";

// this is how you process the form
if(isset($_POST['submit'])) {
    unset($_POST['submit']);
    $tablename = mysqli_real_escape_string($_POST['tablename']);
    unset($_POST['tablename']);

    foreach($_POST as $fieldname => $fieldvalue) {
        $fieldNamesArray[] = mysqli_real_escape_string($fieldname);
        $fieldValuesArray[] = mysqli_real_escape_string($fieldvalue);
    }

    $query = "INSERT INTO $tablename ("`. implode('` ,`', $fieldNamesArray) "`) VALUES (" . implode("','", $fieldValuesArray) . "')";

    // then execute the query
    ...
}

This is just a concept. It can be much improved but you get the idea.