Jump to content

lhbdan

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

lhbdan's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I wrote the code below as a way of deleting books from a database. The variables sent to this piece of code come from the page before it, through checkboxes with names corresponding to books, for example the page may have 3 checkboxes with the names 3, 4 and 5. If the user was to select checkbox 4, the variable 4 would be sent through post to this piece of code. The code below selects all of the books from the database in the users school, and then cycles through it, checking whether a book should be deleted by checking whether the post value for that book has been set, eg. if book three has been sent, isset($_POST[$temp]) should return a true, and thus the book is deleted from the database via the mysql_query. The code however will not run, currently I am getting Parse error: syntax error, unexpected T_STRING in /home/textexch/public_html/home/exchange/deletebooks.php on line 81, but i fear there are other problems. Does anyone have any advice as to how to do this better? $result = mysql_query("SELECT * FROM `books` WHERE School ='".$_COOKIE['School']."'"); while($row = mysql_fetch_array($result)){ $temp = $row['BookID']; if(isset($_POST[$temp])){ mysql_query("DELETE FROM books WHERE BookID = '$Delete'); } } if (mysql_affected_rows() == 0) { echo "sorry didn't work"; } else { echo "Books successfully deleted. Return home <a href='../'>here</a>"; }
  2. It still hasn't worked, this time my output (for the header) was; SMHMü«&#8706;Mü«&#8706;BOOKMOBI‡ XX*X:XJXZXjXzXäX öX ™X&#8747;X X ŒöŒúŒ¿ŒÏƒB MOBIˉ¢B&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;p P&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;EXTHx,:Ä æÙÌÏÔ@î@ì@ô@ò@ú@ùÃÕŒœ)SMH<html><head><guide></guide></head><body>
  3. anybody have any ideas?
  4. So i want to save all of the output in my file to a .prc file. I am using ob_start(); and ob_get_contents(); to do this, so all of the echo's in the script are then stored into this file. The file needs a header and a footer, they are attached below, and they have special characters in them. When saved into the prc format, these special characters need to be as are written into the script, but they are changed. Here is an example of what I have going: <?php ob_start(); $header = "SMHMü«∂Mü«∂BOOKMOBI‡ XX*X:XJXZXjXzXäX öX ™X∫X X ŒöŒúŒ¿ŒÏƒB MOBIˉ¢Bˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇp PˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇEXTHx,:Ä æÙÌÏÔ@î@ì@ô@ò@ú@ùÃÕŒœ)SMH<html><head><guide></guide></head><body>"; echo $header; $body = "Hello"; $footer ="<mbp:pagebreak/></body></html>FLISAˇˇˇˇˇˇˇˇFCISƒB Èé"; echo $footer; $out = ob_get_contents(); ob_end_clean(); $file = fopen("smh.prc","w"); file_put_contents("smh.prc",$out); fclose($file); ?> This script works, and creates the .prc file, though when i look at the prc code, the header is this rather than what was in the script: SMHM√º¬´‚àÇM√º¬´‚àÇBOOKMOBI‚Ä° XX*X:XJXZXjXzX√§X √∂X ‚Ñ¢X‚à´X¬†X≈í√∂≈í√∫≈í¬ø≈í√è∆íBMOBI√ã‚Ä∞¬¢BÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáp PÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáÀáEXTHx,:√Ñ √¶√ô√å√è√î@√Æ@√¨@√¥@√≤@√∫@√π√É√ï≈í≈ì A similar thing has happened in the footer. How can i make an exception for these, and save the characters as the special characters, rather than these replacements? I am not sure what encoding these characters are from.
  5. I understand you need to use the mail() command but this just wont work for me, my webserver is with godaddy, and they sent me an email saying that i need to use a relay server to send my mail, how do i set this up or anything?
  6. thanks, so how will that fit into my code?
  7. sorry the last echo should say "deleted book"; not "delete book";
  8. I have been trying to write code that deletes a book from a database if the user provides a BookName, and the corresponding DeletionCode. I then want to provide the user with feedback, telling the user whether they have deleted a book, that is they have provided a deletion code and a book name, or whether they have not deleted a book, because they have entered the wrong bookname or book ID. I thought this code would work, but it seems that the $result variable is always set as TRUE, no matter whether the code has deleted a row or not. What have i done wrong? $result = mysql_query("DELETE FROM books WHERE BookName = '$_POST[bookName]' && DeletionCode = '$_POST[Deletioncode]'"); if(!$result){ die('Invalid query: ' . mysql_error()); } else echo "delete book";
  9. $result = mysql_query("SELECT * FROM books");
  10. I wrote this while loop to cycle through all the rows in my database, and for each row, to create two things, first to echo the name of the book, and the second was to create a button next to it that when clicked, sends the BookID of that row via the post method to the the page at /scas/moreinfo.php . The first echo statement works, and states every book name on the page one after another. For some reason however the form Posts the same book id in every form i think, the value of it being the value in BookID in the last row of the database, in this case 16, so no matter what button is pressed, it sends the value 16. What have I done wrong? while($row = mysql_fetch_array($result)) { echo $row['BookName'] ; echo "<form name='moreinfo' action='/scas/moreinfo.php' method='post'>"; echo "<input type='hidden' name='BookID' value='" .$row['BookID']. "'>"; echo "<input type='submit' value='More Info' />"; echo "<br />"; }
×
×
  • 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.