Jump to content

Bendoon

Members
  • Posts

    17
  • Joined

  • Last visited

Bendoon's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Omg your a lifesaver!!! I knew the problem was small but I couldnt spot it!!! thanks so much man!
  2. Ok think ive narrowed down the problem its: echo "<input type=\"hidden\" name=\"deleteStudent\" value=\"{$row['id']}\">"; The value thats its giving back is always the last value of the database instead of the one allocated to the button being pressed... ive tried a few different things but nothing is working so far
  3. Hi all, im having a problem with deleting users from a student database, the database adds new students fine, the problem is deleting a student from the system. Each student has a button beside the student name labeled "Delete Student Number: (student number here)", but for some reason the code is just always deleting the last entry from the database and not the student for which the button beside their name is pressed... Any ideas? Thanks! <?php echo "<h1>Student Database</h1>"; require_once('output_functions.php'); function is_initial_request() { return ! isset($_POST['submit']); } function output_form() { echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">"; output_textfield('username', 'New Student: ', 'username', 30, 30, '', false); output_submit_button('Add Student'); echo "</form>"; } // Try to connect to database $dbconnection = mysqli_connect( "localhost", "bfm3", "eeshaica", "2017_bfm3" ); if ( ! $dbconnection ) { die('Unable to connect to database'); } // Code to allow the user to enter a new Student if ( ! is_initial_request() ) { $username = $_POST['username']; // Insert into the database $insert_sql = "INSERT INTO students ( username ) VALUES ('{$username}');"; $dbinsert_result = mysqli_query( $dbconnection, $insert_sql ); if ( ! $dbinsert_result ) { die(); } } // Code to allow the user to delete a new Student if ( isset($_POST['delete_row']) ) { $id = $_POST['deleteStudent']; $delete_sql = "DELETE FROM students WHERE id = {$id}"; $dbdelete_result = mysqli_query( $dbconnection, $delete_sql ); } $retrieve_sql = "SELECT * FROM students"; $dbretrieve_result = mysqli_query( $dbconnection, $retrieve_sql ); if ( ! $dbretrieve_result ) { die(); } if ( mysqli_num_rows( $dbretrieve_result ) != 0 ) { while ( $row = mysqli_fetch_assoc( $dbretrieve_result ) ) { echo $row['id']; echo "<table>"; echo "<form action=\"{$_SERVER['PHP_SELF']}\" name=\"delete_student\" method=\"POST\">"; echo "<tr><td><p><input type=\"submit\" name=\"delete_row\" value=\"Delete Student Number: {$row['id']}\" /></p></td><td><b>Student ID NO.</b> {$row['id']}</td></tr>"; echo "<input type=\"hidden\" name=\"deleteStudent\" value=\"{$row['id']}\">"; echo "<tr><td></td><td><b>Student Name:</b> {$row['username']}</td></tr>"; echo "</table>"; echo "<br>"; } } output_form(); // Free up memory and close the database connection mysqli_free_result( $dbretrieve_result ); mysqli_close( $dbconnection ); ?>
  4. ok so the program needs me to have text in the textarea for the button to display the text thats in it, its like the variable im storing the entered string into is wiping when i press the decrypt button.... code : if ( isset($_POST["decrypt"]) ) { echo $userText; } and this is how im getting the data above : if( isset($_POST["userText"]) && $_POST["key"] ) { if( empty($_POST["userText"]) || empty($_POST["key"]) ) { die("Please enter a key between 1 and 125 and enter some secret message for me to encrypt!</br>"); } $userText = $_POST["userText"]; $key = $_POST["key"]; }
  5. OK so yeah got that working to some extent didnt realise it was similar, but the button will only display the text if the text is in the textarea and then the button is pressed. It seems like when i store the string into a variable when the decrypt button is pressed the value is wiped?
  6. Hi, Im making a basic encryption program and have the encryption side working, but want to add in the feature to "decrypt" the encoded message if need be. Im using the POST method so that my program outputs to the same page that the form is on. I have tried the following : if ( isset($_POST["decrypt"]) ) { echo $_SESSION[$old_ascii]; } if ( $key < 1 || $key > 125 ) { echo "Please enter a key between 1 and 125</br>"; } else { foreach ( $userText as $old_ascii ) { echo $new_ascii = chr(imp_circular_position(32,126, ord( $old_ascii ), $key)); $_SESSION[$old_ascii] .= $old_ascii; } All i really want to do is store the users first entered text and relay that when the decrypt button is pressed the code for that is : <div id="buttons"> <input type="submit" value="Encrypt" name="Encrypt" /> <input name="decrypt" type="submit" value="De-crypt" /> </div> if( isset($_POST["userText"]) && $_POST["key"] ) { if( empty($_POST["userText"]) || empty($_POST["key"]) ) { die("Please enter a key between 1 and 125 and enter some secret message for me to encrypt!</br>"); } $userText = $_POST["userText"]; $key = $_POST["key"]; } If anyone could help with this id really appreciate it , so all i want to do is store the text first entered in a variable if I was using GET then it would be easy but this is my first time outputting text to the same page as the form and am a little lost! Thanks!
  7. OK i think its because where i have $startIndex on this line: $sub = substr($textarea, $startIndex, $ordernumber ); $startIndex contains an actual character and not a number. Is there a way to instead of using substr to extract the character in that space extract the number of how many characters it is in from the start? So if "hello" was the string and "e" was selected it would contain the number "2" ?
  8. So ive got a loop and basically the loop adds a character to the end of $finalString after each loop, i want to then grab the last character of that $finalString and thats what im attempting to do
  9. the php manual states i can have 3 parameters
  10. ah ok yes there is another line i use the substr but that wasnt giving trouble until i put in the new substr. $sub = substr($textarea, $startIndex, $ordernumber ); is line 34 why is that giving the error then
  11. Hi im trying to use the substr function in php. I have a string called $finalString and im trying to grab the last character of that string the line of code im using is : $startIndex = substr($finalString, -1); it wont work giving the error : Warning: substr() expects parameter 2 to be long, string given in /users/2017/bfm3/public_html/cs1109/lab10/markovnew.php on line 34
  12. yayyyy thanks a million! you fixed it . I thought that ++ and +1 were exactly the same . Thanks for helping me really appreciate it! Ill be using this site more often
  13. $textarea = trim ( $_GET['textarea'] ); $ordernumber = $_GET['ordernumber']; $textarea = strtolower ( $textarea ); $string = rand(0, strlen($textarea)-1); $string = $textarea[$string]; $textarray = str_split( $textarea ); $count = 1; $tempArr=array(); while ( $count < 200 ) { foreach ( $textarray as $k => $char ) { if ( $char == $string && array_key_exists($k++, $textarray) ) { if (isset($textarray[$k++])) { $tempArr[]=$textarray[$k++]; } } } if (count($tempArr) > 0) { echo $string=$tempArr[rand(0, count($tempArr)-1)]; } $tempArr=array(); $count++; } So this is what i have now, but the error still persists that i began with . Initializing the variable did indeed get rid of the other error
  14. Hi, thanks for the reply! I tried what you said : foreach ( $textarray as $k => $char ) { if ( $char == $string && array_key_exists($k++, $textarray) ) { if (isset($textarray[$k++])) { $tempArr[]=$textarray[$k++]; } } } But it gives Notice: Undefined variable: tempArr in /users/markov.php on line 37 And Notice: Undefined offset: 5 in /users/markov.php on line 32 The overall goal is create a chat bot that will take any input of text and that will chat back with random text taken from the sentences entered at the start
  15. line 30 is : $tempArr[]=$textarray[$k++];
×
×
  • 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.