Jump to content

phpnoob1991

Members
  • Posts

    10
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

phpnoob1991's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. This is the result (original HTML form contained two rows from the database): Array ( [chapter] => Array ( [0] => Array ( [id] => 132 ) [1] => Array ( [name] => MIT ) [2] => Array ( [password] => New Password ) [3] => Array ( [id] => 133 ) [4] => Array ( [name] => Harvard ) [5] => Array ( [password] => New Password ) ) ) Seeing this, I am beginning to think the problem is with the way I am setting up the multidimensional array... I was originally hoping for something like this: Array ([chapter] => Array ( [0] => Array ([id] =>132 [name] =>some name [password] => some password) [1] => Array ([id] => 133 [name] => some name [password] => some password))
  2. WOW, clearly there is a BIG problem somewhere. This is what I get: UPDATE chapters SET name=, password= WHERE id=132UPDATE chapters SET name=MIT, password= WHERE id=UPDATE chapters SET name=, password=New Password WHERE id=UPDATE chapters SET name=, password= WHERE id=133UPDATE chapters SET name=Harvard, password= WHERE id=UPDATE chapters SET name=, password=New Password WHERE id= I don't understand, is the problem with the way I set up the multidimensional array or with the way I am handing it in ChaptersUpdate.php?
  3. Eeek, sorry, how would I do that? I am fairly new to PHP and MySQL, and am learning on the go. Would I just use the regular "echo"?
  4. I have a MySQL database with the table "chapters". This table has three columns: id, name, password. I am automatically outputting the contents of this table via an HTML form (it's an update page where the user can edit all of the values). Here's the code for the output: <table> <?php while ($row=mysql_fetch_array($result)) { echo "<tr id='chapter-{$row['id']}' chapter-id='{$row['id']}'>"; echo "<td>"; echo "<input type='text' name='chapter[][id]' value='{$row['id']}'>"; echo "</td>"; echo "<td>"; echo "<input type='text' name='chapter[][name]' value='{$row['name']}'>"; echo "</td>"; echo "<td>"; echo "<input type='text' name='chapter[][password]' value='New Password'>"; echo "</td>"; echo "<td>"; echo "<img class='delete-chapter' src='reject-button.png' alt='Delete Button'>"; echo "</td>"; echo "</tr>"; } ?> </table> I am passing all of that information into ChaptersUpdate.php via a submit button that's on the bottom of that form. The idea is that ChaptersUpdate.php should look at all of the information within $_POST and update the "chapters" table so that it reflects the new values that the user put in. Here's the PHP code: <?php include 'database_login.php'; foreach ($_POST['chapter'] as $chapter_id => $chapter_info) { mysql_query("UPDATE chapters SET name={$chapter_info['name']}, password={$chapter_info['password']} WHERE id={$chapter_info['id']}"); } ?> Only problem is that ChaptersUpdate.php just doesn't work...the "chapters" table goes completely unchanged. There is no error_log being generated, so I really don't think there's a problem connecting to the database. Any ideas why it's not working? Thanks in advance!
  5. All is now fixed and working! The problem was me using .on() in the wrong script (I was putting it in the script associated with creating new entries in the form, not the script that handled the delete buttons).
  6. Right, but I'd only like to refresh the appropriate div/form, not the whole page
  7. I did some more research, and it seems like this person had the exact same problem: http://stackoverflow.com/questions/11589576/jquery-functions-not-working-after-using-load-to-refresh-div-content Basically, because the delete button images are being generated dynamically, they lose the attached event when they reset. The recommended fix is to use .on(), but I am not exactly sure how to implement that / use it within my current code...any hints? This is what I thought would work, but it didn't: <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> <script type="text/javascript"> jQuery(document).ready(function() { $('#current_chapters').on('click', '.delete-chapter', function(){ jQuery.ajax({ type: 'post', url: "http://www.lukaspleva.com/MoneyThink/CreateNewChapter.php", dataType: 'text', data: $('#create_new_chapter').serialize(), success: function(msg){ alert(msg); $('#current_chapters').load('NationalAdmin.php #current_chapters'); } }); return false; }); }); </script>
  8. Hmmm, so are you suggesting it should actually be: $('form#update_existing_chapters').load(); ? I tried that, but unfortunately that doesn't fix the problem. Sorry, I am pretty new to jQuery, and am learning on the go. Am I missing something basic?
  9. Here's the page in question: http://www.lukaspleva.com/MoneyThink/NationalAdmin.php If you go to that page, you'll see that you can remove chapters from the system just by clicking the red cross button next to each row. As you do that, the chapter counter at the top automatically updates. Problem arises when you add a new chapter to the mix via the section at the top. The new section gets added and the counter updates, but the delete button stops working. Looking at what's happening with the code, it seems like the .load() function is creating an additional form="update_existing_chapters" WITHIN the form id="update_existing_chapters" that's already on the page. Basically, instead of just refreshing the div or the form, it creates a duplicate copy within it, which breaks the code. The relevant piece of code is: $('form#update_existing_chapters') .load('NationalAdmin.php form#update_existing_chapters'); Any idea why it's creating a duplicate element/section rather than just refreshing the current one? Thank you in advance!
  10. Hi everyone, First time here, so I am hoping one of y'all will be able to help me with my problem. Quick background: I have a basic HTML form. I'd like to store all of the data from that form in a MySQL database. I was able to do this with PHP, but I don't want the page to refresh, so naturally I turned to AJAX. I have ZERO exposure to AJAX, and am learning on-the-go, so apologies if I am making an elementary mistake. Anyway, here's the code of the HTML page with the input form and the AJAX code at the very end. My main problem: upon clicking the "apply" button, I receive the "failure" dialog box, even though the data DOES get stored inside my database. <form> <table cellpadding="10"> <tr> <td><b>Chapter:</b></td> <td><input type="text" name="chapter"></td> </tr> <tr> <td>First Name:</td> <td><input type="text" name="first"></td> <td>Last Name:</td> <td><input type="text" name="last"></td> </tr> <tr> <td>Gender:</td> <td> <select name="gender"> <option value="male">Male</option> <option value="female">Female</option> </select> </td> <td>Ethnicity:</td> <td> <select name="ethnicity"> <option value="white">White/Caucasian</option> <option value="hispanic">Hispanic</option> <option value="asian">Asian/Pacific Islander</option> <option value="native_american">Native American Indian</option> <option value="other">Other</option> </td> </tr> <tr> <td>Year in School</td> <td> <select name="year_in_school"> <option value="freshman">Freshman</option> <option value="sophomore">Sophomore</option> <option value="junior">Junior</option> <option value="senior">Senior</option> </select> </td> <td>Phone Number:</td> <td><input type="text" name="phone"></td> </tr> <tr> <td>Email Address:</td> <td><input type="text" name="email"></td> <td>Street Address:</td> <td> <input type="text" name="address"> </td> </tr> <tr> <td>Apt/Suite:</td> <td> <input type="text" name="suite_num"> </td> <td>City:</td> <td> <input type="text" name="city"> </td> </tr> <tr> <td>State:</td> <td> <select name="state"> <option value="Alabama">Alabama</option> <option value="Alaska">Alaska</option> <option value="Arizona">Arizona</option> <option value="Arkansas">Arkansas</option> <option value="California">California</option> <option value="Colorado">Colorado</option> <option value="Connecticut">Connecticut</option> <option value="Delaware">Delaware</option> <option value="Florida">Florida</option> <option value="Georgia">Georgia</option> <option value="Hawaii">Hawaii</option> <option value="Idaho">Idaho</option> <option value="Illinois">Illinois</option> <option value="Indiana">Indiana</option> <option value="Iowa">Iowa</option> <option value="Kansas">Kansas</option> <option value="Kentucky">Kentucky</option> <option value="Louisiana">Louisiana</option> <option value="Maine">Maine</option> <option value="Maryland">Maryland</option> <option value="Massachusetts">Massachusetts</option> <option value="Michigan">Michigan</option> <option value="Minnesota">Minnesota</option> <option value="Mississippi">Mississippi</option> <option value="Missouri">Missouri</option> <option value="Montana">Montana</option> <option value="Nebraska">Nebraska</option> <option value="Nevada">Nevada</option> <option value="New Hampshire">New Hampshire</option> <option value="New Jersey">New Jersey</option> <option value="New Mexico">New Mexico</option> <option value="New York">New York</option> <option value="North Carolina">North Carolina</option> <option value="North Dakota">North Dakota</option> <option value="Ohio">Ohio</option> <option value="Oklahoma">Oklahoma</option> <option value="Oregon">Oregon</option> <option value="Pennsylvania">Pennsylvania</option> <option value="Rhode Island">Rhode Island</option> <option value="South Carolina">South Carolina</option> <option value="South Dakota">South Dakota</option> <option value="Tennessee">Tennessee</option> <option value="Texas">Texas</option> <option value="Utah">Utah</option> <option value="Vermont">Vermont</option> <option value="Virginia">Virginia</option> <option value="Washington">Washington</option> <option value="West Virginia">West Virginia</option> <option value="Wisconsin">Wisconsin</option> <option value="Wyoming">Wyoming</option> </select> </td> <td>Zip Code:</td> <td> <input type="text" name="zip_code"> </td> </tr> <tr> <td>Cumulutative GPA:</td> <td><input type="text" name="gpa"></td> <td>Major/Area of Study:</td> <td><input type="text" name="major"></td> </tr> <tr> <td>Twitter handle:</td> <td> <input type="text" name="twitter_handle"> </td> </tr> <tr> <td colspan="2"> <p>Please describe any relevant teaching experience:</p> <textarea rows="6" cols="45" name="teaching_experience"> </textarea> </td> <td colspan="2"> <p>Why do you want to join Moneythink?</p> <textarea rows="6" cols="43" name="why_moneythink"> </textarea> </td> </tr> </table> <table> <tr> <td><input type="submit" value="Apply"></td> <td><input type="reset" value="Clear"></td> </tr> </table> </form> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> <script type="text/javascript"> $(function() { $('form').bind('submit', function(){ $.ajax({ type: 'post', url: "/InsertNewMentor.php", dataType: 'html', data: $('form').serialize(), ssuccess: function(){ alert('success'); }, error: function(){ alert('failure'); } }); return false; }); }); </script> And here's InsertNewMentor.php <?php $username=""; $password=""; $database=""; $first = $_POST['first']; $last = $_POST['last']; $email = $_POST['email']; $gpa = $_POST['gpa']; $year = $_POST['year_in_school']; $address = $_POST['address']; $phone = $_POST['phone']; $gender = $_POST['gender']; $ethnicity = $_POST['ethnicity']; $year_in_school = $_POST['year_in_school']; $suite_number = $_POST['suite_num']; $city = $_POST['city']; $state = $_POST['state']; $zip_code = $_POST['zip_code']; $major = $_POST['major']; $twitter_handle = $_POST['twitter_handle']; $why_moneythink = $_POST['why_moneythink']; $teaching_experience = $_POST['teaching_experience']; $date = date("m/d/Y"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO students VALUES ('','$address','$phone','$first','$last','$gender', '$ethnicity', '$year_in_school', '$email', '$suite_number','$city','$state','$zip_code','$major','$gpa','$twitter_handle','$why_moneythink','$teaching_experience','pending','$date')"; mysql_query($query); mysql_close(); ?>
×
×
  • 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.