PHP - Storing Multiple Static Data Into Database
Hello,
I have a table with these columns (database)
table.JPG 34.95KB
0 downloads
and i have a static form through which user define the installments. Static 24 input boxes are there like this
<form name="installment" method="post" action="" enctype="multipart/form-data" onsubmit="return validate()"> <table id="dt_hScroll" class="table table-striped"> <thead> <tr> <th>SL No.</th> <th>Amount</th> <th>Due Date</th> </tr> <tr> <td> 1. </td> <td> <input type="text" name="installment1" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date1" class="tcal span4" value="<?php //echo date("Y-m-d"); ?>" /> </td> </tr> <tr> <td> 2. </td> <td> <input type="text" name="installment2" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date2" class="tcal span4" /> </td> </tr> <tr> <td> 3. </td> <td> <input type="text" name="installment3" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date3" class="tcal span4" /> </td></tr> <tr> <td> 4. </td> <td> <input type="text" name="installment4" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date4" class="tcal span4" /> </td></tr> <tr> <td> 5. </td> <td> <input type="text" name="installment5" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date5" class="tcal span4" /> </td></tr> <tr> <td> 6. </td> <td> <input type="text" name="installment6" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date6" class="tcal span4" /> </td></tr> <tr> <td> 7. </td> <td> <input type="text" name="installment7" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date7" class="tcal span4" /> </td></tr> <tr> <td> 8. </td> <td> <input type="text" name="installment8" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date8" class="tcal span4" /> </td></tr> <tr> <td> 9. </td> <td> <input type="text" name="installment9" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date9" class="tcal span4" /> </td></tr> <tr> <td> 10. </td> <td> <input type="text" name="installment10" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date10" class="tcal span4" /> </td></tr> <tr> <td> 11. </td> <td> <input type="text" name="installment11" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date11" class="tcal span4" /> </td></tr> <tr> <td> 12. </td> <td> <input type="text" name="installment12" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date12" class="tcal span4" /> </td></tr> <tr> <td> 13. </td> <td> <input type="text" name="installment13" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date13" class="tcal span4" /> </td></tr> <tr> <td> 14. </td> <td> <input type="text" name="installment14" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date14" class="tcal span4" /> </td></tr> <tr> <td> 15. </td> <td> <input type="text" name="installment15" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date15" class="tcal span4" /> </td></tr> <tr> <td> 16. </td> <td> <input type="text" name="installment16" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date16" class="tcal span4" /> </td></tr> <tr> <td> 17. </td> <td> <input type="text" name="installment17" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date17" class="tcal span4" /> </td></tr> <tr> <td> 18. </td> <td> <input type="text" name="installment18" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date18" class="tcal span4" /> </td></tr> <tr> <td> 19. </td> <td> <input type="text" name="installment19" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date19" class="tcal span4" /> </td></tr> <tr> <td> 20. </td> <td> <input type="text" name="installment20" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date20" class="tcal span4" /> </td></tr> <tr> <td> 21. </td> <td> <input type="text" name="installment21" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date21" class="tcal span4" /> </td></tr> <tr> <td> 22. </td> <td> <input type="text" name="installment22" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date22" class="tcal span4" /> </td></tr> <tr> <td>23. </td> <td> <input type="text" name="installment23" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date23" class="tcal span4" /> </td></tr> <tr> <td> 24. </td> <td> <input type="text" name="installment24" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date24" class="tcal span4" /> </td></tr> <tr><td></td><td> <input type="submit" name="save" id="save" value="Save" class="btn btn-info span3" /> <input type="hidden" readonly="readonly" name="roll_no" value="<?php echo $roll_no; ?>" class="span5" /> </td><td></td></tr> </thead> </table> </form>Here i am not getting how to store it in that table. Actually all the 24 inputs are not mandatory. If user fills only 2 then also it should store it in the database table. I tried to do like this if(isset($_POST['save'])) { $roll_no = $_POST['roll_no']; $ins_amt1 = $_POST['installment1']; $due_date1 = $_POST['due_date1']; $ins_amt2 = $_POST['installment2']; $due_date2 = $_POST['due_date2']; $ins_amt3 = $_POST['installment3']; $due_date3 = $_POST['due_date3']; $ins_amt4 = $_POST['installment4']; $due_date4 = $_POST['due_date4']; $ins_amt5 = $_POST['installment5']; $due_date5 = $_POST['due_date5']; $ins_amt6 = $_POST['installment6']; $due_date6 = $_POST['due_date6']; $ins_amt7 = $_POST['installment7']; $due_date7 = $_POST['due_date7']; $ins_amt8 = $_POST['installment8']; $due_date8 = $_POST['due_date8']; $ins_amt9 = $_POST['installment9']; $due_date9 = $_POST['due_date9']; $ins_amt10 = $_POST['installment10']; $due_date10 = $_POST['due_date10']; $ins_amt11 = $_POST['installment11']; $due_date11 = $_POST['due_date11']; $ins_amt12 = $_POST['installment12']; $due_date12 = $_POST['due_date12']; $ins_amt13 = $_POST['installment13']; $due_date13 = $_POST['due_date13']; $ins_amt14 = $_POST['installment14']; $due_date14 = $_POST['due_date14']; $ins_amt15 = $_POST['installment15']; $due_date15 = $_POST['due_date15']; $ins_amt16 = $_POST['installment16']; $due_date16 = $_POST['due_date16']; $ins_amt17 = $_POST['installment17']; $due_date17 = $_POST['due_date17']; $ins_amt18 = $_POST['installment18']; $due_date18 = $_POST['due_date18']; $ins_amt19 = $_POST['installment19']; $due_date19 = $_POST['due_date19']; $ins_amt20 = $_POST['installment20']; $due_date20 = $_POST['due_date20']; $ins_amt21 = $_POST['installment21']; $due_date21 = $_POST['due_date21']; $ins_amt22 = $_POST['installment22']; $due_date22 = $_POST['due_date22']; $ins_amt23 = $_POST['installment23']; $due_date23 = $_POST['due_date23']; $ins_amt24 = $_POST['installment24']; $due_date24 = $_POST['due_date24']; $items = array(); $installment[] =array($ins_amt1, $ins_amt2, $ins_amt3, $ins_amt4, $ins_amt5, $ins_amt6, $ins_amt7, $ins_amt8, $ins_amt9, $ins_amt10, $ins_amt11, $ins_amt12, $ins_amt13, $ins_amt14, $ins_amt15, $ins_amt16, $ins_amt17, $ins_amt18, $ins_amt19, $ins_amt20, $ins_amt21, $ins_amt22, $ins_amt23, $ins_amt24); //$in_values= serialize($installment); $due_date[] = array($due_date1, $due_date2, $due_date3, $due_date4, $due_date5, $due_date6, $due_date7, $due_date8, $due_date9, $due_date10, $due_date11, $due_date12, $due_date13, $due_date14, $due_date15, $due_date16, $due_date17, $due_date18, $due_date19, $due_date20, $due_date21, $due_date22, $due_date23, $due_date24); //$in_dates= serialize($due_date); //$s1 = "insert into installment(id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) values ('', ".$fee_id.", '".$roll_no."', ".$in_values.", '".$in_dates."', '', 'unpaid', ''"; foreach($installment as $row_key => $value) { $item = $value; $uom = $due_date[$row_key]; $items[] = sprintf("(%d, %d, '%s', %d, '%s', '%s', '%s', '%s')", '', $fee_id, mysql_real_escape_string($roll_no), intval($item), $uom, '', '', '' ); } $msql = 'INSERT INTO installment (id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) VALUES '.implode(', ', $items);But it is taking only one data. Can somebody please suggest. The data has to be saved like this saveddata.JPG 70.92KB 0 downloads Somebody please help. Thank you Similar TutorialsOkay I'm a newbie at PHP but was trying to write a counter for my website to count the amount of times a specific button is clicked. My desired outcome is as follows: If the form submit button "like" or "dislike" is clicked, get user's ip and check to see if it already exists in the database. If it exists, don't increment the count (of either button), otherwise log the ip and increment the count (of whichever button is clicked) by 1. Currently I've got the increment working (testing only the like button at the moment) and I've got the ip being stored into the database, but cannot get the comparison to work. Each time the button is clicked it adds the ip address into the database instead of disallowing it. Note: there are two different tables--one storing the ip (counter) and one storing the like clicks (Designs) (dunno if there's a better way?) Excuse my newbieness. The problem area: (like button only): if(isset($_POST['like'])) { $ip_address = $_SERVER['REMOTE_ADDR']; $query = mysql_query("SELECT ip FROM counter WHERE ip = '$ip_address'"); $num_rows = mysql_num_rows($query); if ($num_rows > 0) { die ("You've already clicked the button!"); } else { mysql_query("INSERT INTO counter VALUES ($ip_address)"); mysql_query("UPDATE Designs SET up = up + 1 WHERE ref = 'cataclysm'"); } } $select = mysql_query("SELECT up FROM Designs"); while($row = mysql_fetch_array($select)) { echo $row['up']; } I need some advice, I'm not sure if this is the right section to post this or not but I'll give it a try. I am creating a website for a small group of people to be able to message back and forth. I ran into a problem when doing the whole reply to a message option. I dont want to have each individual message as a new entry in my database, and then look for each message in that conversation when loading the conversation, I thought about inserting something like +=+=+=+=+=+= in between messages in the conversation so that when i pull up that conversation i could just separate the messages into an array by looking for that +=+=+=+=+=+= in the string of text and separating all the messages out. I want to know if anyone knows a better way of doing this or if this is a good way to go. thanks for any suggestions. hi, I have created a login page this is my code <?php if (!isset($_SESSION)) { session_start(); } $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="Marketing"; // Database name $tbl_name="Marketinglogin"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM Marketinglogin WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); if ($myusername == "sandeep") { header("location:Marketingadmin.php"); } else { header("location:Marketingemployeeform.php"); } } else { echo "wrong password"; } ?> Marketingemployee form has some fields..here when we click submit button all the fields as well as the loginusername has to be stored in the database <?php if (!isset($_SESSION)) { session_start(); } $con = mysql_connect("localhost","root", ""); if (!$con) {die('Could not connect to DB: ' . mysql_error() );} mysql_select_db ("Marketing", $con); $date = $_POST['year'].$_POST['month'].$_POST['dt'] ; $_SESSION['myusername']=$_POST['myusername']; $myusername=$_SESSION['myusername']; $sql="INSERT INTO Marketingemployeetable (Employeeid, Date,Sector,Place,Contactpersonname,Contactaddress,Mobileno)VALUES ( '$myusername','$date','$_POST[project]','$_POST[place]','$_POST[Contactpersonname]','$_POST[Contactaddress]','$_POST[Mobileno]')"; if (!mysql_query($sql,$con)) {die ('Error: ' . mysql_error());} echo "Record added"; mysql_close($con)?> please help me out here This is more of a database architect question.
I am building a CMS for website development. I am ready to use it for the first time on one of my clients. Now, my issue is is how to set up some or one of my table(s) for some areas that my client wants to be able to change in the admin section.
In their website on the front page, I put together this nice block slider. Its 6 blocks with text, a background image and nice effects. At first it was always going to be static, which was no issue at all, but later they came to me and asked if they could be able to change words in the boxes themselves in the admin section..
Of course this can be easily done by creating a table that is associated with this home page block thing and each row in the table will correspond to one of the blocks on the home page.
But I believe there might be an easier way to store this type of data without having to create another table for every feature the client wants to edit, for example they also want to be able to edit a slider on another page.
The WordPress database then came into my mind and how they store most of their data as JSON. So I was then thinking of creating a table named 'modules' for examples with three columns (id, title, data). Then inside the data column store the editable fields as a JSON string object.
For example a row could like like :
1, "Front Page Box Slider", {"slider-home" : [ {"data" : "value", "img_1", "value1"}, {"data" : "value", "img_2", "value2"} ]}
I've been doing a bit of research on this and people have just been saying, never do this if you do want your data to be searched through, which I don't.
Can anyone tell me why or why not I should do this, or maybe a better solution to my problem?
Thank you
Edited by carlosmoreeira, 17 September 2014 - 07:37 PM. hi everyone, i just signed up on this forum. I have issue, my clients wants to save time by copying data into a textarea and then letting the script process it and store it in database. the problem is never done that. the data is made up for eg. Title Mr Name Radio86 Address Chiltren House etc.... how do i split this data up and store it in database, btw ive just started programming in php in other words newbie Please help me, thanks in advance To me it is logical to store config data such as site name, meta, etc in a php file rather than storing ina table in mysql database. This will reduce the number of calls to the mysql database, as these are key parameters and needed in every page. But, a well-developed CMS like Wordpress uses a mysql table to store such basic data. What is your idea? Ain't it better to reduce mysql loads? Hi,
I have a form like this
<tr> <td><a href="edit_sales_invoice_details.php?id=<?php echo $row['dispatch_id']?>"><?php echo $row['oid'] ?></a></td> <td><?php echo $row['dispatch_id'] ?></td> <td><?php echo $row['cname'] ?></td> <td><?php echo $row['iname'] ?></td> <td><?php echo $row['quantity'] ?></td> <td><?php echo $row['dispatch_quantity'] ?></td> <td><select name="tax[<?php echo $row['dispatch_id']?>]" class="span9"> <option value="<?php echo $row['rate'] ?>"><?php echo $row['tname'].'-'.$row['rate'];?> %</option> <option value="">Tax</option> <?php $s1 = mysql_query("select * from taxes"); while($s2 = mysql_fetch_array($s1)) { ?> <option value="<?php echo $s2['rate'] ?>"><?php echo $s2['name'].'-'.$s2['rate'] ?>%</option> <?php } ?> </select> </td> <td><input type="text" name="freight[<?php echo $row['dispatch_id']?>]" class="span6" /></td> <td><input type="text" name="discount[<?php echo $row['dispatch_id']?>]" class="span6" /></td> <input type="hidden" name="order_id[<?php echo $row['dispatch_id']?>]" value="<?php echo $row['oid']; ?>" /> <td><input type="checkbox" name="selector[]" value="<?php echo $row['dispatch_id']; ?>" /></td> </tr> <?php } ?> <tr><td colspan="11"><input type="submit" name="submit" value="SAVE INVOICE" class="btn btn-info" /></td></tr>Here dispatch_id will be different but the order_id will be same. I want to generate a single invoice id for this and store it in this table invoice.JPG 18.85KB 0 downloads and by taking that invoice_id, i want to insert rest of the multiple line items to this table invoice_line_items.JPG 29.7KB 0 downloads I tried doing like this This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=305902.0 I am trying to array data to database against same id.
Here is code.
form.php
<form name="users" method="post" action="order_submit.php" enctype="multipart/form-data" onSubmit="return validate();" id="inv_form"> <div class="formSep"> <select name="company" onChange="showSubcat(this);"> <option value="">Company</option> <?php $s1 = mysql_query("select * from leads where lead_customer='Lead' ") or die (mysql_error()); while($s2 = mysql_fetch_array($s1)) { ?> <option value="<?php echo $s2['id']; ?>"><?php echo $s2['company']; ?></option> <?php } ?> </select> </div> <div class="formSep"> <table class="table invE_table"> <thead> <tr> <th></th> <th>Item</th> <th>Unit</th> <th>Unit Cost ($)</th> <th>Qty</th> <th>Tax (%)</th> <th>Total ($)</th> </tr> </thead> <tbody> <tr class="inv_row"> <td class="inv_clone_row"><i class="icon-plus inv_clone_btn"></i></td> <td><input type="text" class="span12" name="invE_item[]" /></td> <td><input type="text" class="span12" name="invE_description[]" /></td> <td><input type="text" class="span12 jQinv_item_unit" name="invE_unit_cost[]" /></td> <td><input type="text" class="span12 jQinv_item_qty" name="invE_qty[]" /></td> <td><input type="text" class="span12 jQinv_item_tax" name="invE_tax[]" /></td> <td><input type="text" readonly class="span12 jQinv_item_total" name="invE_total[]" /></td> </tr> <tr class="last_row"> <td colspan="5"> </td> <td colspan="2"> <p class="clearfix">Subtotal: <span class="invE_subtotal">$<span>0.00</span></span></p> <p>Tax: <span class="invE_tax">$<span>0.00</span></span></p> <p>Discount: <span class="invE_discount">$<span>0.00</span></span></p> <p><strong>Balance: <span class="invE_balance">$<span>0.00</span></span></strong></p> </td> </tr> </tbody> </table> </div>Here invE_item[], invE_description[], invE_unit_cost[].... are the array , i mean dynamically one can add as many as items and its details. In my order_submit.php page <?php error_reporting(0); include("connect.php"); include("admin_auth.php"); if(isset($_POST['save'])) { $company = $_POST['company']; $contact_person = $_POST['contact_person']; $billing = $_POST['billing_address']; $shipping = $_POST['shipping_address']; $reference = $_POST['reference']; $t_c = $_POST['t_c']; $payment = $_POST['payment']; $ship_in = $_POST['ship_inst']; $validity = $_POST['validity']; $currency = $_POST['currency']; $order_for = $_POST['order_for']; $assigned_to = $_POST['assigned_to']; $item = $_POST['invE_item']; $unit = $_POST['invE_description']; $price = $_POST['invE_unit_cost']; $qty= $_POST['invE_qty']; $tax = $_POST['invE_tax']; $total = $_POST['invE_total']; $sql = mysql_query("insert into orders (order_id, company_id, contact_person, billing_address, shipping_address, reference, t_c, payment, shipping_inst, validity, order_for, currency, assigned_to, last_modified, order_quote) values ('', ".$company.", '".$contact_person."', '".$billing."', '".$shipping."', '".$reference."', '".$t_c."', '".$payment."', '".$ship_in."', ".$validity.", '".$order_for."', '".$currency."', '".$assigned_to."', NOW(), 'Order')"); $last_id = mysql_insert_id(); $msql = "insert into order_line_items (id, order_id, company_id, item, unit, unit_cost, quantity, tax, total) values ('', ".$last_id.", ".$company.", '".$item."', '".$unit."', ".$price.", ".$qty.", ".$tax.", ".$total.")"; $l1 = mysql_query($msql) or die (mysql_error()); }I want to insert each item in different row with $last_id , as in the attached image . Please somebody help me in this Attached Files db.PNG 11.01KB 4 downloads This is actually a page to edit the drama details. Database- 3 tables 1. drama dramaID drama_title 1 friends 2. drama_genre drama_genreID dramaID genreID 1 1 2 2 1 1 3 1 3 3. genre genreID genre 1 comedy 2 romance 3 family 4 suspense 5 war 6 horror <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $dbname = 'drama'; $link = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or trigger_error('Error connecting to mysql'); $id = $_GET['dramaID']; $link2 = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or trigger_error('Error connecting to mysql'); $sql2 = "SELECT * from drama , drama_genre , genre WHERE drama.dramaID='".$id."' AND drama_genre.dramaID='".$id."' AND drama.dramaID = drama_genre.dramaID AND drama_genre.genreID = genre.genreID"; $status2 = mysqli_query($link2,$sql2) or die (mysqli_error($link2)); $link3 = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or trigger_error('Error connecting to mysql'); $sql3 = "SELECT * from genre "; $status3 = mysqli_query($link3,$sql3) or die (mysqli_error($link3)); <form method='Post' action='doUpdate.php' enctype="multipart/form-data"> <?php while ($row2 = mysqli_fetch_assoc($status2)) { ?> <td height="1"></td> <td><select name="gdrop"> <option value="<?php echo $row2['genreID'];?>"><?php echo $row2['genre'];?></option> <?php while ($row3 = mysqli_fetch_assoc($status3)) { ?> <option value="<?php echo $row3['genreID'];?>"><?php echo $row3['genre'];?></option> <?php } mysqli_close($link3); ?> <input type='hidden' id='drama_genreID' name='drama_genreID' value = "<?php echo $row2['drama_genreID']; ?>"/> </select> <input type="hidden" id="dramaID" name="dramaID" value = "<?php echo $row['dramaID'];?>"/> <input type="submit" Value="Update"/> The result was there were 3 dropdown menus but only the first dropdown menu has all 6 genres from my database and also the genre that belongs to the drama. I'm also wondering how I can bring all the drama_genreIDs to my save(doupdate.php) page and update all 3 of them because it seems like only the last dropdown menu's data is saved. And also how can I display only 6 genres instead of 7 with the genre that belongs to the drama , being set as the default selection. Hello, my first post here. I created a Validation class that depends entirely on static methods. It appears to be working well, but perhaps I misunderstood exactly the purpose and the consequences of using static methods. My class essentially looks like this: class Validate { static public $errors = array(); static public $valid = array(); static public function Name($name) { if ($name != '') { self::$valid['name'] = $name; return true; } else { self::$errors['name'] = 'Name is empty'; return false; } } } Does this create any chance whatsoever for a collision of data from multiple users? I am beginning to think it does, simply because from what I have recently learned about static methods, theyr'e essentially global variables because they are not instantiated. If that's the case, then it would seem possible that during times of heavy use, any application depending on this class would confuse submitted data. Any thoughts? Thanks in advance. Quote i want to store a value from a database and use it as variable in php code can anyone help me out in this code i want to store value of copies in a php variable and want that it should be more than 0 (zero) for furthur calculations $update_book="update book set copies=copies-1 where bookid='$bookid'"; $result=mysql_query($update_book,$linkID1); if($result) { print "<html><body background=\"header.jpg\"> <p>book successfully subtracted from database</p></body></html>"; } else { print "<html><body background=\"header.jpg\"> <p>problem occured</p></body></html>"; } Im making a application but many users can access it at the same time, also the data that needs to be stored into the database in 3 parts firstly the user will enter some details the comany will fill out the reamining details and the user will then accept or decline the companies proposal. The issue im havign will it be easier to just store all of this information into session variables and then save them into the database at the end when all of the details are ready ? Thank You Can anyone tell me whats wrong with this: The file uploads fine, the url however does not get posted to the database? I added a 'or die' but it didn't execute...Do I need to move the query higher up the script? <?php include ('base.php'); $id = $_GET['id']; if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "imgs/pictures/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } $file = $_FILES["file"]["name"]; $sql = "UPDATE `chillp_security`.`staff` SET `picture` = \'imgs/pictures/$file\' WHERE `staff`.`id` = $id;"; ?> Dear All, I am developing a like/dislike voting system for a scientific experiment in which the user will cast vote on a number of images. I have already written the code for it but the code is unable to store the data in the database. Kindly help me out in this issue. Below is my code for it: HTML Form for Like/Dislike Button: Code: [Select] <html> <head> <title> Like/Dislike buttons </title> </head> <body> <h1> Like/Dislike buttons </h1> <form name="form1" action="likedislike.php" method ="post"> <input type="submit" name="Like" value="Like"> <input type="submit" name="Dislike" value="dislike"> </form> </body> </html> PHP code for retrieving data and storing the vote in the database: Code: [Select] <?php session_start(); ob_start(); $host="localhost"; $username="computat_abhi"; $password="1123581321"; $databasename="computat_button"; $tbl_name="record"; $db=mysql_connect ("localhost","computat_abhi","1123581321")or die("cannot connect"); mysql_select_db($databasename,$db); if( isset($_POST['Like']) ) { $sql = 'INSERT INTO record(Image Number,Like Counter) VALUES ("b1.php",1)'; $result = mysql_query($sql); } elseif(isset($_POST['Dislike'])){ $sql = 'INSERT INTO record(Image Number,Dislike Counter) VALUES ("b1.php",1)'; $result = mysql_query($sql); } ob_end_flush(); ?> Thank you for your help. I've got an array like this: $firstquarter = array('January', 'February', 'March'); Then I'm adding it to a MySQL DB as follows: $insert = "INSERT INTO sometable (months) VALUES ('$firstquarter') "; $insertresult = mysql_query($insert) or die ('Error in Insert query: ' . mysql_error()); When I use PHPMyAdmin I see a this value stored in the DB: 'Array' Can I retrieve the values, by index, from this database field?? Hi I am using Zen-Cart to which I have made significant changes. Two years ago I managed to change the Products Sort Order from Integer to Decimal(5,2) to store books such as 1, 1.5, 1.75, 2 etc. Regrettably we had a major server issue and I also lost the new coding. Having restored everything else whenever we enter a book series number such as 1.5 it only stores as 1. To date the zen-Cart forums have been unable to offer a solution so I am reaching out to see if anyone else can advise me of how to get this working again please.
Thanks in advance Owen
For some reason my for loop only seems to be storing some data in my fields, most of the time the data is not true but simply duplicating one of the entries. So instead of having a string of 1,2,3,4 for instance it would store all of them as 4. The entires are selected using fields in a multiple select box, in theory of someone choses 10 unique entries from the "Systems" category all 10 should be made into rows in the MySQL table. Any idea why this is happening? The form, if ($type == "games") { echo "<tr><td>".$name."</td><td><select name='".$name."_".$i."'[] multiple='multiple'><option value='' selected>--------</option>"; $sqla = mysql_query("SELECT * FROM ".$pre."games ORDER BY `name` ASC") or die(mysql_error()); while($row2a = mysql_fetch_array($sqla)) { $system = mysql_fetch_array(mysql_query("SELECT * FROM ".$pre."systems WHERE id = '".$row2a[system]."'")); echo "<option value='".$row2a[id]."'>".$row2a[name]." - ".$system[name]."</option>"; } echo "</select></td></tr>"; } if ($type == "system") { echo "<tr><td>".$name."</td><td><select name='".$name."_".$i."'[] multiple='multiple'><option value='' selected>--------</option>"; $sqlb = mysql_query("SELECT * FROM ".$pre."systems ORDER BY `name` ASC") or die(mysql_error()); while($row2b = mysql_fetch_array($sqlb)) { echo "<option value='".$row2b[id]."'>".$row2b[name]."</option>"; } echo "</select></td></tr>"; } The PHP code, while($row = mysql_fetch_array($query)) { $name = "$row[name]"; for ($i = 0; $i < count($_POST["systems_$i"]); $i++) { mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, 'systems', '".$_POST["systems_$i"]."', '".$fetch[0]."', 'content')"); } for ($i = 0; $i < count($_POST["games_$i"]); $i++) { mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, 'games', '".$_POST["games_$i"]."', '".$fetch[0]."', 'content')"); } Hi, wondering if somebody can tell me where I'm going wrong (I'm new to all of this). I have the following php code which uploads an image file into my database: Code: [Select] //Connect to database include 'Resources/Include/db.inc.php'; $tmp=$_FILES['image']['tmp_name']; //get users IP $ip=$_SERVER['REMOTE_ADDR']; //Don't do anything if file wasn't selected if (!empty($tmp)) { //Copy file to temporary folder copy($tmp, "./temporary/".$ip.""); //open the copied image, ready to encode into text to go into the database $filename1 = "./temporary/".$ip; $fp1 = fopen($filename1, "rb"); //record the image contents into a variable $contents1 = fread($fp1, filesize($filename1)); $contents1 = addslashes($contents1); //close the file fclose($fp1); $ftype = $_FILES['image']['type']; //insert information into the database if(!mysql_query("INSERT INTO LetterImages (Data,Type,LetterID,Page)"." VALUES ( '$contents1', '$ftype',1,1)")){ echo mysql_error(); } //delete the temporary file we made unlink($filename1); } This seems to work ok, as when I go to the LetterImages table there is now an additional row with a file in the blob field. I then have the following code which is supposed to display the image: Code: [Select] $result=mysql_query("SELECT * FROM LetterImages WHERE LetterID=1 AND Page=1"); //fetch data from database $sqldata=mysql_fetch_array($result); $encoded=stripslashes($sqldata['Data']); $ftype=$sqldata['Type']; //tell the browser what type of image to display header("Content-type: $ftype"); //decode and echo the image data echo $encoded; Instead of displaying an image, however, this just displays pages and pages of incomprehensible data. Can anybody tell me where I'm going horribly wrong? |