Jump to content

phpstuck

Members
  • Posts

    59
  • Joined

  • Last visited

Everything posted by phpstuck

  1. Ok, I am using JavaScript for a form, it generates a new row for data entry should the user need to add more parts and pricing, when I post this to the PHP handler I would like to get a total of the Array for $cost only... So far I have managed to create a loop that has no exit and I am burned out. I have researched this using Google and managed to get a virus from another Forum that took two entire days to root out. I hope someone here can help me solve this First the Form. <HTML> <HEAD> <TITLE> Add/Remove dynamic rows in HTML table </TITLE> <SCRIPT language="javascript"> function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; for(var i=0; i<colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[0].cells[i].innerHTML; //alert(newcell.childNodes); switch(newcell.childNodes[0].type) { case "text": newcell.childNodes[0].value = ""; break; case "checkbox": newcell.childNodes[0].checked = false; break; case "select-one": newcell.childNodes[0].selectedIndex = 0; break; } } } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { if(rowCount <= 1) { alert("Cannot delete all the rows."); break; } table.deleteRow(i); rowCount--; i--; } } }catch(e) { alert(e); } } </SCRIPT> </HEAD> <BODY><FORM action=testjs.php method=post> <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" /> <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" /> <TABLE id="dataTable" width="350px" border="1"> <TR> <TD><INPUT type="text" name="partnum[]"/></TD> <TD><INPUT type+"text" name="desc[]"/></TD> <TD><INPUT type="text" name="cost[]"/></TD><br> <TABLE id="dataTable1" width="350px" border="1"> <TR> <TD><INPUT type=submit value="Generate estimate now" name=B1></B></P></TD> </TR> </TABLE> </FORM> </TR> </TABLE> </BODY> </HTML> Then the handler that needs to get the sum of the $cost Array: <?php $partnum = $_POST['partnum']; $desc = $_POST['desc']; $cost = $_POST['cost']; foreach($desc as $a => $b) echo "$partnum[$a] - $desc[$a] - $cost[$a] <br />"; for ($i=0; $i<$cost; $i++) { echo $_POST['cost'][$i]."<br>"; } $test = array($_POST['cost']); echo "Sum of the array is: ".array_sum($test)."<br>"; ?> Any help figuring this out would be greatly appreciated!
  2. Thanks everyone... the seemingly impossible is not so scary...LOL
  3. Oh well I will just make it invisible for now using the trusty ole' <? include "db.php"; error_reporting(~E_ALL); $sql_date = mysql_query.... But I still sure would like to know what is causing the warning to pop up there... If anyone knows I am watching for the answer so that I can learn from my mistake.
  4. Nope...no error on line 4... It prints the desired result, but then shows that warning right after it... The code and result are exact and full that I posted... Makes no sense. It appears the error is on line 6, but it all seems right to me.
  5. OK I get the following error when running this on my server.... any ideas? "Title: 650 New!! Warning: mysql_fetch_array(): 4 is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\jhc\csidisplay.php on line 6" It returns the tag number and the phrase New!! but develops this error, any help is greatly appreciated! <? include "db.php"; $sql_date = mysql_query("SELECT tag, ro, veh, cust, phone, warr, appt, wait, tech, type, notes, dateadded , ( TO_DAYS(CURDATE()) - TO_DAYS(dateadded) ) as date_diff FROM repairs") or die (mysql_error()); while(list($tag, $ro, $veh, $cust, $phone, $warr, $appt, $wait, $tech, $type, $notes, $dateadded, $date_diff)=mysql_fetch_array($sql_date)){ if($date_diff > 14){ $new = "y"; } echo "Title: $tag"; if($new == "y"){ echo " <font color='red'>New!!</font>"; } mysql_free_result($sql_date); unset($new); } ?>
  6. The quick explination... You are simply applying the ID number to the exact article when you create the link, that means anything you do with that link will carry the ID number so it applies changes only to that exact article. If you look over it a few times it will begin to become really clear... Glad it worked well for you. BTW I just checked the page... It all looks really great :-)
  7. Just take out that line and it should function perfectly, since everything is coming in POST anyway. Just srip out any special characters someone might add and you are there.
  8. Yeah you should be fine with that, I was just putting it as simple as I could for example purposes. I'm off to bed but I'll check on you in the morning.. Good luck!
  9. Ok I'll try this again, even I was confused by my last post...LOL Ok on your main page as linked in your first post you need to query the database and assign the id with the hit this link. [code] $linklist=mysql_query(         "SELECT id, title, link, category, body FROM articles"); while ($all = mysql_fetch_array($linklist)) {   $id=$all['id'];   $title=$all['title'];   $link=$all['link'];   $category=$all['category'];   $body = $all['body'];    //then your layout but the hit this link needs to be as follows echo "<a href='hit_this_link.php?appid=$id'>[HIT THIS]</a> // that will attach your id for the GET statment on the processing page [/code] Next you need to create a php page to process the hit this call it hit_this_link.php [code] $aprid = $_GET['appid']; UPDATE articles SET hits = hits + 1 WHERE id='$aprid'"); include_once "the_name of your main page.php"; [/code] The rest you'll have to figure out on your own :-)
  10. Check out this reference.. I think with a little figuring you can htaccess protect the files so they can't be deep linked, shile still allowing logged in users to gain access without multiple log in screeens popping up each time. [a href=\"http://forums.devshed.com/php-development-5/htaccess-and-php-16736.html\" target=\"_blank\"]http://forums.devshed.com/php-development-...-php-16736.html[/a]
  11. Here is a script that does just that using a cookie. It is easier for me to link you than try to explain it. [a href=\"http://www.clarksco.com/blog/?p=10\" target=\"_blank\"]http://www.clarksco.com/blog/?p=10[/a]
  12. If I am reading correctly... Don't let them view the files on the directory itself. I would add the users ID number from your users table to thier session. When they upload a file, enter the file name along with thier username and id into that database, this way each file is associated with a user. THen when a user wants to view thier files you can create a page that will only pull files names associated with the logged in user and echo them as a link for download. Close the entire directory with permissions or by inserting an index page into it.
  13. Each story when entered into the database should have an ID number, use that number to ID each story and also become the ID php uses to update the hit number. If I am way off base please explain your situation a little better and I'll redo my reply
  14. Try this [code] while($row = mysql_fetch_array($result))         $key_row = $row['keyword'];   if ($key_row != ""){       echo $row['keyword'];       echo "<br />";       echo $row['definition'];       echo "<br />";   } else {       echo "The keyword wasn't found";   } [/code]
  15. Thank you, for with that and some time in the manual I'm set
  16. Another great book on this subject... Beginning PHP 5 and MySQL ECommerce: From Novice to Professional by Cristian Darie and Mihai Bucica
  17. $String3a = implode(", ", $_POST['features']); Right after implode this line tells it to store it in the database with a comma in between each entry. If you want to pull it out and echo it as all the chosen features listed and shown with just a comma in between, just pull it out as you would any other data. If you want to reseperate into individual features all in thier own table cell in HTML you would have to EXPLODE the data first. A simple example if you want it all laid out in one section with comma's between each choice: [code] $contlist=mysql_query(         "SELECT * FROM yourtable WHERE username='$username'"); /*I added username incase you are breaking each down, you can take it out if you don't need it.*/ while ($all = mysql_fetch_array($contlist)) { $features = $all['features']; $somethingelse = $all['somethingelse']; $anotherone = $all['anotherone']; } echo "Features Chosen: " . $features . "<i>END</i>"; [/code] Hope it helps, Rob
  18. <input type="checkbox" name="features[]" value="Sauna"> is correct how you process it into the database is where you are probably having the trouble. [code] //<?php blah blah would be before the first lines.. $String3a = implode(", ", $_POST['features']); $String3b = implode(", ", $_POST['somethingelse']); $String3c = implode(", ", $_POST['anotherone]); //other stuff might be here $sql = mysql_query("INSERT INTO yourtablename (features, somethingelse, anotherone)                      VALUES('$String3a', '$String3b', '$String3c')")                      or die (mysql_error());   if(!$sql){     echo 'A database error occured while updating your choices. Please contact the Web site owner.';     } else {       include 'nextformpage'; } }   ?> [/code] Hope that helps
  19. I think I know what the problem is... I think When you echo or print you start with echo "something inside these quotes"; but if you say echo "somthing "important" in these quotes"; it will generate a syntax error because you have double quotes inside the start and end double quotes. Try changing the starting and ending quotes to single quotes, if that dosen't work change the start and end back to doubles and all of the quotes inside (in your code for everything) to single quotes. Let me know, but that has happened to me more than once and driven me crazy for hours trying to figure it out.
  20. Are you getting a parse error?
  21. $sql = mysql_query("UPDATE Users SET Username='$ud_Username', Password='$ud_Password', Email='$ud_Email' WHERE Username='$Username'"; mysql_query($query); if(!$sql){ echo 'A database error occured while creating your account. Please contact support.'; }
  22. <a target="_blank" href="http://www.yahoo.com">YAHOO LINK</a>
  23. You can enforce MIME types also... if (eregi('^image/p?jpeg(;.*)?$', $_FILES['upload']['type'] There are a few issues though, and you still want to simply check extentions also to keep hackers from adding code the the end of a .jpg file with a binary editor and then ending it in .php which the MIME would be an image still... Also IE uses the standard compliant image/pjpeg while mozilla uses image/jpeg and opera even uses something different. I'm sure someone can add more to this post, my thoughts are kinda scattered today.
  24. First of all... DO NOT store credit card numbers, bad practice and you would have to be very good at security to do it, plus there is no need. Leave the credit cards to the payment processor. I think many are missing the point of you using this as a chance to learn. I can assure you that you are about to write the mesiest code you have ever seen, and then you will throw it out and re-write it hundreds of times. But that is how everyone else learns too. You are right, cookies and sessions will be the best way to track the shopping of your clients. There are several good tutorials online about writing your own php/MySQL shopping system that should help you get where you are headed. It won't be fast, but since you have a project in mind you will drive towards the goal. Your C++ background will certainly speed up the learning curve, since PHP is derived from C style syntax. Good luck and just keep asking questions, someone will offer help, maybe not the Superman but some local superhero will emerge to help you with each trouble you run into. For a quick start into many of the basics, run to Books a Million and get the book "PHP5 and MySQL BIBLE" Lots of good reading and helpful figuring out the basics and some more complex stuff. Rob
  25. Is it possible to have PHP delete a hard copy of an image from a folder in the tree, when deleting the corrosponding information from the MySQL database. More or less what I am trying to figure out is... I have a table with three fields, ID, Name and filename, when a user first uploads an image it uploads to a folder in my server, then simply inserts the file name into the database which I call later using <img src='uploadz/$photoname'> Now if the user deletes the account or just one picture, can I have PHP also delete the hard copy in the folder when it takes the link from the database. Hmmm... Probably an easy task but I have searched the world over with no solution Thanks, Rob
×
×
  • 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.