Jump to content

BadGoat

Members
  • Posts

    72
  • Joined

  • Last visited

    Never

Everything posted by BadGoat

  1. Yay! I fixed it.. Here's what works! (was a problem with the syntax of the MySQL query) Thank you kindly for pointing me in the right direction <?PHP include ("../config.php"); echo' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> <link rel=stylesheet href="../eve.css" type="text/css"> </head> <body>'; $input = $_POST['t_data']; //your post data here. $array = explode("\n", $input); foreach ($array as $value){ if ($value != null && $value != "" && $value != " " && $value != "\n" && $value != "\t" && $value != "\r"){ $array2 = explode(",", $value); $cola = mysql_real_escape_string($array2[0]); $colb = mysql_real_escape_string($array2[1]); echo 'column a is '.$cola.'<br />'; echo 'column b is '.$colb.'<br />'; $sql = "INSERT INTO etest VALUES ('$cola', '$colb')"; mysql_query($sql) or die("Query failed: " . mysql_error() . " Actual query: " . $sql); } } ?>
  2. OK, been tinkering all day and night and still not having any luck.. I have tried: $sql = "INSERT INTO `etest`('$cola', '$colb') VALUES ('$cola', '$colb')"; and $sql = "INSERT INTO `etest`('$cola', '$colb')"; and $sql = "INSERT INTO `etest`('$cola', '$colb') VALUES ('$array2[0]', '$array2[1]')"; and various other attempts at getting the two numbers posted into the db.. The goal is to take the data from the first page, separate by comma and then insert into the data into the db. Help ???
  3. I can understand that but that defeats the purpose of just pasting the data into the textfield on the previous page.. (I think!) Would the VALUES portion have to be $array2[0] and $array2[1] instead?
  4. ok, I started small, to make sure I had it figured out before expanding it, and I am getting an error.. On the page where I can paste in the data to the textfield I type 1,1 and submit it. The error I get: Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1', '1')' at line 1 Actual query: INSERT INTO `etest`('1', '1') Here's the code from the second page: <?PHP include ("../config.php"); echo' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> </head> <body>'; $input = $_POST['t_data']; //your post data here. $array = explode("\n", $input); foreach ($array as $value){ if ($value != null && $value != "" && $value != " " && $value != "\n" && $value != "\t" && $value != "\r"){ $array2 = explode(",", $value); $cola = mysql_real_escape_string($array2[0]); $colb = mysql_real_escape_string($array2[1]); $sql = "INSERT INTO `etest`('$cola', '$colb')"; mysql_query($sql) or die("Query failed: " . mysql_error() . " Actual query: " . $sql); } } echo $input; ?> Is there anything glaring as to why it errors out?
  5. Thank you for the replies! I've been reading on the PHP site about EXPLODE and I see (in theory) how to use it.. And I see in your example code how it is done, so I think that I can play around with it. One question that comes to mind early on though.. As the field that I paste the data into is a textarea field, would I need to do something like $text = nl2br($text); to preserve the line breaks between each row of data I am entering?
  6. Hello! Looking for pointers in how to enter comma separated lines of text into a db using a text field? The ideal would be to have a text box which I can paste large lumps of data into which would be inserted into a db line by line.. I don't know which concept I should be learning to do such a thing. Any guidance is much appreciated! (example of data which could be pasted into a text field for db insertion) 200005, Vegetable, Corn 200006, Vegetable, Peas 300001, Fruit, Apple 300002, Fruit, Banana 400004, Meat, Mutton 400005, Meat, Turkey
  7. I tried a handful of different syntaxes (I get them mixed up, still to this day) // write form results to file $ourFileName = "testFile.txt"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); $myFile = "testFile.txt"; $page_number = $row['page_number']; $line_number = $row['line_number']; $deo_text = $row['deo_text']; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $row['page_number']); fclose($fh); It does not error out, but it does write a blank text file.
  8. Sorry for confusion That's correct, I want to save the output from this query to a text file.
  9. Hello! I am trying to save a MSSQL query to a text file, and having no luck. I've read tutorials on how to create a text file and how to write some text to it: $ourFileName = "test.txt"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); $myFile = "testFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "Heres line number 1!\n"; fwrite($fh, $stringData); $stringData = "Heres line number 2!\n"; fwrite($fh, $stringData); fclose($fh); And I have written the query which displays the information I want, but I am not sure how to implement the query into the text file creation. Query: $sqlquery = "SELECT text.*, text_text.* FROM text_text, text WHERE text_text.textid = text.textID AND text.textID = '".$row['textID']."' ORDER BY dep_text_id"; $queryresult = mssql_query($sqlquery) or die(" Could not execute mssql query !"); $row = mssql_fetch_row($queryresult); Looking for a bit of direction!
  10. Hello! Looking for a kick in the right direction... How would I go about nesting an if/else within an if/else? As an example, let's say I have a list of music groups, and by clicking one of them, a list of their albums is displayed. (this part I can do!) But I want a list of the songs associated with that album to be displayed below the album. Perhaps nesting an if/else within an if/else is not the answer? I have tinkered with some theoretical code, and the only time I have been able to return anything, it's a single wrong song in every other album list. Any help would be most appreciated. Here's a bit of code which I've successfully used to $sqlquery = "SELECT song.*, album.*group.* FROM song, album, group WHERE song.song_id = album.song_id AND album.group_id = group.group_id AND group.group_id = '$group_id' "; $queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query !"); $row = mysql_fetch_row($queryresult); $album= $row[0]; $tdcount = 1; $numtd = 1; // number of cells per row echo ' '; mysql_data_seek($queryresult,0) ; while($row = mysql_fetch_array($queryresult)) { if ($tdcount == 1) echo ''.$row['album'],' '; if ($tdcount == $numtd) { echo "<br />"; $tdcount = 1; } else { $tdcount++; } }
  11. OK, I see that COUNT is the right choice. Now when I want to echo the count, is it this? echo count($citycount);
  12. Hi! I am trying to count the # of instances where an ID appears in a table. I have a city table where each city has an id and a region id, a region table where the region has an id. I want to be able to count the # of cities are in a region by id. Everything I've tried is either 0 or 4, no clue how I got 4, even though I verified that none of the regions had only 4 cities. Here's a bit of code, where I'd been trying to get it to work. <tr> <td>'.$row['region'].' contains '; $query1 = "SELECT SUM(region_id) AS totalcons FROM e_city WHERE region_id = '$region_id'"; $result = mysql_query($query1); $r = mysql_fetch_array($result); echo number_format($totalcons); echo' Cities.</td> </tr> Please point me in the right direction. Thanks!
  13. thorpe, diw_id={$row['diw_id']}' made all the difference in the world. With that, now the pop-up pops correctly with the data from my db. Thank you kindly!
  14. OK, going through my own code, I found I constructed the Java portion incorrectly. Now, echo"<a href=\"/edits/edit_status.php?diw_id=".$row[diw_id]."\" onClick=\"openPic('/edits/edit_status.php?diw_id='".$row[diw_id]."' size=small','pop','600','200'); return false\">[edit]</a></td> "; echo' The above gives me the correct data but the pop-up window functionality is not working. But if I do echo"<a href=\"/edits/edit_status.php?diw_id=".$row[diw_id]."\" onClick=\"openPic('/edits/edit_status.php?diw_id=".$row[diw_id]." size=small','pop','600','200'); return false\">[edit]</a></td> "; echo' instead, the pop-up functionality works, but the SQL data is not pulled.
  15. Hello! I am trying to get a hyperlink with embedded php to work also with a java function. The goal is to get all the data associated with the 'diw_id' record. The link, in it's current, non-working state: echo"<a href=\"/edits/edit_status.php?diw_id=".$row[diw_id]."\" onClick=\"openPic('/edits/edit_status.php?'.$row[diw_id].' size=small','pop','600','200'); return false\">[edit]</a></td> openPic is a Java function: function openPic (url,name,wide,high) { var window_top = (screen.height-high)/2; var window_left = (screen.width-wide)/2; newWindow = window.open('' + url + '',''+ name +'','height=' + high +',width=' + wide + ',top=' + window_top + ',left=' + window_left + ', scrollbars'); } function closeWindow() { if (window.newWindow && window.newWindow.open && !window.newWindow.closed) window.newWindow.close(); I'm not that familiar with Java, would I be better served leaving the URL out of the function, or is that a requirement?
  16. Thanks, that gives me an idea of where to search/how to construct what I need. Many thanks!
  17. Thank you mpharo, that allowed me to see the ID in the string! A followup question: What is the best way to refresh the parent HTML frame that the link is launched from, upon clicking the SUBMIT button?
  18. My fault, I selectively tried to only include the link in question. Typically I use single quotes, but I run into problems (such as this one) when links have combinations of single and double quotes within them. A larger chunk of code: $get_firm_info = mssql_query("SELECT * FROM i_status WHERE status_id = '".$row['diw_status_id']."'"); $row=mssql_fetch_array($get_firm_info); $status_name = $row['status_name']; echo' <tr> <td class="selcol1">Status:</td> <td class="selcol2"> ' .$status_name. ' '; echo"<a href=\"http://www.domain.com/edit_status.php?diw_id=\".$row[diw_id].\"\" onClick=\"openPic('edits/edit_deposition_status.php?size=small','pop','600','200'); return false\">[edit]</a></td> </tr>";
  19. Hello! I have been trying to get a link to work which is in PHP but has a Java element to it.. And so far, I have not been successful. <td>echo"<a href=\"http://www.domain.com/edits/edit_status.php?diw_id=\".$row[diw_id].\"\" onClick=\"openPic('edits/edit_status.php?size=small','pop','600','200'); return false\">[edit]</a></td> When I mouse over the link, the edit_status.php?diw_id= is blank, not getting the ID#. Clicking the Edit pops up the new window as hoped for, just missing my data. Since I am relatively new, I would bet I am doing something very wrong.
  20. Hi Ken, I made that change and there are no errors still. Would that indicate that it's an issue elsewhere?
  21. Thank you only one for looking, just tried your recommendation, didn't work I am still getting the MAIL FAILED message.
  22. Here are all the variables associated with mail: mail.force_extra_parameters no value no value sendmail_from scheduling@domain.com scheduling@domain.com sendmail_path no value no value Internal Sendmail Support for Windows enabled SMTP localhost localhost smtp_port 25 25 I would guess that mail is enabled... Is that correct?
  23. Heya! I am having a problem with a simple mail script... It doesn't send! I have PHP5 installed on our company webserver. Our website is ASP-based, and there are a few ASP scripts which send emails successfully. This server hosted some older PHP scripts which used to mail stuff out also, and I tried to test the mail using the old scripts and they fail as well. So while I admit to being a nooblet, I would think that the server is set up to email correctly... ? So far, none of the PHP scripts have worked out, including the FreakMailer mail tutorial, which I tried this morning. I am not sure what I need to check next. My simple little email script is below. This page <?php $connect = mssql_connect("***","***", "***") or die("Could not connect"); $result = mssql_select_db("***") or die("Could not select that database !"); error_reporting(0); // To send HTML mail, the Content-type header must be set $from = "From: Form Results <test@domain.com>"; $to = "badgoat@domain.com"; $subject = "TEST"; $body = ($_POST['name'] . "\r" . $_POST['phone'] . "\r" . $_POST['email'] . "\r" . $_POST['comments'] . "\r\n"); $email=$_POST['email']; if(mail($from,$to,$subject,$body)) echo "Data Recieved Successfully"; else echo "MAIL FAILED"; ?> Might it be a problem with the PHP.ini file? Would I be better off trying to get the admin to allow me to install Apache? Any suggestions would be most appreciated, I am sincerely stuck.
×
×
  • 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.