Updating MySQL table with PHP and checkboxes in WordPress - php

On my website enter link description here I'm using checkbox buttons for updating data in a MySql table (pages are with login) and use this code in PHP that's working fine:
<?php
$sql="SELECT *,cast(DATE_FORMAT(datum,'%d-%m-%Y ') AS CHAR(32)) as datum FROM wedstrijden";
$result=mysqli_query($db,$sql);
$count=mysqli_num_rows($result);
?>
<table style="width: 100%;">
<tr>
<td><form name="frmactive" action="1fanionchange.php" method="post">
<tr>
<td colspan="6"><input name="activate" type="submit" id="activate" value="Open selected" />
</tr>
<tr>
<td> </td>
</tr><tr>
<td align="center"><!--<input type="checkbox" name="allbox" title="Select or Deselct ALL" style="background-color:#ccc;"/> --></td>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Datum</strong></td>
<td align="center"><strong>Uur</strong></td>
<td align="center"><strong>Thuis</strong></td>
<td align="center"><strong>Uit</strong></td>
</tr>
<?php
while($rows=mysqli_fetch_array($result)){
?>
<tr>
<td align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
<td align="center"><? echo $rows['id']; ?></td>
<td align="center"><? echo $rows['datum']; ?></td>
<td align="center"><? echo $rows['uur']; ?></td>
<td align="center"><? echo zoeknaam($rows['thuisploeg']); ?></td>
<td align="center"><? echo zoeknaam($rows['uitploeg']); ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="6"><input name="activate" type="submit" id="activate" value="Open selected" />
</tr>
</form>
</td>
</tr>
</table>
But when I use the same code in WordPress (I'm trying to make the website in WordPress), it is not working and no records are displayed. When I try to find the number of rows using:
echo $count. "<br />";
I get the correct number of records in that table. But the records are not showed?
Any idea how to handle the problem? Thanks.
PS. I use the plugin phpexec in WordPress!

In WordPress it is suggested to use the WordPress builtin Queries. So that it can have maximum compatibility with the server too it is hosted.
Reference: https://codex.wordpress.org/Class_Reference/wpdb
global $wpdb;
And all the following functions will attach the database that is defined as global..
$wpdb->insert('wp_submitted_form', array(
'name' => 'Kumkum',
'email' => 'kumkum#gmail.com',
'phone' => '3456734567', // ... and so on
));
Like wise you can use it for Update / Select as per your wish and it is considered as the best one according to WordPress..

Related

How to display devnagri font from INPUT to a php page

I have one php page in which I have changed font for input to devnagri. I need to display it in next php page and also need to insert those to mysql.
first page index.php contains this details......
<table width="535" height="54" border="1">
<tbody>
<tr>
<td height="23">नाम</td>
<td><input type="text" name="name" id="name" style="font-family: Preeti">
</td>
</tr>
<tr>
<td height="23">काम</td>
<td><input type="text" name="job" id="job" style="font-family: Preeti">
</td>
</tr>
</tbody>
</table>
my second page post.php contains
<table width="535" height="54" border="1">
<tbody>
<tr>
<td height="23">नाम</td>
<td><?php
echo $_POST['name'];
?></td>
</tr>
<tr>
<td height="23">काम</td>
<td><?php
echo $_POST['job'];
?></td>
</tr>
</tbody>
</table>
when I type कला in name and खेप in job input
it displays relative english letters on the 2nd page .....
where as I need to display as it displays in input.
I also need to insert those input to mysql and again need to display those mysql data to another page....
I am not getting the way to display and stuck at this point so insert and select query is yet to be done....
Need help to figure it out.
Thanx a lot Phil.
<table width="535" height="54" border="1">
<tbody>
<tr>
<td height="23">नाम</td>
<td style="font-family: Preeti"><?php
echo $_POST['name'];
?></td>
</tr>
<tr>
<td height="23">काम</td>
<td style="font-family: Preeti"><?php
echo $_POST['job'];
?></td>
</tr>
</tbody>
</table>
It has displayed preeti font...
Still INSERT and SELECT query is remaining.

Displaying table from MySQL and link to delete each row from database

I've stucked a bit when it comes to a small piece of my PHP code. The role of this script is to display whole table from mysql plus adding to each row a hyperlink to delete such row.
<?php
$connection=mysql_connect('localhost','root','') or die(mysql_error());
error
mysql_select_db('localhost_db',$connection) or die(mysql_error());
$query=mysql_query("SELECT * FROM cms_contest") or die(mysql_error());
if(mysql_num_rows($query)>0):
?>
<table width="100%" border="0">
<tr style="font-weight:bold;">
<td align="center">Id</td>
<td align="center">First Name</td>
<td align="center">Last Name</td>
<td align="center">Email</td>
<td align="center">Phone</td>
<td align="center">Answer</td>
<td align="center">Remove</td>
</tr>
<?php
while($row=mysql_fetch_object($query)):?>
<tr>
<td align="center"><?php echo $row->ID; //row id ?></td>
<td align="center"><?php echo $row->name; // row first name ?></td>
<td align="center"><?php echo $row->surname; //row las tname ?></td>
<td align="center"><?php echo $row->email; //row created time ?></td>
<td align="center"><?php echo $row->phone_number; //row created time ?></td>
<td align="center"><?php echo $row->contest_answer; //row created time ?></td>
<td align="center">REMOVE</td>
</tr>
<?php endwhile;?>
</table>
<?php
else: ?>
<h3>No Results found.</h3>
<?php endif; ?>
It would be perfect if there appear a short javascript popup with question like: are you sure you want to remove this entry? OK / Cancel.
I have no clue how to do it.. thanks for any tips!
Simple/stupid method:
<td>nuke me</td>
But if a web spider or a browser link pre-fetch tool gets loose on this page, you'll be nuking ALL of your records.
Somewhat better:
<td>
<form method="post" action="deleteme.php">
<input type="hidden" name="id" value="<?php echo $row->ID ?>" />
<input type="submit" value="Nuke me" />
</form></td>
And then there's various options involving radio buttons/checkboxes, or JS to trap the click-on-the-link etc...
But, in the end, they ALL boil down to "you have to sent the ID of the row back to the server". How you go about that is up to you... just don't use the plain "click here" version.
Indeed there are several different ways to do this. One way I like is to wrap the entire table in a form that submits to the delete script, and use a button for each row with the row ID as its value.
<form method="post" action="delete.php">
<table width="100%" border="0">
<tr style="font-weight:bold;">
<td align="center">Id</td>
<td align="center">First Name</td>
<td align="center">Last Name</td>
<td align="center">Email</td>
<td align="center">Phone</td>
<td align="center">Answer</td>
<td align="center">Remove</td>
</tr>
<?php while($row=mysql_fetch_object($query)): ?>
<tr>
<td align="center"><?php echo $row->ID; //row id ?></td>
<td align="center"><?php echo $row->name; // row first name ?></td>
<td align="center"><?php echo $row->surname; //row las tname ?></td>
<td align="center"><?php echo $row->email; //row created time ?></td>
<td align="center"><?php echo $row->phone_number; //row created time ?></td>
<td align="center"><?php echo $row->contest_answer; //row created time ?></td>
<td align="center">
<button name="delete-id" type="submit" value="<?php echo $row->ID; ?>">
REMOVE
</button>
</td>
</tr>
<?php endwhile;?>
</table>
</form>
There are also many different ways to confirm the deletion. The simplest I know of on the client side is to add onclick="return confirm('Are you sure?');" to the delete button.
click event:
DELETE
<script type="text(javascript">
function confirmDelete(id){
if(confirm('sure u want to delete entry with id: ' + id + '?')){
window.location.href = "ursite.php?id="+id+"&delete=true";
}
}
</script>
PHP
if(isset($_GET['delete'])){
$stmt = "DELETE FROM cms_contest WHERE ID = ".$_GET['id'];
mysql_query($stmt);
}
it's the worst way to do it.
I recommend you to look at:
jQuery $.post()jQuery $.ajax()
I hope it will help you.

display search result using ajax in a div

hello i have built a multi search form using php, basically this search form queries from a particular date to another, which i have gotten to work perfectly,
using this codes
search.html
<form class="form-horizontal" action="report_advanced.php" method="post" name="form1" id="form1">
<div class="control-group">
<label class="control-label" for="inputagent name"><span class="asasa">*</span> Advanced Search:</label>
<div class="controls">
<input type="text" name="from" value="" size="32" id="inputDate" placeholder="From" /><br /><br />
<input type="text" name="to" value="" size="32" id="inputDatess" placeholder="To" />
</div>
</div>
<p align="center">
<input type="submit" class="btn btn-mini btn-primary" value="Search" /></p>
</form>
and
report_advanced.php
mysql_select_db($database_kbl, $kbl);
$query_cert = sprintf("SELECT * FROM `transactions` WHERE `Start_Date` BETWEEN %s AND %s ",
GetSQLValueString($colname_cert, "text"),GetSQLValueString($colname2_cert, "text"));
$query_limit_cert = sprintf("%s LIMIT %d, %d", $query_cert, $startRow_cert, $maxRows_cert);
$cert = mysql_query($query_limit_cert, $kbl) or die(mysql_error());
$row_cert = mysql_fetch_assoc($cert);
<table width="60%" class="table table-bordered" id="table"></span>
<tr class="success">
<td style="color:#FFF" width="10%">Insured Name</td>
<td style="color:#FFF" width="10%">Telephone No</td>
<td style="color:#FFF" width="10%">Policy Number</td>
<td style="color:#FFF" width="10%">Car Make</td>
<td style="color:#FFF" width="10%">Model</td>
<td style="color:#FFF" width="10%">Registeration Number</td>
<td style="color:#FFF" width="10%">Amount</td>
<td style="color:#FFF" width="10%">Start Date</td>
<td style="color:#FFF" width="10%">Expiry Date</td>
</tr>
<?php do { ?>
<tr class="success" style="text-transform:capitalize;font-size:16px">
<td style="color:#FFF" width="10%"><?php echo $row_cert['Insured_Name']; ?></td>
<td style="color:#FFF" width="10%"><?php echo $row_cert['Telephone']; ?></td>
<td style="color:#FFF" width="10%"><?php echo $row_cert['Policy_Number']; ?></td>
<td style="color:#FFF" width="10%"><?php echo $row_cert['Make_Of_Car']; ?></td>
<td style="color:#FFF" width="10%"><?php echo $row_cert['Model']; ?></td>
<td style="color:#FFF" width="10%"><?php echo $row_cert['Registeration_Number']; ?></td>
<td style="color:#FFF" width="10%"><?php echo $row_cert['Premium']; ?></td>
<td style="color:#FFF" width="10%"><?php echo $row_cert['Start_Date']; ?> </td>
<td style="color:#FFF; font-size:14px" width="10%"><?php echo $row_cert['Expiry_Date']; ?></td>
<?php } while ($row_cert = mysql_fetch_assoc($cert)); ?> </table>
<?php } // Show if recordset not empty ?>
but now i want to implement this same type of functionality in a mobile app, using phonegap, and i intend to make ajax requests using the snippets i have posted and display in a div, since php cannot be run in phonegap,
but i dont know how o go about this, i have done some searchin online but havent seen what i am lookin 4.
most especially because i want to use the same code i have used in my web project for this app by makin an ajax request
Simply, what you do is just make another http ajax request from phonegap to the same endpoint to your server, get the response and reload it in the div.
i.e
$.get(url_to_endpoint, function(data){
// do reloading of your div
});
this is can be done using jquerymobile library easily or depends how you do http requests from your phonegap.

Passing a Variable in PHP to the simplemodal

So hi guys. I have a problem regarding a variable passing. I can't explain it clearly but here's the code. I know it'll be clearer with this.
<tbody>
<tr>
<td><?php echo $row['nameSchool'] ?></td>
<td><?php echo $row['address'] ?></td>
<td><?php echo $row['honor'] ?></td>
<td><?php echo $row['year'] ?></td>
<td width = "5%"><div id='basic-modal-2'><img src="../img/edit.png" height="22" width="22"></div></td>
<td><img src="../img/Delete.png" height="22" width="22"></td>
</tr>
<?php
}
?>
</tbody>
//some codes here.
<!-- Update Employee -->
<div id="basic-modal-content-2">
<h3>Update Information</h3>
<p></p>
</br>
<form method="post" action="add3.php">
<table id = "box-table-c2" class = "basic-modal-content-2">
<thead></thead>
<tbody>
<tr>
<td><strong><?php echo $_GET['idnum']; ?></strong></td>
<td>:</td>
<td><input type="text" class="input-xlarge" name = "NS"></td>
</tr>
<tr>
<td><strong>Address</strong></td>
<td>:</td>
<td><input type="text" class="input-xlarge" name = "ad"></td>
</tr>
<tr>
<td><strong>Honors Received</strong></td>
<td>:</td>
<td><input type="text" class="input-xlarge" name = "HR"></td>
</tr>
<tr>
<td><strong>Year Graduated</strong></td>
<td>:</td>
<td><input type="text" class="input-xlarge" name = "YG"></td>
</tr>
<tr>
<td align= "left" width= "3"><button class="btn-primary" type="submit" style = "cursor: pointer";>Submit</button></td>
</tr>
</tbody>
</table>
</form>
</div>
They are both on the the same php file (educinfo.php)
My error is that i can't pass the value of the "EDIT" link to the simplemodal.
Thank You guys.
You can pass value in PHP using many ways. one way is passing value in Query String. That is you can pass value after file name with question mark. just like key value passing
phpfilename.php?key1=value1&key2=value2
You can pass any number of key and value. After that you can access in next page using key value.
In HTML Part:
<a href="filename.php?QueryString=valueOne" title = "Edit" class = "basic">
<img src="../img/edit.png" height="22" width="22">
</a>
In php you can get like this
$Idvalue = isset($_GET['QueryString']) ? $_GET['QueryString'] : "";
Please let me know if you have any issue for passing value like this

