PHP - Trying To Insert Records Selected From A Table Into A Newly Created Rpg File
I am very new to PHP and haven't wriiten an update program except in the class I took about 4 years ago using MYSQL.
The company I work for is using PDO so I am having a little bit of a learning curve.
I have a table with a checkbox at the end and I want to insert the records from the table into a new file I created called
OPPSHEDT
SHEDORD Order Number 14 Char
SHEDBORD BackOrder Number 2 Char
SHEDPKD Picked Cases 9,0 Decimal
SHEDSHP Shipped Cases 9,0 Decimal
I'm just not sure how to write the update program to read the array of records and run through the loop and insert the items checked. I saw some other examples on here and all over the internet but they were using mysql. I have a copy of the code to create my table below.
I'd appreciate the help if you can.
Thanks.
ShipEstimate.php 6.41KB
4 downloads
Similar TutorialsHi, I have contact form in my website project. Users fill First name ,Last Name ,Email etc information. I do not want to create database and table to store this information. I want to store this information in XML file. When user will add information then information will be added in XML file. Any solution for this ? - Thanks Hi everybody. I use flash 8 and actionscript 2.0. I am trying to create a small program that needs communication between php / HTML and flash. I have found ( after much frustration and having wasted days on this ) that no matter what - if i make a change to my program and re publish the HTMl AND SWF files after I have deleted the old HTML and swf files , even then when i run the NEW PUBLISHED html / php file, the movie that runs is the old one. I have tried all that I know, like checking paths and stuff to ensure that everything is ok. I am unable to shed the chached old swf file and so the old movie continues to run. Is there any one who has encountered anything like this? Please help me. This is driving me nuts. Thanks loads in anticipation of a reply from the nerds on this ! Yes, I am going to be one of those guys today. I have never done XML anything, besides past 2-3 hours or so, and I am getting frustrated. I have learned how to create simple XML files and save them. I am however having hard time figuring out how to create and XML file when trying to access an table from databse. I am looking to export from "registered_users" table all "registrations" and include "first_name", "last_name" and "age"
Sample:
<registered_users>
<registration>
<first_name>Bob</first_name>
<last_name>Smith</last_name>
<age>36</age>
</registration>
<registration>
<first_name>Jack</first_name>
<last_name>Miller</last_name>
<age>45</age>
</registration>
</registered_users>
It would be nice if the file would be saved as spearate "all_users.xml"
Any help would be appreciated
I have got myself a bit confused whilst trying to create an 'update selected records' page. In memberlist.php, a set of records is shown, each with a checkbox. When the user clicks on 'Update Selected' it opens up membermultiupdate.php. I cannot get this page to recognise which id's have been passed and put them in an array so only the checked records are shown. The page in question is at http://www.margate-fc.com/memberlist.php. When it opens membermultiupdate.php, there are currently 2 errors.... Code: [Select] Warning: implode() [function.implode]: Invalid arguments passed in /homepages/46/d98455693/htdocs/membermultiupdate.php on line 11 which refers to $update = implode ("','", mysql_real_escape_string ($_POST['checkbox'])) Code: [Select] Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /homepages/46/d98455693/htdocs/membermultiupdate.php on line 44which is while ($rowmembers = mysql_fetch_array($members)) I have also tried mysql_fetch_assoc there too. I may be miles out or I may be missing something simple but I have tried for hours now to get my head around this and have not even got to the point where I can see if the actual update side works! Any suggestions would be greatly received and I have put the relevant code from both pages below. Thanks in advance for any help or suggestions Steve memberlist.php The query to get all rows $members = mysql_query(" SELECT * FROM users"); The submit form with checkboxes <form name="form1" method="post" action="membermultiupdate.php"> <?php while ($rowmembers = mysql_fetch_assoc($members)) {echo ' <tr> <td><input type="hidden" name="id[]" value="'.$rowmembers['id'].'" />'.$rowmembers['id'].'</td> <td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="'.$rowmembers['id'].'"></td></td> <td>'.$rowmembers['id'].'</td> <td>'.$rowmembers['username'].'</td> <td>'.$rowmembers['first_name'].'</td> <td>'.$rowmembers['last_name'].'</td> <td>'.$rowmembers['email'].'</td> '; if ($rowmembers['active'] == 1) {echo '<td> YES </td>';} else {echo ' <td>NO </td>';} echo ' <td><a href="memberedit.php?member='.$rowmembers['id'].'"><img src="http://icons.iconarchive.com/icons/custom-icon-design/office/256/edit-icon.png" width="15" height="15" /></a> <img src="http://icons.iconarchive.com/icons/custom-icon-design/office/256/delete-icon.png" width="15" height="15" /></td> </tr>';} ?> <tr> <td colspan="4" align="center"><input type="submit" name="submit" value="Update Selected"></td> </tr> </form> membmultiupdate.php The code bit to try to show all checked rows if (isset ($_POST['submit'])) { if (is_array ($_POST['checkbox'])) { $update = implode ("','", mysql_real_escape_string ($_POST['id'])); $members = mysql_query("SELECT * FROM users WHERE id IN (".$update.") "); } } The form to show all of the checked rows <form name="form1" method="post" action=""> <?php while ($rowmembers = mysql_fetch_array($members)) {echo ' <tr> <td width="200px" align="right" style="font-weight:bold"> <label for="name">Username:</label> </td> <td width="200px" > <input type="text" name="name" value="'.$rowmembers['username'].'" /><br> </td> </tr> <tr> <td width="200px" align="right" style="font-weight:bold"> <label for="name">First Name:</label> </td> <td width="200px" > <input type="text" name="first_name" value="'.$rowmembers['first_name'].'" /><br> </td> </tr> <tr> <td width="200px" align="right" style="font-weight:bold"> <label for="name">Last Name:</label> </td> <td width="200px" > <input type="text" name="last_name" value="'.$rowmembers['last_name'].'" /><br> </td> </tr> <tr> <td width="200px" align="right" style="font-weight:bold"> <label for="name">Email:</label> </td> <td width="200px" > <input type="text" name="email" value="'.$rowmembers['email'].'" /><br> </td> </tr>' ;} ?> <tr> <td colspan="4" align="center"><input type="submit" name="update" value="update"></td> </tr> </form> The code to update the rows from the above form and the return to memberlist.php if($update) { foreach($_POST['id'] as $id) { $sql1=" UPDATE users SET username='".$_POST["name".$id]."' , first_name='".$_POST["first_name".$id]."' , last_name='".$_POST["last_name".$id]."' , email='".$_POST["email".$id]."' , ONOFF='".$_POST["ONOFF".$id]."' WHERE id='".$id."'"; $result1=mysql_query($sql1); } } if($result1){ header("location:memberlist.php"); } Hello, i have this php code. Its for sms insertion of links in to table <table border="1"> <?PHP $db_user = 'user'; $db_pass = 'pass'; $db_name = 'name'; $db_host = 'localhost'; if(mysql_connect($db_host,$db_user,$db_pass)) { mysql_select_db($db_name); mysql_query("CREATE TABLE IF NOT EXISTS smsads(id bigint unsigned primary key auto_increment, link varchar(255), fromnum varchar(60))"); $res = mysql_query("SELECT * FROM smsads ORDER BY id DESC LIMIT 10"); while($row = mysql_fetch_object($res)) { $http_link = $row->link; if(strstr($http_link, 'http') === FALSE) $http_link = 'http://'.$http_link; echo "<tr><td><a href=\"{$http_link}\" target=\"_blank\">{$row->link}</a></td></tr>"; } } ?> </table> The problem is that i use tpl files for the visual part and all my other tables are in tpl. How can i insert the table above in my tpl file, whitout loosing its functions? Hi all! I have a page that is used to manage multiple user requests. The problem that I am having, is that it is supposed to send an email to the reporter any time their request is updated from this page. This works fine as long as I am doing one at a time, but when I try to update multiple records it doesn't send the emails. (All other functionality is working fine though.) Here is a summary of what I have so far: The form field to pass the users' emails Code: [Select] <input type="hidden" name="user_email<?= $arrValues["mantis_bug_id"] ?>" id="user_email<?= $arrValues["mantis_bug_id"] ?>" value="<?=$arrValues["email"]?>" /> This gets passed, along with the rest, to an update case on the same page, where I use a foreach() to process the multiple records: Code: [Select] foreach($_POST['chkResult'] as $intBugID){ . . . . . if (isset($_POST["user_email$intBugID"])){ $emailTo = $_POST["user_email$intBugID"]; $emailSubject = "Mantis issue $intBugID has been modified."; $emailContent = "Mantis issue $intBugID has recently been modified. Please review the changes that have been made here [link]</a><br />If you have any questions or concerns regarding this issue, please contact Mike or Matt.<br />Thank you,<br />The IT Team."; include_once("{$_SERVER['DOCUMENT_ROOT']}/includes/Email.class.php"); $email = new Email(); $email->ContentType = "text/html"; $email->From = "me@myemail.org"; $email->FromName = "MOPS Mantis Bugtracker"; $email->to($emailTo); $email->bcc('me@myemail.org'); $email->subject($emailSubject); $email->setBody($emailContent); $email->send; echo 'User: ' . $emailTo. '<br />'; echo "User Email: " . $emailTo. "<br /><br />"; } }//end foreach As I said, this all works fine when I'm processing one issue at a time, but not when doing multiples. All other actions in the foreach() are also working. You'll notice that I'm echoing the username and email at the end for debugging purposes. The interesting thing is, that will output all of the correct usernames and emails for each user, it's just that the $email->send; just isn't working. Needless to say, this has become quite a frustrating bug to fix. Any help at all is much appreciated! Thanks, Mike my name is fairooj and ama new to php and jquery. i have a proplam. i want your help.
<script type="text/javascript"> var count = 0; $(function(){ $('p#add_field').click(function(){ count += 1; $('#container').append( '<strong>Link #' + count + '</strong><br />' + '<input id="field_' + count + '" name="fields[]' + '" type="text" />' + '<input id="code_' + count + '" name="code[]' + '" type="text" /><br />' ); }); }); </script> I created this database Code: [Select] <?php $mysqli = mysqli_connect('localhost', 'admin', 'jce123', 'php_class'); if(mysqli_connect_errno()) { printf("connection failed: %s\n", mysqli_connect_error()); exit(); }else{ $q = mysqli_query($mysqli, "DROP TABLE IF EXISTS airline_survey"); if($q){echo "deleted the table airline_survey....<br>";} else{echo "damm... ".mysqli_error($mysqli);} $sql = "CREATE TABLE airline_survey ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, staff CHAR(10) NOT NULL, luggage CHAR(10) NOT NULL, seating CHAR(10) NOT NULL, clean CHAR(10) NOT NULL, noise CHAR(10) NOT NULL )"; $res = mysqli_query($mysqli, $sql); if($res === TRUE) { echo "table created"; } else { printf("Could not create table: %s\n", mysqli_error($mysqli)); } mysqli_close($mysqli); } ?> When I look at it it looks fine. I have a form that sends data to this script: Code: [Select] <?php $con = mysql_connect('localhost', 'admin', 'abc123'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("php_class", $con); foreach ($_POST as $key => $value) { $staff = ""; $luggage = ""; $seating = ""; $clean = ""; $noise = ""; switch($key){ case "staff": $staff = $value; break; case "luggage": $luggage = $value; break; case "seating": $seating = $value; break; case "clean": $clean = $value; break; case "noise": $noise = $value; break; default: echo "we must be in the twilight zone"; } echo $staff."<br>"; [color=red] mysql_query("INSERT INTO airline_survey (staff, luggage, seating, clean, noise) VALUES ($staff, $luggage, $seating, $clean, $noise)");[/color] } ?> as you can see right before the insert query I test one of the variables to see if it has the string I'm expecting and it does. The problem is the script runs without giving me an error message but the data never gets inserted into the table. When submitting the form, the records are sometimes inserted and sometimes not. I receive no errors stating what the problem is. Code: [Select] <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO customer_tbl (customer_first_name, customer_last_name, customer_company, customer_ac, customer_phone, customer_fax_ac, customer_fax_phone, customer_email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['customer_first_name'], "text"), GetSQLValueString($_POST['customer_last_name'], "text"), GetSQLValueString($_POST['customer_company'], "text"), GetSQLValueString($_POST['customer_ac'], "text"), GetSQLValueString($_POST['customer_phone'], "text"), GetSQLValueString($_POST['customer_fax_ac'], "text"), GetSQLValueString($_POST['customer_fax_phone'], "text"), GetSQLValueString($_POST['customer_email'], "text")); $customer_id = false; if(mysql_query($insertSQL, $connCid)) $customer_id = mysql_insert_id(); else echo "There was an error."; } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO quote_request_tbl (customer_id, quote_trans_date, quote_from_company, quote_from_address, quote_from_city, quote_from_state, quote_from_zip, quote_to_company, quote_to_address, quote_to_city, quote_to_state, quote_to_zip, quote_comments) VALUES ('$customer_id', %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['quote_trans_date'], "text"), GetSQLValueString($_POST['quote_from_company'], "text"), GetSQLValueString($_POST['quote_from_address'], "text"), GetSQLValueString($_POST['quote_from_city'], "text"), GetSQLValueString($_POST['quote_from_state'], "text"), GetSQLValueString($_POST['quote_from_zip'], "text"), GetSQLValueString($_POST['quote_to_company'], "text"), GetSQLValueString($_POST['quote_to_address'], "text"), GetSQLValueString($_POST['quote_to_city'], "text"), GetSQLValueString($_POST['quote_to_state'], "text"), GetSQLValueString($_POST['quote_to_zip'], "text"), GetSQLValueString($_POST['quote_comments'], "text")); $quote_id = false; if(mysql_query($insertSQL, $connCid)) $quote_id = mysql_insert_id(); else echo "There was an error."; } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1") && (isset($quote_id))) { $insertSQL = sprintf("INSERT INTO building_tbl (quote_id, building_quantity, building_width, building_length, building_height, building_overhang, slope_id, building_type_id, manufacture_id, foundation_id) VALUES ('$quote_id', %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['building_quantity1'], "int"), GetSQLValueString($_POST['building_width1'], "int"), GetSQLValueString($_POST['building_length1'], "int"), GetSQLValueString($_POST['building_height1'], "int"), GetSQLValueString($_POST['building_overhang1'], "int"), GetSQLValueString($_POST['slope_id1'], "int"), GetSQLValueString($_POST['building_type_id1'], "int"), GetSQLValueString($_POST['manufacture_id1'], "int"), GetSQLValueString($_POST['foundation_id1'], "int"); mysql_select_db($database_connCid, $connCid); $Result1 = mysql_query($insertSQL, $connCid) or die(mysql_error()); header('Location: index.php?view=article&id=7'); } mysql_select_db($database_connCid, $connCid); $query_rsSlope = "SELECT * FROM slope_tbl ORDER BY slope_id ASC"; $rsSlope = mysql_query($query_rsSlope, $connCid) or die(mysql_error()); $row_rsSlope = mysql_fetch_assoc($rsSlope); $totalRows_rsSlope = mysql_num_rows($rsSlope); $query_rsSlope = "SELECT * FROM slope_tbl ORDER BY slope_id ASC"; $rsSlope = mysql_query($query_rsSlope, $connCid) or die(mysql_error()); $row_rsSlope = mysql_fetch_assoc($rsSlope); $totalRows_rsSlope = mysql_num_rows($rsSlope); mysql_select_db($database_connCid, $connCid); $query_rsBuildingType = "SELECT * FROM building_type_tbl ORDER BY building_type_id ASC"; $rsBuildingType = mysql_query($query_rsBuildingType, $connCid) or die(mysql_error()); $row_rsBuildingType = mysql_fetch_assoc($rsBuildingType); $totalRows_rsBuildingType = mysql_num_rows($rsBuildingType); mysql_select_db($database_connCid, $connCid); $query_rsManufacture = "SELECT * FROM manufacture_tbl ORDER BY manufacture_name ASC"; $rsManufacture = mysql_query($query_rsManufacture, $connCid) or die(mysql_error()); $row_rsManufacture = mysql_fetch_assoc($rsManufacture); $totalRows_rsManufacture = mysql_num_rows($rsManufacture); mysql_select_db($database_connCid, $connCid); $query_rsFoundation = "SELECT * FROM foundation_tbl ORDER BY foundation_name ASC"; $rsFoundation = mysql_query($query_rsFoundation, $connCid) or die(mysql_error()); $row_rsFoundation = mysql_fetch_assoc($rsFoundation); $totalRows_rsFoundation = mysql_num_rows($rsFoundation); ?> I belve the problem is in this part of the code: if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1") && (isset($quote_id))) Many thanks in advance. Hi,I'm hoping someone can help me:). When I add foreign keys to the database in MySQL I CAN change the primary key field and the corresponding indexed field will automatically change giving me the same value which is exactly what i want. The issue is when I try to insert the values using my php code i get the 'cannot update child error'. I have not selected a value for the unique_id field as I want it to inherit the value from the primary key. Here's my code as simplified as I could do it. <?php //this calls the class productupload and instantiates the function insert_form to insert values into the db. $product = new productUpload(); $product->insert_form();?> //This calls the insert_form function and inserts info into tables <?php class productUpload extends DatabaseObject{ protected static $table_name="itm_details"; protected static $db_fields =array('id','unique_id','itm_cat','itm_make','itm_model','itm_desc','itm_cond','itm_date_from','itm_date_to','itm_add_date'); public $id; public $unique_id; public $itm_cat; public $itm_make; public $itm_model; public $itm_desc; public $itm_cond; public $itm_date_from; public $itm_date_to; public $itm_add_date; Heres the function insert_form which grabs the form submitted data. Note I have not defined a value for $unique_id public function insert_form(){ global $database; //set the object attributes to the form the parameters if(isset($_POST['submit'])) { $result = array( $this->itm_cat =(!empty($_POST['itm_cat'])) ? trim($_POST['itm_cat']) : NULL, $this->itm_make =(!empty($_POST['itm_make'])) ? trim($_POST['itm_make']) : NULL, $this->itm_model = (!empty($_POST['itm_model'])) ? trim($_POST['itm_model']) : NULL, $this->itm_desc =(!empty($_POST['itm_desc'])) ? trim($_POST['itm_desc']) : NULL, $this->itm_cond =(!empty($_POST['itm_cond'])) ? trim($_POST['itm_cond']) : NULL, $this->itm_date_from =(!empty($_POST['itm_date_from'])) ? trim($_POST['itm_date_from']) : NULL, $this->itm_date_to =(!empty($_POST['itm_date_to'])) ? trim($_POST['itm_date_to']) : NULL, $this->itm_add_date = date("Y-m-d H:m:s")); //check date is numeric //if(is_numeric($_POST['itm_date_from'])) { //$this->itm_date_from = $_POST['itm_date_from']; //} //check date is numeric //if(is_numeric($_POST['itm_date_to'])) { //$this->itm_date_to = $_POST['itm_date_to']; //} if($result){ $result = $this->create(); } } } //here's the create function referred to above which sanitises the posted data and inserts it into the db. public function create() { global $database; $attributes = $this->sanitised_attributes(); $sql = "INSERT INTO ".self::$table_name."("; $sql .= join(", ", array_keys($attributes)); $sql .= ") VALUES ('"; $sql .= join("', '", array_values($attributes)); $sql .= "')"; if($database->query($sql)) { $this->id = $database->insert_id(); return true; } else { return false; } } Code: [Select] <?php require "db/config.php"; $fname = $_POST['fname']; $lname = $_POST['lname']; $country = $_POST['country']; $state = $_POST['state']; $city = $_POST['city']; $zcode = $_POST['zcode']; $address = $_POST['address']; $ppemail = $_POST['ppemail']; $pnumber = $_POST['pnumber']; $cemail = $_POST['cemail']; $url = $_POST['url']; $price = "$5.00"; $query = "INSERT INTO custpackage1000( id, FirstName, LastName, Country, State, City, ZipCode, Address, PayPalEmail, PhoneNumber, PrimaryEmail, WebsiteURL) VALUES ( '1', '$fname', '$lname', '$country', '$state', '$city', '$zcode', '$ppemail', '$pnumber', '$cemail', '$url')"; mysql_connect($host, $user, $pass) or die("<br /><br /><h1>Fatal error. Please contact support if this persists.</h1>"); mysql_select_db($dbname); mysql_query($query) or die ("could not open db".mysql_error()); sleep(2); ?> Why won't the code insert into my database upon submission of data? What am I doing wrong? Hi. Im searching for a way to enter multiple records at once to mysql databased on a date range. Lets say i want to insert from date 2010-11-23 to date 2010-11-25 a textbox with some info and the outcome could look in database like below. ---------------------------------------------------------- | ID | date | name | amount | ----------------------------------------------------------- | 1 | 2010-11-23 | Jhon | 1 | | 2 | 2010-11-24 | Jhon | 1 | | 2 | 2010-11-25 | Jhon | 1 | ----------------------------------------------------------- The reason i need the insertion to be like this is because if quering by month and by user to see vacation days then vacations that start in one month and end in another month can be summed by one month. If its in one record then it will pop up in both months. Help is really welcome. I need to reach Win server, scan shared folder and find out what is last created file name on this folder, and than copy this file to local folder. BUT main problem is smb, never used it before, and this is what i came up with, but no luck.
require_once('smbclient.php'); $latest = null; $smbc = new smbclient ('//10.1.1.10/Share/Address Verification/', 'domain\\username', 'password'); if ($handle = opendir($smbc)) { $latest = null; while (($cur = readdir($handle) !== false)) { if ($latest == null || filectime($cur) > filectime($latest)) { $latest = $cur; } } closedir($handle); } return $latest;please help, returns Warning: opendir() expects parameter 1 to be string Hello, We've been working on a page that allows users to create their own avatar to be displayed on their page. We can get the script working but the only way to show the image is to save it to a temp folder, we want to just save the string in the database and let the php show this wehen required here are the file http://test.digitaldemocracy.org.uk/test_avatar.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="author" content="John Munro, Democratise Ltd" /> <meta name="copyright" content="Democratise Ltd 2010" /> <meta name="description" content="Digital Democracy -" /> <meta name="keywords" content=" add here" /> <meta name="robots" content="index, follow" /> <meta name="revisit-after" content="1 week" /> <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5)" /> <link rel="SHORTCUT ICON" href="http://www.digitaldemocracy.co.uk/favicon.ico" /> <title>Digital Democracy -</title> <link href="css/site.css" rel="stylesheet" type="text/css" /> <link href="css/basic.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="avatars/avatar.css" type="text/css" /> <script type="text/javascript" src="avatars/avatar.js"></script> <style type="text/css"> /*<![CDATA[*/ <!-- body { background-image: url(images/background_paper.jpg); background-repeat: repeat; } --> /*]]>*/ </style> <script type="text/javascript"> //<![CDATA[ var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-15681567-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); //]]> </script> </head> <body> <div id="wrapper"> <div id="inner_wrapper"> <div class="header"> <div class="header_logo"> <img src="images/header_logo.png" width="190" height="55" alt="Digital Democracy" /> </div> <div class="header_link"> Make a<br/>proposal </div> <div class="header_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="header_link"> View<br/>proposal </div> <div class="header_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="header_link"> Vote on top<br/>proposal </div> <div class="header_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="header_link"> View<br/>results </div> <div class="header_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="header_link_single_line"> Profile </div> <div class="header_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="header_link_single_line"> More </div> <div id="header_search_bar"> <form action="Search" method="post"> <input name="Search" type="text" value="Search" size="15" /> <input name="Submit" type="button" value="Go" /> </form> </div> <div class="header_login"> <span class="header_login_text">Login / Register</span> </div> </div> <div id="info"> <div id="chosen_avatar"> <!--<p> avatar to be shown here when completed only - image shown below is thee to reference the saved code</p>--> <p><img src="<?php if (!empty($image)) { echo $filename; } else { echo 'http://test.digitaldemocracy.org.uk/avatar_creator.php?avatar[background]=bg_08&avatar[body]=body_01&avatar[head]=head_01&avatar[eyes]=blank&avatar[mouth]=blank&avatar[moustache]=blank&avatar[glasses]=blank&avatar[male_hair]=blank&avatar[female_hair]=blank';} ?>" title="Your chosen avatar (assembled as a PNG image)" alt="Your chosen avatar (PNG image)" /></p> <p>Your chosen avatar</p> </div> <form action="http://test.digitaldemocracy.org.uk/avatar_creator.php" method="get"> <div id="avatar_section"> <div id="avatar_stack"> <p> <img src="avatars/bg_01.png" alt="" /><input name="avatar[background]" type="radio" value="bg_01" checked="checked" /> <img src="avatars/bg_02.png" alt="" /><input name="avatar[background]" type="radio" value="bg_02" /> <img src="avatars/bg_03.png" alt="" /><input name="avatar[background]" type="radio" value="bg_03" /> <img src="avatars/bg_04.png" alt="" /><input name="avatar[background]" type="radio" value="bg_04" /> <img src="avatars/bg_05.png" alt="" /><input name="avatar[background]" type="radio" value="bg_05" /> <img src="avatars/bg_06.png" alt="" /><input name="avatar[background]" type="radio" value="bg_06" /> <img src="avatars/bg_07.png" alt="" /><input name="avatar[background]" type="radio" value="bg_07" /> <img src="avatars/bg_08.png" alt="" /><input name="avatar[background]" type="radio" value="bg_08" /> <img src="avatars/bg_09.png" alt="" /><input name="avatar[background]" type="radio" value="bg_09" /> </p> <p> <img src="avatars/body_01.png" alt="" /><input name="avatar[body]" type="radio" value="body_01" checked="checked" /> <img src="avatars/body_02.png" alt="" /><input name="avatar[body]" type="radio" value="body_02" /> <img src="avatars/body_03.png" alt="" /><input name="avatar[body]" type="radio" value="body_03" /> <img src="avatars/body_04.png" alt="" /><input name="avatar[body]" type="radio" value="body_04" /> <img src="avatars/body_05.png" alt="" /><input name="avatar[body]" type="radio" value="body_05" /> <img src="avatars/body_06.png" alt="" /><input name="avatar[body]" type="radio" value="body_06" /> <img src="avatars/body_07.png" alt="" /><input name="avatar[body]" type="radio" value="body_07" /> <img src="avatars/body_08.png" alt="" /><input name="avatar[body]" type="radio" value="body_08" /> </p> <p> <img src="avatars/head_01.png" alt="" /><input name="avatar[head]" type="radio" value="head_01" checked="checked" /> <img src="avatars/head_02.png" alt="" /><input name="avatar[head]" type="radio" value="head_02" /> <img src="avatars/head_03.png" alt="" /><input name="avatar[head]" type="radio" value="head_03" /> <img src="avatars/head_04.png" alt="" /><input name="avatar[head]" type="radio" value="head_04" /> <img src="avatars/head_05.png" alt="" /><input name="avatar[head]" type="radio" value="head_05" /> <img src="avatars/head_06.png" alt="" /><input name="avatar[head]" type="radio" value="head_06" /> <img src="avatars/head_07.png" alt="" /><input name="avatar[head]" type="radio" value="head_07" /> <img src="avatars/head_08.png" alt="" /><input name="avatar[head]" type="radio" value="head_08" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[eyes]" type="radio" value="blank" checked="checked" /> <img src="avatars/eyes_1.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_1" /> <img src="avatars/eyes_2.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_2" /> <img src="avatars/eyes_3.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_3" /> <img src="avatars/eyes_4.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_4" /> <img src="avatars/eyes_5.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_5" /> <img src="avatars/eyes_6.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_6" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[mouth]" type="radio" value="blank" checked="checked" /> <img src="avatars/mouth_1.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_1" /> <img src="avatars/mouth_2.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_2" /> <img src="avatars/mouth_3.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_3" /> <img src="avatars/mouth_4.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_4" /> <img src="avatars/mouth_5.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_5" /> <img src="avatars/mouth_6.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_6" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[moustache]" type="radio" value="blank" checked="checked" /> <img src="avatars/moustache_01.png" alt="" /><input name="avatar[moustache]" type="radio" value="moustache_01" /> <img src="avatars/moustache_02.png" alt="" /><input name="avatar[moustache]" type="radio" value="moustache_02" /> <img src="avatars/moustache_03.png" alt="" /><input name="avatar[moustache]" type="radio" value="moustache_03" /> <img src="avatars/moustache_04.png" alt="" /><input name="avatar[moustache]" type="radio" value="moustache_04" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[glasses]" type="radio" value="blank" checked="checked" /> <img src="avatars/glasses_01.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_01" /> <img src="avatars/glasses_02.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_02" /> <img src="avatars/glasses_03.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_03" /> <img src="avatars/glasses_04.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_04" /> <img src="avatars/glasses_05.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_05" /> <img src="avatars/glasses_06.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_06" /> <img src="avatars/glasses_07.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_07" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[hair 1]" type="radio" value="blank" checked="checked" /> <img src="avatars/m_hair_01.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_01" /> <img src="avatars/m_hair_02.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_02" /> <img src="avatars/m_hair_03.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_03" /> <img src="avatars/m_hair_04.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_04" /> <img src="avatars/m_hair_05.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_05" /> <img src="avatars/m_hair_06.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_06" /> <img src="avatars/m_hair_07.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_07" /> <img src="avatars/m_hair_08.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_08" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[hair 2]" type="radio" value="blank" checked="checked" /> <img src="avatars/f_hair_01.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_01" /> <img src="avatars/f_hair_02.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_02" /> <img src="avatars/f_hair_03.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_03" /> <img src="avatars/f_hair_04.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_04" /> <img src="avatars/f_hair_05.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_05" /> <img src="avatars/f_hair_06.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_06" /> <img src="avatars/f_hair_07.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_07" /> <img src="avatars/f_hair_08.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_08" /> </p> </div> </div> <p> </p> <p id="submit" > <input type="submit" value="Click here to save your personalised Avatar" /> </p> </form> <div id="hidden_spacer"> <p> </p> </div> </div> </div> </div> <div class="footer"> <div class="footer_content"> <div id="footer_democratise"> © Democratise Ltd </div> <div class="footer_link_single_line"> About us </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> Contact </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> Blog </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> Help </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> Privacy </div> </div> </div> </body> </html> And the file that runs the php and creates the images is <?php # form inputs in the correct stacking order from bottom to top $form_fields = array('background', 'body', 'head', 'eyes', 'mouth', 'moustache', 'glasses', 'hair 1', 'hair 2'); ob_start(); if(!isset($_GET['avatar'])) die; validate_inputs($form_fields); $filename = create_avatar($form_fields); //ob_end_clean(); //echo "hello"; //$image = output_image(ob_get_clean()); $image_output = ob_get_contents(); //ob_end_clean(); //echo $image; //$image = ob_get_contents(); //$image="data:image/png;base64, base64_encode($image)"; $image = 'test.digitaldemocracy.org.uk' . $_SERVER['REQUEST_URI']; //$image = $_SERVER['REQUEST_URI']; //echo $image; function validate_inputs($inputs) { foreach($inputs as $item) { if((preg_match('@(\.|/)@', $_GET['avatar'][$item])) or (!is_file('avatars/'.$_GET['avatar'][$item].'.png'))) { die(); } } } function create_avatar($inputs) { while($inputs) { $layer = @imagecreatefrompng('avatars/'. ($file = $_GET['avatar'][array_shift($inputs)]). '.png') or die('I could not open the avatars/'.$file); $layerWidth = imageSX($layer); $layerHeight = imageSY($layer); if(!isset($slate)) { $slate = @imagecreatetruecolor($layerWidth, $layerHeight); } @imagecopy($slate, $layer, 0, 0, 0, 0, $layerWidth, $layerHeight); @imagedestroy($layer); } imagetruecolortopalette ($slate, false, 256); //header('Content-Type: image/png'); $filename = 'temp'. rand(1,50) . '.png'; imagepng($slate, $filename); //imagepng($slate); imagedestroy($slate); return $filename; } function output_image($image) { $hash = md5($image); if(isset($_SERVER['HTTP_IF_NONE_MATCH'])){ if($hash == trim($_SERVER['HTTP_IF_NONE_MATCH'], '"')){ header("HTTP/1.x 304 Not Modified"); header('Etag: "'.$hash.'"'); die(); } } //header('Etag: "'.$hash.'"'); //header('Content-Type: image/png'); //imagepng($image); //echo $image; //return $image; } //header ("Location:test_avatar.php?image=$image"); include 'test_avatar.php'; ?> If anybody can help us it would be very appreciated Thanks John Munro Democratise.org I am using apache web server on linux. I am using php for coding. My php code is not able to read the files from /var/tmp folder. If apache itself creates some files in /var/tmp folder then php code is able to read it. Why this permission denied issues are there though full access permissions are given to each file?
I'm trying to create a table form that pulls in "Extra" choices from a table and allows users to select a number of days and number of guests for each choice. I started creating it a a checkbox field but am thinking just using the name as a label and setting days and guests to default "0" might be a better bet. Guidance from someone more experienced with this? Also, how do I store the submission (db structure - in the "reservations" table, another?). I'm new to this and feel kind of lost with this challenge. //Extras $query = "select * from extras"; $data = mysqli_query($db, $query); $num = mysqli_num_rows($data); echo "<p><b>Extras:</b></p>"; for ($i=0; $i<$num; $i++) { $row = mysqli_fetch_array($data); $extra_id = $row['extra_id']; $extra_name = $row['extra_name']; $extra_rate = $row['extra_rate']; echo "<p><input type='checkbox' name='extra_id[]' value = '$extra_id' />$extra_name <i>\$$extra_rate</i> Num Days<input type='text' name='d$extra_id' /> Num Guests<input type='text' name='g$extra_id' />"; } Hi all, I am having difficulty getting my UPDATE script to work. Basically the info is being pulled from a form and then being UPDATED, but it doesn't actually update and I am presented with no errors. It finds the record correctly and displays in the fields in the form as it should, just no update! Any ideas? Thanks in advance... Code: [Select] <?php error_reporting (E_ALL ^ E_NOTICE); $usr = "fdgdg"; $pwd = "dgdg"; $db = "dgdg"; $host = "dgdg.ddg.dg.50dgdg /***********************Get Record***********************/ $ref = (!empty($_GET['ref']))?trim($_GET['ref']):""; # connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid){ echo("ERROR: " . mysql_error() . "\n"); } $db_selected = mysql_select_db(database, $cid); $query = sprintf("SELECT * FROM fleet where fleetref like '%s' LIMIT 1","%".mysql_real_escape_string($ref)."%"); $result = mysql_query($query) or die($query."<br>".mysql_error()); $record = mysql_fetch_assoc($result); if(mysql_num_rows($result) > 0) { echo "<strong>Updating fleet vehicle</strong>"; $fleetref=$record["ref"]; $fleetmake=$record["fleetmake"]; $fleetmodel=$record["fleetmodel"]; $fleetberth=$record["fleetberth"]; $fleetyear=$record["fleetyear"]; $fleetlength=$record["fleetlength"]; $fleetchassis=$record["fleetchassis"]; $fleetengine=$record["fleetengine"]; $fleetlayout=$record["fleetlayout"]; $fleettype=$record["fleettype"]; $fleetcomments=$record["fleetcomments"]; $pricelow=$record["pricelow"]; $pricemid=$record["pricemid"]; $pricehigh=$record["pricehigh"]; $fleetof=$record["fleetof"]; }else{ echo "<div id=\"pages\"><strong>Record not found</strong> - Edit Directory</div>"; $fleetmake=""; $fleetmodel=""; $fleetberth=""; $fleetyear=""; $fleetlength=""; $fleetchassis=""; $fleetengine=""; $fleetlayout=""; $fleettype=""; $fleetcomments=""; $pricelow=""; $pricemid=""; $pricehigh=""; $fleetof=$record["fleetof"]; } if ($fleetof == $account) { /***********************Save Record***********************/ # this is processed when the form is submitted # back on to this page (POST METHOD) if (isset($_POST['submit'])){ $fleetmake=$_POST["fleetmake"]; $fleetmodel=$_POST["fleetmodel"]; $fleetberth=$_POST["fleetberth"]; $fleetyear=$_POST["fleetyear"]; $fleetchassis=$_POST["fleetchassis"]; $fleetengine=$_POST["fleetengine"]; $fleetlayout=$_POST["fleetlayout"]; $fleetlength=$_POST["fleetlength"]; $fleettype=$_POST["fleettype"]; $fleetcomments=$_POST["fleetcomments"]; $pricelow=$_POST["pricelow"]; $pricemid=$_POST["pricemid"]; $pricehigh=$_POST["pricehigh"]; # setup SQL statement $query = sprintf("UPDATE `fleet` SET `fleetmake` = '%s',`fleetmodel` = '%s',`fleetberth` = '%s',`fleetyear` = '%s',`fleetchassis` = '%s',`fleetengine` = '%s',`fleetlayout` = '%s',`fleetlength` = '%s',`fleettype` = '%s',`fleetcomments` = '%s',`pricelow` = '%s',`pricemid` = '%s',`pricehigh` = '%s' WHERE `fleetref` ='%s' LIMIT 1", mysql_real_escape_string($fleetmake),mysql_real_escape_string($fleetmodel),mysql_real_escape_string($fleetberth),mysql_real_escape_string($fleetyear),mysql_real_escape_string($fleetchassis),mysql_real_escape_string($fleetengine),mysql_real_escape_string($fleetlayout),mysql_real_escape_string($fleetlength),mysql_real_escape_string($fleettype),mysql_real_escape_string($fleetcomments),mysql_real_escape_string($pricelow),mysql_real_escape_string($pricemid),mysql_real_escape_string($pricehigh),mysql_real_escape_string($fleetref)); #execute SQL statement $result = mysql_db_query($db,$query,$cid) or die($query."<br>".mysql_error()); # check for error if (!$result){ echo("ERROR: " . mysql_error() . "\n$SQL\n"); } echo "<P>Fleet vehicle updated</P>\n"; } } else {echo "Sorry, you are not authorised to edit this vehicle, please contact the system administrator for further help.";} ?> I'm sorry to be back so soon, but I'm up against another mystery. I'm using the code below to enter a bunch of css data from a spreadsheet into a mysql table. I think the data file is OK. The array created by the script checks out with print_r. (There are many more records than shown. I truncated it to save space.) The problem is that I get this error regarding my sql statement, not the data or anything else: Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'check, name, phone, email, entry_fee, print_fee, image_name, description, med...' at line 1 in /Users/studio/Sites/BannerProject/b-as/_test_site/csv_to_array.php:242 Stack trace: #0 /Users/studio/Sites/BannerProject/b-as/_test_site/csv_to_array.php(242): PDO->prepare('INSERT INTO tbl...') #1 {main} thrown in /Users/studio/Sites/BannerProject/b-as/_test_site/csv_to_array.php on line 242 I've typed it in a dozen times to make sure there are no errors and keep getting the same error. I tried running a test file and gradually increasing the number of placeholders and at some point I always end up getting the same error, I can delete the most recent addition and it works again. Then I can add another placeholder exactly as before and it works the second time. It feels like a ghost in the machine. Any idea what I am doing wrong? An I typing something I don't see? <?php require '__classes/Db.php'; $csvData = '1,FALSE,Carol Lettko,,,TRUE,FALSE,Carol_Lettko-DSC_3022.jpg,Baby Herons/Brickyard,photo,,, ,,,925-285-0320,cjl164@aol.com,,,Carol_Lettko-DSC_0164.JPG,Heron/Brickyard,photo,,, ,,,,,,,Carol_Lettko-IMG_5723.jpg,Kayaker/Brickyard,photo,,, ,,,,,,,,,,,, 2,FALSE,Louise Williams,,,TRUE,FALSE,Louise_Williams-BirdsOfAFeatherAOPR.jpg,Alligator with Words,Book Excerpt,,, ,,,510-232-9547,lkw@louisekwilliams.com,,,Louise_Williams-Hope-TheFairyChickenAOPR.jpg,Hope The Fairy Chicken,,,, ,,,The d exatrfrfvct/.*tygrvurr,,,,,,,,, ,,,,,,,,,,,, 3,TRUE,Dorothy Leeland,,lelanddorothy@gmail.com,TRUE,FALSE,DJ_Lee-bridge at dusk 700px width.jpg,Bridge,photo,,, ,,,,,,,DJ_Lee-friends 700px width.jpg,Friends,photo,,, ,,,,,,,DJ_Lee-hybiscus 700 px wide.jpg,Hibiscus,photo,,, ,,,,,,,,,,,, 4,FALSE,Rita Gardner,,,TRUE,FALSE,Rita_Gardner-Explosion - Gardner photo.JPG,Explosion,photo,,, ,,,,tropicrita@msn.com,,,Rita_Gardner-Ferry Point tables and chair - Gardner.JPG,Ferry Point Tables,photo,, , ,,,,,,,Rita_Gardner-Forks - Gardner photo.JPG,Forks,photo,,, ,,,,,,,,,,,, '; $lines = explode(PHP_EOL, $csvData); $array1 = array(); foreach ($lines as $line) { $array1[] = str_getcsv($line); } $stmt = $pdo->prepare("INSERT INTO tbl_person_data (number, check, name, phone, email, entry_fee, print_fee, image_name, description, medium, select, orient, site) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)"); foreach ($array1 as $row) { $stmt->execute('$row'); } echo '<pre>'; print_r($array1); echo '</pre>'; ?>
Hi all. I built an online finance tracking thingy for myself and I got it to work using the following database table and PHP code. I didn't write the PHP code, rather, I edited it to suit my needs. It works great for my needs. I have a way to enter records and view the last 180 records in a table. The thing is, while viewing the table, I would lke to be able to edit and delete records. I don't know enough to be able to do this. Can it be done? I realize my PHP code would probably, for the most part, be totally different. Thanks for any help with this. Here is my DB table structu Code: [Select] DROP TABLE IF EXISTS `money`; CREATE TABLE IF NOT EXISTS `money` ( `id` int(5) NOT NULL AUTO_INCREMENT, `date` date NOT NULL, `type` varchar(18) NOT NULL, `checking` decimal(5,2) NOT NULL DEFAULT '0.00', `cash` decimal(5,2) NOT NULL DEFAULT '0.00', `description` varchar(25) NOT NULL, `who` varchar(25) NOT NULL, `note` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; And here is the PHP: Code: [Select] <?php $result = mysql_query ('SELECT date, type, checking, cash, who, description, note' . ' FROM money' . ' ORDER BY date DESC LIMIT 0,180') or die(mysql_error()); echo "<table border='1' cellpadding='5'>"; echo "<tr><th>Date</th><th>Type</th><th>Checking</th><th>Cash</th><th>Who?</th><th>Description</th><th>Note</th></tr>"; while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['date']; echo "</td><td>"; echo $row['type']; echo "</td><td>"; echo $row['checking']; echo "</td><td>"; echo $row['cash']; echo "</td><td>"; echo $row['who']; echo "</td><td>"; echo $row['description']; echo "</td><td>"; echo $row['note']; echo "</td></tr>"; } echo "</table>"; ?> Hi I'm using this code to insert multiple records. The code executes but nothing is entered into my database. This usually happens when there's a mismatch in data types.
How do I ensure that description goes in as text which in sql is wrapped in single quotes, but also make sure the other variables go in as numeric.
// an array items to insert $array = array( 'theid' => $theid, 'descr' => $descr, 'costperunit' => $costperunit, 'quantity' => $quantity, 'costperlot' => $costperlot ); // begin the sql statement $sql1 = "INSERT INTO descriptions (jobid, description, costperunit, quantity, costperlot) VALUES "; $it = new ArrayIterator( $array ); // a new caching iterator gives us access to hasNext() $cit = new CachingIterator( $it ); // loop over the array foreach ( $cit as $value ) { // add to query $sql1 .= "('".$cit->key()."','" .$cit->current()."')"; if( $cit->hasNext() ) { $sql1 .= ","; } } |