In my flex application, I have a form which retrieves data from an SQL table and displays it in the textinput:
<s:Form id="form" includeIn="ShoppingList" x="223" y="353"
creationComplete="form_creationCompleteHandler(event)" defaultButton="{button}">
<s:FormItem label="Name">
<s:TextInput id="textInput" text="{getAllShoppinglistResult.lastResult[0].name}"/>
<s:TextInput id="textInput1" text="{getAllShoppinglistResult.lastResult[1].name}"/>
<s:TextInput id="textInput2" text="{getAllShoppinglistResult.lastResult[2].name}"/>
<s:TextInput id="textInput3" text="{getAllShoppinglistResult.lastResult[3].name}"/>
</s:FormItem>
<s:Button id="button" label="Submit" click="button_clickHandler(event)"/>
</s:Form>
In this case, there is just 2 items in the SQL table, the other 2 text input fields of free.
I want to be able to type text into the textinput and it saves it to the server.
protected function button_clickHandler(event:MouseEvent):void
{
items.name = textInput.text;
createShoppinglistResult.token = shoppinglistService1.createShoppinglist(name);
}
protected function createShoppinglistResult_resultHandler(event:ResultEvent):void
{
}
I'm unsure as to what goes into the createShoppinglist..* function.
I know that the PHP service is correct as currently it does save it to the server but it just saves NULL, I want it to save the textinput. I know that if it were a datagrid I could use AddItem() for an Array Collection, but I don't know what I could use for a form?
Maybe that will help! regards aktell
Unfortunately looks a bit like a mess! Here is a Link were you can see it much better - just towards the bottom!
http://board.flashkit.com/board/showthread.php?828493-php-gt-gt-mySQL-not-returning-data-as-XML
<?php
// init.php
// Script:
// Connecting to the MySQL DataBase Server & a DataBase.
/* ------------------------------------------------------------------------------------------------------------------ */
// MySQL DataBase Server Variables.
$mysql_host = "localhost";
$mysql_user = "root";
$mysql_pass = "";
// DataBase Variable.
$db = 'webflash_createcartdb';
// Connect to MySQL DataBase Server.
$con = # mysql_connect("$mysql_host", "$mysql_user", "$mysql_pass")
or exit("Could not connect to MySQL DataBase Server! \n Select DB Error: " . # mysql_error());
$con = # mysql_select_db($db)
or exit( 'Can\'t select the Database is unavailable.' . # mysql_error());
return $con;
/* ------------------------------------------------------------------------------------------------------------------ */
?>
READ & WRITE:
// custInfoDetails.php
/* ------------------------------------------------------------------------------------------------------------------ */
header('Content-Type: text/xml');
/* ------------------------------------------------------------------------------------------------------------------ */
include("../Conn/init.php");
/* ------------------------------------------------------------------------------------------------------------------ /
// MAIN TABLE.
/ ------------------------------------------------------------------------------------------------------------------ */
if (isset($_POST['lastName'])) {
$title = $_POST['title'];
$firstName = $_POST['firstName'];
$middleName = $_POST['middleName'];
$lastName = $_POST['lastName'];
$fullName = $_POST['fullName'];
$no = $_POST['no'];
$street1 = $_POST['street1'];
$street2 = $_POST['street2'];
$zip = $_POST['zip'];
$suburb = $_POST['suburb'];
$city = $_POST['city'];
$state = $_POST['state'];
$country = $_POST['country'];
$email = $_POST['email'];
$userName = $_POST['userName'];
$password = $_POST['password'];
$userNameCopy = mysql_real_escape_string($_POST["userNameCopy"]);
$sql = 'INSERT INTO ' . $userNameCopy . '
(title, firstName, middleName, lastName, fullName, no, street1, street2, zip, suburb, city,
state, country, email, userName, password, now)
VALUES
("' . $title . '", "' . $firstName . '", "' . $middleName . '", "' . $lastName . '", "' . $fullName . '",
"' . $no . '", "' . $street1 . '", "' . $street2 . '", "' . $zip . '", "' . $suburb . '",
"' . $city . '", "' . $state . '", "' . $country . '", "' . $email . '",
"' . $userName . '", "' . $password . '", NOW() )';
$result = # mysql_query($sql);
if (!$result) { exit('Error performing the MAIN INSERT query.' . # mysql_error());
}
}
/* ------------------------------------------------------------------------------------------------------------------ */
$sql = "SELECT custcartinfoID, title, firstName, middleName, lastName, fullName, no, street1, street2,
zip, suburb, city, state, country, email, userName, password, now FROM ' . $userNameCopy . ' ";
$result = # mysql_query($sql);
if (!$result) {
$message = 'Invalid query: ' . # mysql_errno() . " : " . # mysql_error() . "\n";
$message .= 'Whole query: ' . $sql;
exit($message);
}
/* ------------------------------------------------------------------------------------------------------------------ /
// XML READOUT.
/ ------------------------------------------------------------------------------------------------------------------ */
$xml = new DomDocument('1.0', 'UTF-8');
$root = $xml->createElement('allMessages');
$root = $xml->appendChild($root);
$result = # mysql_query($sql);
if ($result) {
if ( # mysql_num_rows($result) > 0) {
while ($row = # mysql_fetch_array($result)) {
$custcartinfoID = $row['custcartinfoID'];
$title = $row['title'];
$firstName = $row['firstName'];
$middleName = $row['middleName'];
$lastName = $row['lastName'];
$fullName = $row['fullName'];
$no = $row['no'];
$street1 = $row['street1'];
$street2 = $row['street2'];
$zip = $row['zip'];
$suburb = $row['suburb'];
$city = $row['city'];
$state = $row['state'];
$country = $row['country'];
$email = $row['email'];
$userName = $row['userName'];
$password = $row['password'];
$now = $row['now'];
// Message Element OPEN Node.
$itemElement = $xml->createElement('message');
$itemElement = $root->appendChild($itemElement);
// First Field.
$idElement = $xml->createElement('custcartinfoID', $custcartinfoID);
$idElement = $itemElement->appendChild($idElement);
$titleElement = $xml->createElement('title', $title);
$titleElement = $itemElement->appendChild($titleElement);
$firstNameElement = $xml->createElement('firstName', $firstName);
$firstNameElement = $itemElement->appendChild($firstNameElement);
$middleNameElement = $xml->createElement('middleName', $middleName);
$middleNameElement = $itemElement->appendChild($middleNameElement);
$lastNameElement = $xml->createElement('lastName', $lastName);
$lastNameElement = $itemElement->appendChild($lastNameElement);
$fullNameElement = $xml->createElement('fullName', $fullName);
$fullNameElement = $itemElement->appendChild($fullNameElement);
$noElement = $xml->createElement('no', $no);
$noElement = $itemElement->appendChild($noElement);
$street1Element = $xml->createElement('street1', $street1);
$street1Element = $itemElement->appendChild($street1Element);
$street2Element = $xml->createElement('street2', $street2);
$street2Element = $itemElement->appendChild($street2Element);
$zipElement = $xml->createElement('zip', $zip);
$zipElement = $itemElement->appendChild($zipElement);
$suburbElement = $xml->createElement('suburb', $suburb);
$suburbElement = $itemElement->appendChild($suburbElement);
$cityElement = $xml->createElement('city', $city);
$cityElement = $itemElement->appendChild($cityElement);
$stateElement = $xml->createElement('state', $state);
$stateElement = $itemElement->appendChild($stateElement);
$countryElement = $xml->createElement('country', $country);
$countryElement = $itemElement->appendChild($countryElement);
$emailElement = $xml->createElement('email', $email);
$emailElement = $itemElement->appendChild($emailElement);
$userNameElement = $xml->createElement('userName', $userName);
$userNameElement = $itemElement->appendChild($userNameElement);
$passwordElement = $xml->createElement('password', $password);
$passwordElement = $itemElement->appendChild($passwordElement);
// Last Field.
$nowElement = $xml->createElement('now', $now);
$nowElement = $itemElement->appendChild($nowElement);
}
}
// Message Element CLOSING Node.
else {
$messageElement = $xml->createElement('message','There are no posts.');
$messageElement = $root->appendChild($messageElement);
}
}
else {
$messageElement = $xml->createElement('message', #mysql_error());
$messageElement = $root->appendChild($messageElement);
}
// Return the XML Document.
echo $xml->saveXML();
/* ------------------------------------------------------------------------------------------------------------------ */
// CLOSE DATABSE.
// Close DataBase Server Connection!
# mysql_close($con);
/* ------------------------------------------------------------------------------------------------------------------ */
?>
READ ONLY:
// select.php
/* ------------------------------------------------------------------------------------------------------------------ */
// First, this script uses the header() function to tell the web server that the return is going to be XML.
header('Content-Type: text/xml');
/* ------------------------------------------------------------------------------------------------------------------ */
// Connecting with MySQL DataBase Server & a DataBase.
include("init.php");
/* ------------------------------------------------------------------------------------------------------------------ /
// MAIN TABLE.
/ ------------------------------------------------------------------------------------------------------------------ */
// SELECT more than one Table !
/* $query="SELECT movie.movie_name, movietype.movietype_label FROM movie, movietype
WHERE movie.movie_type = movietype.movietype_id
AND movie.movie_year>1990
ORDER BY movie_type"; */
$sql = 'SELECT customerID, title, firstname, middlename, lastname, no, street1, street2, zip, suburb, city,
state, country, email, emailpriv, emailbus, url1, url2, note, now FROM customerdetails';
$result = # mysql_query($sql);
if (!$result) {
$message = 'Invalid query: ' . # mysql_errno() . " : " . # mysql_error() . "\n";
$message .= 'Whole query: ' . $sql;
exit($message);
}
/* ------------------------------------------------------------------------------------------------------------------ /
// XML READOUT.
/ ------------------------------------------------------------------------------------------------------------------ */
$xml = new DomDocument('1.0', 'UTF-8');
$root = $xml->createElement('customerDetails');
$root = $xml->appendChild($root);
$result = # mysql_query($sql);
if ($result) {
if ( # mysql_num_rows($result) > 0) {
while ($row = # mysql_fetch_array($result)) {
$customerID = $row['customerID'];
$title = $row['title'];
$firstname = $row['firstname'];
$middlename = $row['middlename'];
$lastname = $row['lastname'];
$no = $row['no'];
$street1 = $row['street1'];
$street2 = $row['street2'];
$zip = $row['zip'];
$suburb = $row['suburb'];
$city = $row['city'];
$state = $row['state'];
$country = $row['country'];
$email = $row['email'];
$emailpriv = $row['emailpriv'];
$emailbus = $row['emailbus'];
$url1 = $row['url1'];
$url2 = $row['url2'];
$note = $row['note'];
$now = $row['now'];
// Message Element OPEN Node.
$itemElement = $xml->createElement('information');
$itemElement = $root->appendChild($itemElement);
// First Field.
$idElement = $xml->createElement('customerID', $customerID);
$idElement = $itemElement->appendChild($idElement);
$titleElement = $xml->createElement('title', $title);
$titleElement = $itemElement->appendChild($titleElement);
$firstnameElement = $xml->createElement('firstname', $firstname);
$firstnameElement = $itemElement->appendChild($firstnameElement);
$middlenameElement = $xml->createElement('middlename', $middlename);
$middlenameElement = $itemElement->appendChild($middlenameElement);
$lastnameElement = $xml->createElement('lastname', $lastname);
$lastnameElement = $itemElement->appendChild($lastnameElement);
$noElement = $xml->createElement('no', $no);
$noElement = $itemElement->appendChild($noElement);
$street1Element = $xml->createElement('street1', $street1);
$street1Element = $itemElement->appendChild($street1Element);
$street2Element = $xml->createElement('street2', $street2);
$street2Element = $itemElement->appendChild($street2Element);
$zipElement = $xml->createElement('zip', $zip);
$zipElement = $itemElement->appendChild($zipElement);
$suburbElement = $xml->createElement('suburb', $suburb);
$suburbElement = $itemElement->appendChild($suburbElement);
$cityElement = $xml->createElement('city', $city);
$cityElement = $itemElement->appendChild($cityElement);
$stateElement = $xml->createElement('state', $state);
$stateElement = $itemElement->appendChild($stateElement);
$countryElement = $xml->createElement('country', $country);
$countryElement = $itemElement->appendChild($countryElement);
$emailElement = $xml->createElement('email', $email);
$emailElement = $itemElement->appendChild($emailElement);
$emailprivElement = $xml->createElement('emailpriv', $emailpriv);
$emailprivElement = $itemElement->appendChild($emailprivElement);
$emailbusElement = $xml->createElement('emailbus', $emailbus);
$emailbusElement = $itemElement->appendChild($emailbusElement);
$url1Element = $xml->createElement('url1', $url1);
$url1Element = $itemElement->appendChild($url1Element);
$url2Element = $xml->createElement('url2', $url2);
$url2Element = $itemElement->appendChild($url2Element);
$noteElement = $xml->createElement('note', $note);
$noteElement = $itemElement->appendChild($noteElement);
// Last Field.
$nowElement = $xml->createElement('now', $now);
$nowElement = $itemElement->appendChild($nowElement);
}
}
// Message Element CLOSING Node.
else {
$messageElement = $xml->createElement('information','There are no posts.');
$messageElement = $root>appendChild($messageElement);
}
}
else {
$messageElement = $xml->createElement('information', #mysql_error());
$messageElement = $root>appendChild($messageElement);
}
echo $xml->saveXML();
?>
Related
Sorry if its a little mistake. i was using first time multi query. error 1 and error 2 both codes are same except single colon('') added in error 2 insert row. if i echo from inside the the for loop shows everything fine. some time success but not inserted in data base. Thank You in advance.
Error 1: Error :You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near 'INSERT INTO student_attendance (attendance_date,
attendance_class_id, attendance' at line 1
include("../includes/db.php");
if(!empty($_POST)) {
$student_attendance_id = $_POST['student_attendance_id'];
$attendance_date = $_POST['attendance_date'];
$attendance_class_id = $_POST['attendance_class_id'];
$attendance_section_id = $_POST['attendance_section_id'];
$attendance_student_id = $_POST['attendance_student_id'];
if(isset($_POST['attendance_present_absent'])){
$attendance_present_absent = $_POST['attendance_present_absent'];
} else {
$attendance_present_absent = '';
}
$query = '';
for($count = 0; $count<count($attendance_student_id); $count++)
{
$attendance_date_now = mysqli_real_escape_string($connection, $attendance_date);
$student_attendance_id_now = mysqli_real_escape_string($connection, $student_attendance_id[$count]);
$attendance_class_id_now = mysqli_real_escape_string($connection, $attendance_class_id[$count]);
$attendance_section_id_now = mysqli_real_escape_string($connection, $attendance_section_id[$count]);
$attendance_student_id_now = mysqli_real_escape_string($connection, $attendance_student_id[$count]);
$attendance_present_absent_now = mysqli_real_escape_string($connection, $attendance_present_absent[$count]);
$query .= "INSERT INTO student_attendance (attendance_date, attendance_class_id, attendance_section_id, attendance_student_id, attendance_present_absent ) ";
$query .= "VALUES ('{$attendance_date_now}', '{$attendance_class_id_now}', '{$attendance_section_id_now}', '{$attendance_student_id_now}', '{$attendance_present_absent_now}' ) ";
echo $attendance_date_now;
echo $attendance_class_id_now . $attendance_section_id_now . "<br>";
}
$result = mysqli_multi_query($connection, $query) or die("Error :" . mysqli_error($connection));
Error 2:You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ''attendance_date', 'attendance_class_id',
'attendance_section_id', 'attendance_s' at line 1
include("../includes/db.php");
if(!empty($_POST)) {
$student_attendance_id = $_POST['student_attendance_id'];
$attendance_date = $_POST['attendance_date'];
$attendance_class_id = $_POST['attendance_class_id'];
$attendance_section_id = $_POST['attendance_section_id'];
$attendance_student_id = $_POST['attendance_student_id'];
if(isset($_POST['attendance_present_absent'])){
$attendance_present_absent = $_POST['attendance_present_absent'];
} else {
$attendance_present_absent = '';
}
for($count = 0; $count<count($attendance_student_id); $count++)
{
$attendance_date_now = mysqli_real_escape_string($connection, $attendance_date);
$student_attendance_id_now = mysqli_real_escape_string($connection, $student_attendance_id[$count]);
$attendance_class_id_now = mysqli_real_escape_string($connection, $attendance_class_id[$count]);
$attendance_section_id_now = mysqli_real_escape_string($connection, $attendance_section_id[$count]);
$attendance_student_id_now = mysqli_real_escape_string($connection, $attendance_student_id[$count]);
$attendance_present_absent_now = mysqli_real_escape_string($connection, $attendance_present_absent[$count]);
$query .= "INSERT INTO student_attendance ('attendance_date', 'attendance_class_id', 'attendance_section_id', 'attendance_student_id', 'attendance_present_absent' ) ";
$query .= "VALUES ('{$attendance_date_now}', '{$attendance_class_id_now}', '{$attendance_section_id_now}', '{$attendance_student_id_now}', '{$attendance_present_absent_now}' ) ";
echo $attendance_date_now;
echo $attendance_class_id_now . $attendance_section_id_now . "<br>";
}
$result = mysqli_multi_query($connection, $query) or die("Error :" . mysqli_error($connection));
There are two mistakes. First is, in your for cycle you have to add ; after each INSERT string. Second, if you wanna use multiple insert, you should write INSERT part string before for cycle and then just add rows with values, there is , separator used.
include("../includes/db.php");
if(!empty($_POST)) {
$student_attendance_id = $_POST['student_attendance_id'];
$attendance_date = $_POST['attendance_date'];
$attendance_class_id = $_POST['attendance_class_id'];
$attendance_section_id = $_POST['attendance_section_id'];
$attendance_student_id = $_POST['attendance_student_id'];
if(isset($_POST['attendance_present_absent'])){
$attendance_present_absent = $_POST['attendance_present_absent'];
} else {
$attendance_present_absent = '';
}
$query = '';
for($count = 0; $count<count($attendance_student_id); $count++)
{
$attendance_date_now = mysqli_real_escape_string($connection, $attendance_date);
$student_attendance_id_now = mysqli_real_escape_string($connection, $student_attendance_id[$count]);
$attendance_class_id_now = mysqli_real_escape_string($connection, $attendance_class_id[$count]);
$attendance_section_id_now = mysqli_real_escape_string($connection, $attendance_section_id[$count]);
$attendance_student_id_now = mysqli_real_escape_string($connection, $attendance_student_id[$count]);
$attendance_present_absent_now = mysqli_real_escape_string($connection, $attendance_present_absent[$count]);
$query .= "INSERT INTO student_attendance (attendance_date, attendance_class_id, attendance_section_id, attendance_student_id, attendance_present_absent ) ";
$query .= "VALUES ('{$attendance_date_now}', '{$attendance_class_id_now}', '{$attendance_section_id_now}', '{$attendance_student_id_now}', '{$attendance_present_absent_now}' ); ";
echo $attendance_date_now;
echo $attendance_class_id_now . $attendance_section_id_now . "<br>";
}
$result = mysqli_multi_query($connection, $query) or die("Error :" . mysqli_error($connection));
OR
include("../includes/db.php");
if(!empty($_POST)) {
$student_attendance_id = $_POST['student_attendance_id'];
$attendance_date = $_POST['attendance_date'];
$attendance_class_id = $_POST['attendance_class_id'];
$attendance_section_id = $_POST['attendance_section_id'];
$attendance_student_id = $_POST['attendance_student_id'];
if(isset($_POST['attendance_present_absent'])){
$attendance_present_absent = $_POST['attendance_present_absent'];
} else {
$attendance_present_absent = '';
}
$query = 'INSERT INTO student_attendance (attendance_date, attendance_class_id, attendance_section_id, attendance_student_id, attendance_present_absent ) VALUES ';
for($count = 0; $count<count($attendance_student_id); $count++)
{
$attendance_date_now = mysqli_real_escape_string($connection, $attendance_date);
$student_attendance_id_now = mysqli_real_escape_string($connection, $student_attendance_id[$count]);
$attendance_class_id_now = mysqli_real_escape_string($connection, $attendance_class_id[$count]);
$attendance_section_id_now = mysqli_real_escape_string($connection, $attendance_section_id[$count]);
$attendance_student_id_now = mysqli_real_escape_string($connection, $attendance_student_id[$count]);
$attendance_present_absent_now = mysqli_real_escape_string($connection, $attendance_present_absent[$count]);
$query .= ($count>0?",":"") . "('{$attendance_date_now}', '{$attendance_class_id_now}', '{$attendance_section_id_now}', '{$attendance_student_id_now}', '{$attendance_present_absent_now}' )";
echo $attendance_date_now;
echo $attendance_class_id_now . $attendance_section_id_now . "<br>";
}
$query .= ";"
$result = mysqli_multi_query($connection, $query) or die("Error :" . mysqli_error($connection));
What is the best way to stop the script if there are no results????
The Upload the file that is created to a vender but I don't need to creat a file if there is no results,
I have a second question what is the best way to run this every hour between 8 am and 6 pm Monday through Friday?
I found a lot of information on this if using MySQL but we are using Microsoft SQL Server.
Thanks for the help!
<?php
$connect = odbc_connect("removed");
if (!$connect) {
exit("Connection Failed: " . $connect);
}
$gr_total = 0;
$gr_count = 0;
$sql = "
SELECT distinct
ltrim(rtrim(SO.ompCustomerOrganizationID))as customer
,ltrim(rtrim(left(cmoName,30))) as name
,left(ltrim(rtrim(cmoAddressLine2)),30) as address1
,ltrim(rtrim(cmoCity)) as city
,ltrim(rtrim(cmoState)) as state
,ltrim(rtrim(cmoPostCode)) as postal
, ltrim(rtrim(REPLACE(REPLACE(REPLACE(cmoPhoneNumber, '(', ''), ')', ''), '-', ''))) as phone
FROM m1_kf.dbo.SalesOrders SO
LEFT JOIN m1_kf.dbo.Organizations ON cmoOrganizationID = SO.ompCustomerOrganizationID
WHERE ompCreatedDate >='06-11-2017' and ompPaymentTermID in ('CN30','CTN30')
and UOMPSCHEDULENUMBER !=1 and ompOrderTotalBase > 1
";
$sql2 = "
select
ltrim(rtrim(ompCustomerOrganizationID)) as cust
,ltrim(rtrim(ompSalesOrderID)) as orderid
, right('00000000'+cast(cast(round(ompOrderTotalBase,0)as int) as varchar(8)),8) as num
,REPLACE(CONVERT(VARCHAR(10), ompRequestedShipDate, 1), '/', '') as reqship
,'030' as terms
,REPLACE(CONVERT(VARCHAR(10), ompRequestedShipDate, 1), '/', '') as ship
FROM m1_kf.dbo.SalesOrders SO
WHERE ompCreatedDate >='06-11-2017' and ompPaymentTermID in ('CN30','CTN30')
and UOMPSCHEDULENUMBER !=1 and ompOrderTotalBase > 1
order by SO.ompCustomerOrganizationID
";
$result = odbc_exec($connect, $sql);
if (!$result) {
exit("Error in SQL");
}
$mycount = 0;
$tradestyle = ' ';
$address2 = ' ';
$my_file = 'cit_order_upload.co';
$handle = fopen($my_file, 'w+') or die('Cannot open file: ' . $my_file);
while ($row = odbc_fetch_array($result)) {
$record_type = 'A';
$cit_cust_id = '1234';
$cust_num = $row['customer'];
$name = $row['name'];
$address = $row['address1'];
$city = $row['city'];
$state = $row['state'];
$postal = $row['postal'];
$phone = $row['phone'];
fprintf($handle, "%-4s%-2s%-1s%-15s%-30s%-30s%-30s%-17s%-2s%-9s%-10s", $cit_cust_id, $tradestyle, $record_type, $cust_num, $name, $address, $address2, $city, $state, $postal, $phone . "\n");
$mycount = $mycount + 1;
}
$results = odbc_exec($connect, $sql2);
if (!$results) {
exit("Error in SQL");
}
$mycount2 = 0;
$space1 = ' ';
$space6 = ' ';If the first while loop does not have any results then stop the script
$space12 = ' ';
$today = date("mdy");
echo "<table><tr>";
echo "<th>CustID</th>";
echo "<th>OrderId</th>";
echo "<th>Amount</th>";
echo "<th>TotalAmount</th>";
while ($row = odbc_fetch_array($results)) {
$client = '1234';
$trade = ' ';
$record_ty = 'R';
$cust = $row['cust'];
$orderid = $row['orderid'];
$num = $row['num'];
$reqship = $row['reqship'];
$terms = $row['terms'];
$ship = $row['ship'];
$mycount2 = $mycount2 + 1;
$gr_total = $gr_total + $row['num'];
$tradestyle = '99';
$custnum = '999999999999999';
$record = 'S';
$recordtype = '999999T999999999999999';
fprintf($handle, "%-4s%-1s%-1s%-15s%-22s%-8s%-1s%-6s%-3s%-6s", $client, $trade, $record_ty, $cust, $orderid, $num, $space1, $reqship, $terms, $ship . "\n");
echo "<tr><td>$cust </td>";
echo "<td> $orderid </td>";
echo "<td> $num </td>";
echo "<td> $gr_total </td></tr>";
}
fprintf($handle, "%-4s%-2s%-1s%-15s%06d%06d%-6s%012d", $client, $tradestyle, $record, $custnum, $mycount, $mycount2, $space6, $gr_total);
fprintf($handle, "\n");
fprintf($handle, "%-22s%06d%06d%-6s%012d%-12s%-6s", $recordtype, $mycount, $mycount2, $space6, $gr_total, $space12, $today);
fclose($handle);
?>
You already have this stop condition if query is unsuccessful, for handling case with no results modify it like below:
if (!$result) {
exit("Error in SQL");
}
if (0 === odbc_num_rows($result)) {
exit("No results");
}
Check the docs for OBDC_num_rows.
About your secondary question - cron utility is probably the most popular way to schedule jobs. Your crontab string should be like this:
* 8-18/1 * * 2,3,4,5 yourscript.php
I write a simple web application for my compnay that can let user log in to arrange their work time. Besides, user can also view the report of he's or she's attandence that I use ajax to callback from java.jar. (We use java to analyze)I use Xampp to set up the server in virtual machine HyperV and it can run successfully at the begining but after twenty hours or more than one day it won't let anyone to log in.
I open the error.log shows that :
PHP Fatal error: Could not queue new timer in Unknown on line 0
. . . and than:
PHP Warning: mysqli_connect(): (HY000/2002): Unknown Error
I don't understand what can cause that happend and how to solve it.
I alreday know is when I restarted the apache server, it can still be used till that error happened.
My System Enviroment :
win7 64 bit HyperV
xampp Apache/2.4.18, php/7.0.6, mysql/ 5.1
Here is my code:
mysql_start.php
<?php
header("Content-Type:html;charset=utf-8");
$servername = "127.0.0.1";
$username = "root";
$password = "cc1234";
$dbname = "cc_tw000427";
$conn = null;
try {
$conn = new mysqli($servername, $username, $password, $dbname);
} catch (Exception $e) {
$error_message = "Connect Error (" .$conn->connect_errno ." )" . $conn->connect_error;
error_log($error_message, 3, "php_error_log");
header("location:login.php?err=$e");
}
$conn->set_charset("utf-8");
$strDBColLoingAccount = "AccountID";
checklogin.php
session_start();
include_once("mysql_start.php");
$yid = trim(filter_input(INPUT_POST, "yid"));
$passd = trim(filter_input(INPUT_POST,"passd"));
$strSql = "SELECT acc.*, b.String_10_1 FROM basicstoreinfomanageacc_sub acc,basicstoreinfo b
WHERE acc.$strDBColLoingAccount ='$yid' AND acc.String_50_1 = b.String_50_1";
$result = $conn->query($strSql);
$n = $result->num_rows;
if ($n == 0) {
header("Location:../desktop/login.php?err=1");
echo "Error 1";
exit();
}
while ($row = $result->fetch_assoc()) {
$passd_right = $row["AccountPwd"];
$user_id = $row["AccountID"];
$user_name = $row["AccountName"];
$user_dep_id = $row["String_10_1"];
$user_dep = $row['String_50_1'];
}
$result->close();
if (($passd_right == "") || ($passd_right == NULL)){
session_start();
$_SESSION['user_id'] = $user_id;
$_SESSION['user_name'] = $user_name;
header("location:newpwd.php");
exit();
}
if ($passd == $passd_right) {
$_SESSION['user_id'] = $user_id;
$_SESSION['user_name'] = $user_name;
$_SESSION['loginOK'] = 'yes';
$_SESSION['year_i'] = date('Y',time());
$_SESSION['year_f'] = date('Y',time());
$_SESSION['month_i'] = date('m',time());
$_SESSION['month_f'] = date('m',time());
$_SESSION['day_i'] = date('d',time());
$_SESSION['day_f'] = date('d',time());
$_SESSION['Hour'] = date('Y-m-d G:i:s',strtotime('+6 hour'));
$_SESSION['user_dep_id'] = $user_dep_id;
$_SESSION['user_dep'] = $user_dep;
header("Location:../desktop/Punch.php");
} else {
header("Location:../desktop/login.php?err=1");
}
$conn->close();
?>
Next two *.php files are used to receive the post from the web.
The select.php is used to select the data from mysql than output in html tag.
The save.php is used to save the data post from web.
select.php
<?php
session_start();
include_once '../control/mysql_start.php';
$strYear = $_POST['year'];
$strMonth = $_POST['month'];
$strDay = $_POST['day'];
.
.//some codes
.
$strSql = "SELECT * FROM basicemploymentinfo bei WHERE bei.BelongStore = '". $_SESSION['user_dep']."'".
"AND ((bei.datetime_2 is null AND bei.datetime_3 is null) OR (bei.datetime_2 is null AND bei.datetime_3 >= STR_TO_DATE('" . $strDate . "', '%Y-%m-%d'))" .
" OR (bei.datetime_2 <= STR_TO_DATE('" . $strDate . "', '%Y-%m-%d') AND bei.datetime_3 is null)" .
" OR (bei.datetime_2 <= STR_TO_DATE('" . $strDate . "', '%Y-%m-%d') AND bei.datetime_3 >= STR_TO_DATE('" . $strDate . "', '%Y-%m-%d'))) "
."AND bei.Active ='Y'";
$EmpId = array();
$EmpName = array();
if ($result = $conn->query($strSql)) {
while($row = $result->fetch_assoc()) {
array_push($EmpId, $row['String_20_1']);
array_push($EmpName, $row['String_20_2']);
.
.//some codes
.
}
}
$Emp = array_combine($EmpId, $EmpName);
$strSql = " SELECT Distinct date_format(DateTime_1, '%e') as date, AutoCheck
FROM hrotcheck
WHERE date_format(DateTime_1, '%Y-%m-%d') = '$newformat'
AND AutoCheck = 'C'
AND String_20_1 IN ($array_emp_id)";
if ($result = $conn->query($strSql)) {
$n = $result->num_rows;
if ($n > 0) { $checkboxVerify = 'C';}
}
$result->close();
foreach ($Emp as $EId => $EName)
{
.
.//some codes
.
$strSql = "SELECT RegularM_1, RegularM_2, FORMAT(OT_3, 1) as OT_3, TOM, TOTM, Notes, AutoCheck FROM hrotcheck where string_20_1 = '" . $EId . "' AND"." date_format(DateTime_1,'%Y-%m-%d') = '$newformat'";
$result = $conn->query($strSql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$RegularM_1 = $row['RegularM_1'];
$RegularM_2 = $row['RegularM_2'];
$OT3 = $row['OT_3'];
$tom = $row['TOM'];
$totm = $row['TOTM'];
$notes = $row['Notes'];
}
}
$result->close();
.
.//I did a lot of SQL select and use that to create htmltable
.
$output .= '
<tr data-table="sub">
<td>'.$row['string_20_1'].'</td>
<td>'.$row['string_20_2'].'</td>
.
.//<td>...</td>
.
<td class="'.$condition16.'">'.$notes.'</td>
<td class="'.$condition17.'"></td>
</tr>
';
}
.
.//some codes
.
$strSql01 = "SELECT * FROM manufacturejobschedulingpersonal where string_20_1 = '".
$row['string_20_1']."' AND"." date_format(DateTime_1,'%Y-%m-%d') = '$newformat'";
$result01 = $conn->query($strSql01);
if ($result01->num_rows > 0) {
while ($row01 = $result01->fetch_assoc()) {
.
.//some codes
.
}
}
$result01->close();
.
.//some codes
.
$result->close();
$conn->close();
echo $optionUse.'?'.$checkboxVerify.'?'.$output.'?'.$hasCheckDate;
?>
save.php
<?php
session_start();
include_once '../control/mysql_start.php';
$arrayObjs = $_POST;
.
.//some codes
.
$msDanger = '';
foreach($arrayObjs as $array)
{
foreach($array as $row)
{
$UserId = $row['UserId'];
$UserName = $row['UserName'];
.
.//some codes
.
$strSql = "SELECT * FROM manufacturejobschedulingpersonal where string_20_1 = '".
$UserId."' AND"." date_format(DateTime_1,'%Y-%m-%d') = '$DateTime_1'";
$result = $conn->query($strSql);
if( $result->num_rows > 0) {
if ($table == 'main') {
$strSql = "Update manufacturejobschedulingpersonal SET String_10_1 ='$String_10_1', String_Assist01 ='$assist_1',String_Assist02='$assist_2' where string_20_1 = '".
$UserId."' AND"." date_format(DateTime_1,'%Y-%m-%d') = '$DateTime_1'";
} else {
$strSql = "Update manufacturejobschedulingpersonal SET String_10_1 ='$String_10_1' where string_20_1 = '".
$UserId."' AND"." date_format(DateTime_1,'%Y-%m-%d') = '$DateTime_1'";
}
$result = $conn->query($strSql);
} else {
$strSql = "INSERT INTO manufacturejobschedulingpersonal (string_20_1,string_20_2,YM,DateTime_1,String_10_1,String_Assist01,String_Assist02)".
"VALUES ( '$UserId', '$UserName', '$YM', '$DateTime_1', '$String_10_1','$assist_1','$assist_2')";
$result = $conn->query($strSql);
}
.
.//A lot of sql CRUD
.
}
}
$conn->close();
$last_line = exec('java -jar C:/CCERP/ChainCodeERP/ExtraModule/HRMultiOTCheck/HRMultiOTCheck.jar -ssa '.$javaDate.' ' .$javaDepId, $return_var);
echo 'Updated';
?>
I'm trying to run a PDO update statement, but none of the fields are being updated. Here is my PDO query. I've gone through and tried to find where the values were being changed and found that where being assigned nothing. I found the problem right when the values are escaped (You'll see my comment placed there). I know it probably something I'm overlooking but I haven't been able to figure out yet.
if(isset($_POST['submit']))
{
if(isset($_POST['name'])){ $name = $_POST['name'];}else{ $name = '';}
if(isset($_POST['city'])){ $city = $_POST['city'];}else{ $city = '';}
if(isset($_POST['state'])){ $state = $_POST['state'];}else{ $state = '';}
if(isset($_POST['address_line1'])){ $address_line1 = $_POST['address_line1'];}else{ $address_line1 = '';}
if(isset($_POST['address_line2'])){ $address_line2 = $_POST['address_line2'];}else{ $address_line2 = '';}
if(isset($_POST['city'])){ $city = $_POST['city'];}else{ $city = '';}
if(isset($_POST['state'])){ $state = $_POST['state'];}else{ $state = '';}
if(isset($_POST['zip_code'])){ $zip_code = $_POST['zip_code'];}else{ $zip_code = '';}
if(isset($_POST['last_modified_by'])){ $last_modified_by = $_POST['last_modified_by'];}else{ $last_modified_by = 'admin';}
$last_modified_date = date('Y-m-d H:i:s');
$confirmcode = 'y';
if(isset($_POST['bitactive'])){ $bitactive = $_POST['bitactive'];}else{ $bitactive = '';}
//Test portion 1 = Values are correct
// echo $address_line1 . "<p>";
// echo $city . "<p>";
// echo $zip_code . "<p>";
// exit;
$support_broker_id = $_GET['id'];
$user_exists = "SELECT * FROM lu_agency WHERE agency_id =". $support_broker_id;
$statement = $conn->query($sql);
$result = $statement->fetch();
$count = $statement->rowCount();
$name = $row['name'];
$address_line1 = $row['address_line1'];
$address_line2 = $row['address_line2'];
$city = $row['city'];
$state = $row['state'];
$zip_code = $row['zip_code'];
$last_modified_by = $row['last_modified_by'];
$last_modified_date = $row['last_modified_date'];
$bitactive = $row['bitactive'];
//Test portion two: Values are correct
// echo $address_line1 . "<p>";
// echo $city . "<p>";
// echo $zip_code . "<p>";
// exit;
if($count > 0)
{
$sqlupdate = "UPDATE lu_agency
SET name = :name,
address_line1 = :address_line1,
address_line2 = :address_line2,
city = :city,
state = :state,
zip_code = :zip_code,
last_modified_by = :last_modified_by,
last_modified_date = :last_modified_date,
bitactive = :bitactive
WHERE agency_id= ". $support_broker_id;
//Here is where only $city and $support_broker_id have values, the others don't show up
echo $address_line1 . "<p>";
echo $city . "<p>";
echo $zip_code . "<p>";
echo $support_broker_id . "<p>";
exit;
$preparedstmt = $conn->prepare($sqlupdate);
$preparedstmt->execute(
array(
':name'=>$name,
':address_line1'=>$address_line1,
':address_line2'=>$address_line2,
':city'=>$city,
':state'=>$state,
':zip_code'=>$zip_code,
':last_modified_by'=>$last_modified_by,
':last_modified_date'=>$last_modified_date,
':bitactive'=>$bitactive
)
);
header("Location: http://173.254.127.52/~avenuet7/supporttables.php?msg=1");
}
}
$row is undefined. It should be $result:
$result = $statement->fetch(PDO::FETCH_ASSOC); // you declared `$result` not `$row`
And why not use prepared statements all through out:
$user_exists = "SELECT * FROM lu_agency WHERE agency_id =". $support_broker_id; // still directly injecting?
Final look:
$support_broker_id = $_GET['id'];
$user_exists = "SELECT * FROM lu_agency WHERE agency_id = :support_broker_id ";
// not `$sql` use `$user_exists`!
$statement = $conn->prepare($user_exists);
$statement->bindParam(':support_broker_id', $support_broker_id);
$statement->execute();
$count = $statement->rowCount();
if($count > 0) {
$result = $statement->fetch(PDO::FETCH_ASSOC);
$sqlupdate = "
UPDATE lu_agency SET
name = :name,
address_line1 = :address_line1,
address_line2 = :address_line2,
city = :city,
state = :state,
zip_code = :zip_code,
last_modified_by = :last_modified_by,
last_modified_date = :last_modified_date,
bitactive = :bitactive
WHERE agency_id = :support_broker_id
";
$preparedstmt = $conn->prepare($sqlupdate);
$preparedstmt->execute(
array(
':name' => $result['name'],
':address_line1' => $result['address_line1'],
':address_line2' => $result['address_line2'],
':city' => $result['city'],
':state' => $result['state'],
':zip_code' => $result['zip_code'],
':last_modified_by' => $result['last_modified_by'],
':last_modified_date' => $result['last_modified_date'],
':bitactive' => $result['bitactive'],
':support_broker_id' => $support_broker_id,
));
header("Location: http://173.254.127.52/~avenuet7/supporttables.php?msg=1");
}
Sidenote: Always add this after making a connection:
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
So my problem is that I want to add multiple members in one team, but I cannot seem to figure out how or whether if it is even possible to do so. Here is my code for you to get my question.
<?php
$tname = $_POST['tname'];
$maxnum = $_POST['maxnum'];
$host = "localhost";
$sqluname = "root";
$sqlpass = "";
$db = "teams";
$tablename = "team info";
$mem1 = $_POST['mem1'];
$mem2 = $_POST['mem2'];
$mem3 = $_POST['mem3'];
$mem4 = $_POST['mem4'];
$connect = mysqli_connect("$host","$sqluname","$sqlpass","$db") ;
if(mysqli_connect_errno())
{
echo "Problem". mysqli_connect_error();
}
$sql = "INSERT INTO teaminfo (TeamName,MaxNum,Members)
VALUES
('$tname','$maxnum','$mem1')";
/* Inside Members, I would like to add more than just $mem1, like $mem2, $mem3, $mem4.
*/
if(!mysqli_query($connect,$sql)){
die('Error: ' .mysqli_error($connect));
}
echo "Team is added";
mysqli_close($connect);
header("location: TeamDummyClient.html");
?>
$sql = "INSERT INTO teaminfo (TeamName,MaxNum,Members) VALUES";
$sql .= "('$tname','$maxnum','$mem1'),";
$sql .= "('$tname','$maxnum','$mem2'),";
$sql .= "('$tname','$maxnum','$mem3'),";
$sql .= "('$tname','$maxnum','$mem4')";
You should be escaping the strings before you insert their values to prevent SQL injections. Here's an example for one of the rows:
$sql .= "(
'" . mysqli_real_escape_string($tname) . "',
'" . mysqli_real_escape_string($maxnum) . "',
'" . mysqli_real_escape_string($mem1) . "'
),";