popup page php data doesn't show on submit

i have a table has php variables fetched from mysql , the table is inside a Form , what i am trying to do is to display page to be printed for the user with a an invoice style layout, i tried to make a behavior that when the FORM Is submitted , a pop up page will come display the php variables data , which is doesn't work at all , i tried to display the content of popup page inside a regluar page , it worked ! , which means there is no problem with my php code .
here is the form page code :
<form action="../../printInvoice.php" method="post" onsubmit="MM_openBrWindow('../../printInvoice.php','Invoice','status=yes,scrollbars=yes')">
<table width="100%" border="0">
<tr>
<td align="left">Invoice:</td>
</tr>
<tr>
<td width="12%" height="39" bgcolor="#9DE3FB" align="center">Invoice Number</td>
<td width="12%" bgcolor="#9DE3FB" align="center">Event Name</td>
<td width="12%" bgcolor="#9DE3FB" align="center">Reservation Date</td>
<td width="12%" bgcolor="#9DE3FB" align="center">Quantity</td>
<td width="12%" bgcolor="#9DE3FB" align="center">Price Per Ticket</td>
<td width="12%" bgcolor="#9DE3FB" align="center">Total Price</td>
</tr>
<tr>
<td width="12%" height="39" align="center"><input type="text" name="invoiceId" readonly="readonly" value="<? echo $row['invoiceId']; ?>" class ="field-style"/></td>
<td width="12%" height="39" align="center"><input type="text" name="eventTitle" readonly="readonly" value="<? echo $row['name']; ?>" class="field-style" /></td>
<td width="12%" height="39" align="center"><input type="text" name="invoiceDate" readonly="readonly" value="<? echo $row['invoiceDate']; ?>" class="field-style" /></td>
<td width="12%" height="39" align="center"><input type="text" name="invoiceqty" readonly="readonly" value="<? echo $row['quantity'] ?>" class="field-style" /></td>
<td width="12%" height="39" align="center"><input type="text" name="invoicePPU" readonly="readonly" value="<? echo $row['price']; ?>" class="field-style" /></td>
<td width="12%" height="39" align="center"><input type="text" name="invoiceTotal" readonly="readonly" value="<? echo $row['totalPrice']; ?>" class="field-style" /></td>
</tr>
</table>
<br />
<input type="submit" value="Print Invoice" />
</form>
here is the popup window code (invoice layout to print ):
<table width="65%" border="1" cellspacing="5" cellpadding="5">
<tr>
<td colspan="5"><table width="100%" border="0" cellspacing="5" cellpadding="5">
<tr>
<td width="60%"><img src="images/Logo.png" /></td>
<td width="40%"><p>Invoice No:# <? echo $invoiceId; ?></p>
<p>Invoice Date: <? echo $invoiceDate ;?> </p></td>
</tr>
</table></td>
</tr>
<tr>
<td height="125" colspan="5" valign="top"><p>Bill To:</p>
<p>Name:</p>
<p>Address:</p></td>
</tr>
<tr>
<td width="12%" align="center" height="40">Item Id</td>
<td width="28%" align="center">Item Disc</td>
<td width="9%" align="center">QTY</td>
<td width="40%" align="center">Price Per Unit</td>
<td width="11%" align="center">Total</td>
</tr>
<tr>
<td align="center" valign="middle">1</td>
<td align="center" valign="middle"><? echo $eventTitle . " ticket(s)"; ?></td>
<td align="center" valign="middle"><? echo $invoiceqty ; ?></td>
<td align="center" valign="middle"><? echo $invoicePPU ; ?></td>
<td align="center" valign="middle"><? echo $invoiceqty * $invoicePPU ; ?></td>
</tr>
</table>
for submitting behavior, i used Dreamweaver behavior panel. what's wrong here ?
I'm not sure about dreamweaver behaviour but as far as I can tell this will never work.
You are posting the data to a the "../../printInvoice.php" but when you request the popup page you are opening a new instance that hasn't received the post data.
You need to alter your javascript that pops the page up so that it posts the forms data when it performs the popup request.
I don't know which library you are using to create your popup but fancybox (Jquery plugin: http://fancybox.net) allows you to post data to the popup it creates.
If you could tell me what popup library you are using I might be able to help further.
you cant use php to show a popup you must use ajax, and javascript :
http://jquery.malsup.com/form/
$(document).ready(function() {
// bind 'myForm' and provide a simple callback function
$('#myForm').ajaxForm(function() {
//show your Popup
});
});
Have you tried to use $row['invoiceId']; instaed of $invoiceId in the popupwindow?
It seems to be the same file and therfore the $row[] data should be accessable!
If this doesn't works we propably need more code, especially of the php side.
^^ Overlooked something, we definitely need more code!
thanks, instead of all of this , i posted all the variables as url parameters such as :
<onsubmit="MM_openBrWindow('../../printInvoice.php?invoiceId=<? echo $row['invoiceId']; ?>&eventTitle=<? echo $row['name']; ?>','Invoice'
thanks for trying & your time everyone :)

Categories