Jump to content

IreneLing

Members
  • Posts

    60
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

IreneLing's Achievements

Member

Member (2/5)

0

Reputation

  1. Thanks for your advice , I will take note of it , thank you.
  2. Thank you so much, yes it works.Really thanks to your solution and explanations.
  3. I'm so sorry for this question but I not really know how to play with single and double quote. If I have a query like this: mysql_query('UPDATE table SET Status=1,Sending=Done WHERE ID IN ('.implode(',', $done).')'); And I wish to add SentAt='$date' in the query as well , and I try this: mysql_query('UPDATE table SET Status=1,Sending=Done,SentAt='$date' WHERE ID IN ('.implode(',', $done).')'); Not working...how should I write it? Thank you.
  4. Hello all. I have a php script which will insert csv data into database using PDO. But it's slow even with just few thousands records. So how can I prevent client from waiting for it when they want to upload data? I tried INSERT DELAYED but it's not working... Thank you.
  5. Really thanks for your code requinix , I tried to understand it ( a little hard for me) and try it , but here is the errors: Warning: array_combine() [function.array-combine]: Both parameters should have an equal number of elements Warning: array_merge() [function.array-merge]: Argument #2 is not an array Warning: array_combine() [function.array-combine]: Both parameters should have an equal number of elements Warning: array_merge() [function.array-merge]: Argument #2 is not an array INSERT INTO UserAddedRecord (lastname, firstname, ceLL, group) VALUES (NULL, NULL, NULL, NULL), (NULL, NULL, NULL, NULL) $additional_columns = array("group"); If I change 'group' to other column name that do not exist in my table then it will just insert data in csv file and works fine , but if I put existed column name then everything will become NULL , and I have problem in trying to solve it since do not really understand the error..
  6. Hi all. Here is the code:(thanks to jcbones) if (($handle = fopen($source_file, "r")) !== FALSE) { $columns = fgetcsv($handle, $max_line_length, ","); foreach ($columns as &$column) { $column = str_replace(".","",$column); } while (($data = fgetcsv($handle, $max_line_length, ",")) !== FALSE) { while(count($data) < count($columns)) { array_push($data, NULL); } $c = count($data); for($i = 0; $i < $c; $i++) { $data[$i] = "'{$data[$i]}'"; } $sql[] = '(' . implode(',',$data) . ','.$_POST[group].')'; } $sql = implode(',',$sql); $query = "INSERT INTO mytable (".mysql_real_escape_string(implode(",",$columns)).",Custgroup,user_id) VALUES " . $sql . "\n"; mysql_query($query) or trigger_error(mysql_error()); fclose($handle); } } If my csv file is: lastname,firstname,gender bob,ah,male So now the query will be : INSERT INTO mytable (lastname,firstname,gender) VALUES ('bob',ah','male'). But how if I want to insert extra data into mysql together with the data in csv file? Such as I have a value $_POST['group'] = 'family', so I tried: $sql[] = '(' . implode(',',$data) . ','.$_POST[group].')'; $query = "INSERT INTO $target_table (".mysql_real_escape_string(implode(",",$columns)).",custgroup) VALUES " . implode(',',$sql) . "\n"; But in the query it will become : INSERT INTO mytable (lastname,firstname,gender,custgroup) VALUES ('bob',ah','male',family). It didn't have single quote , so I have error to insert the record.Can I know how to solve this problem? Thanks.
  7. jcbones , I really wish can treat you to lunch if I live near your place , yes it fit my use , and it works like a charm. Thank you so much , I really appreciate your help.
  8. Thanks for your reply. So now I try something like this... if (isset($_POST['submit'])) { if (is_uploaded_file($_FILES['filename']['tmp_name'])) { echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "<br></h1>"; echo "<h2>Displaying contents:</h2>"; readfile($_FILES['filename']['tmp_name']); echo "<br>"; echo $headers; } $handle = fopen($_FILES['filename']['tmp_name'], "r"); $header = fgetcsv($handle); while(! feof($handle)){ while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); mysql_select_db("EMC", $db); $sql = "SELECT * from CSVtest"; $result = mysql_query($sql,$db); while ($user_table_property = mysql_fetch_field($result)) { for($i=0; $i<$num; $i++){ if($header[$i] == $user_table_property->name ) { $import = "insert into CSVtest ( `" . $header[$i] . "`) values ('" . $data[$i] . "')"; } } mysql_query($import) or die(mysql_error()) ; } } } The column is correct , but each data will inserted into different rows,and some will duplicate....
  9. Hello all. Here is my script... if (isset($_POST['submit'])) { if (is_uploaded_file($_FILES['filename']['tmp_name'])) { echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "<br></h1>"; echo "<h2>Displaying contents:</h2>"; readfile($_FILES['filename']['tmp_name']); echo "<br>"; echo $headers; } $handle = fopen($_FILES['filename']['tmp_name'], "r"); $header = fgetcsv($handle); while(! feof($handle)){ while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $import="INSERT into CSVtest($header[0],$header[1],$header[2],$header[3],$header[4]) values ('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')"; mysql_query($import) or die(mysql_error()); } } fclose($handle); echo "Done"; } This is the way how I insert data into database according to header even it's not arranged same as the table column. If the csv has only "cell,firstname,lastname,," (and my table has only these 3 columns as well) then it still working...but if there are "cell,address,company,firstname,lastname" then it will show me unknown column error. Actually I wish to have a function that even there are many columns in csv that not exist in the table it still can just pick the right column and insert into table. Can anyone give me hints on how to change my script?I know there are many errors...it's really embarrassed to show my low standard script... Thanks in advance.
  10. Thank you so much for the links xyph , I'm just wondering how to turn it off before I start google it . Thanks again and wish you have a nice day . PS: Thanks for the link in your signature too , my coding have major sql injection problem now and gotta solve it.
  11. Ah...I found the solution....using stripslashes(). and because I have have magic quotes enabled.
  12. Hi all. When I typed symbol ' in my textarea , after I submit it and view for what I typed , it will automatically add a slash in front of the ' . Such as the message is "I'm fine" , then it will turn out as "I\'m fine". Can I know what is the problem ? and how can I solve it? Thanks for every reply .
  13. Problem solved , the solution is add one more line: var bulksend = document.getElementById('bulksend');
  14. I have a function which is use to check chinese input in a textarea then set the maximum length , it works with IE , Opera , Chrome except firefox . Is there any way to solve this problem ? Just in case....I will put my function here.... function testChinese() { countA = 0; for(var i=0; i<bulksend.inputtext.value.length; i++) { curText = bulksend.inputtext.value.charCodeAt(i); if(curText > 127) { countA += 1; } } if(countA>0) return true; } function setlength(){ min = 0; limit = 0; if(testChinese() == true) { min = 70; limit = 66; } else { min = 160; limit = 156; } var typedtext = document.getElementById('inputtext').value; .........continue....... Thanks for every reply .
  15. Thanks for your reply Drummin , actually there are 2 forms in this page , above is to insert data , and below is display and delete. <form name="frmSearch" method="post" action="insert-add.php"> <table width="599" border="1"> <tr> <td> Mobile Phone: </td> <td> <input name="cell" type="text" id="cell" > </td> </tr> <tr> <td>Mobile Company:</td> <td><select name="mobilecompany"> <option>A</option> <option>B</option> <option>C</option> </select> </td> </tr> <tr> <td> First Name: </td> <td> <input name="firstname" type="text" id="firstname" > </td> </tr> <tr> <td> Last Name: </td> <td> <input name="lastname" type="text" id="lastname" > </td> </tr> <tr> <td>Work Phone:</td> <td><input style="text" name="workphone"></td> </tr> <tr> <td>Fax:</td> <td><input style="text" name="fax"></td> </tr> <tr> <td>Email:</td> <td><input style="text" name="email"></td> </tr> <tr> <td>Gender:</td> <td><select name="gender"> <option>Male</option> <option>Female</option> </select> </td> </tr> <tr> <td>Birthday:</td> <td> <input name="birthday" value="<?php echo htmlentities($disp_birthday) ?>"> <input type=button value="select" onclick="displayDatePicker('birthday', this);"> </td> </tr> <tr> <td> ID: </td> <td> <input type="text" name="user_id" value="<?php echo $id;?>"></td> </tr> <tr> <td><input type="submit" value="Add" name="add"></td> </tr> </table> </form> Some other codes...then continue... <table width="600" border="1"> <tr> <th width="50"> <div align="center">#</div></th> <th width="91"> <div align="center">ID </div></th> <th width="198"> <div align="center">First Name </div></th> <th width="198"> <div align="center">Last Name </div></th> <th width="250"> <div align="center">Mobile Company </div></th> <th width="100"> <div align="center">Cell </div></th> <th width="100"> <div align="center">Workphone </div></th> <th width="100"> <div align="center">Group </div></th> </tr> <? echo "<form name='form1' method='post' action=''>"; while($objResult = mysql_fetch_array($objQuery)) { echo "<tr>"; echo "<td align='center'><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$objResult[addedrec_ID]\"></td>"; echo "<td>$objResult[addedrec_ID] </td>"; echo "<td>$objResult[FirstName]</td>"; echo "<td>$objResult[LastName] </td>"; echo "<td>$objResult[MobileCompany] </td>"; echo "<td>$objResult[Cell] </td>"; echo "<td>$objResult[WorkPhone] </td>"; echo "<td>$objResult[Custgroup] </td>"; echo "</tr>"; } echo "<td colspan='7' align='center'><input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\">"; if (isset($_POST['delete']) && isset($_POST['checkbox'])) // from button name="delete" { $checkbox = ($_POST['checkbox']); //from name="checkbox[]" $countCheck = count($_POST['checkbox']); for($d=0;$d<$countCheck;$d++) { $del_id = intval($checkbox[$d]); $sql = "DELETE from UserAddedRecord where addedrec_ID = $del_id"; $result2=mysql_query($sql) or trigger_error(mysql_error());;; } if($result2) { $fgmembersite->GetSelfScript(); } else { echo "Error: ".mysql_error(); } } echo "</form>"; ?> </table>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.