Jeg er ny i jQuery, og javascript generelt, men har "snuset" lidt til det.
Jeg vil gerne lave form validering og lave et ajax kald, til den side hvor jeg gemmer dataene i mysql, med jQuery.
Men jeg går i stå her. Kan ikke finde svar på hvorfor den ikke gemme noget?
Valideringen vil jeg lave når jeg kan gemme data.
Dette er
process.php- <?php
- include('functions.php');
-
- if ($_GET['DO'] == "INSERT") {
-
- $data = array_map("check_input_mysql_injection", $_POST);
-
- sql_execute ("INSERT", "structure_options", $data, $where);
-
- } elseif ($_GET['DO'] == "UPDATE") {
-
- $data = array_map("check_input_mysql_injection", $_POST);
-
- $where = "id = '1''";
-
- sql_execute ("UPDATE", "structure_options", $data, $where);
-
- echo json_encode(array("success" => "Det lykkedes!", "error" => "Fejl!"));
-
- } elseif ($_GET['DO'] == "DELETE") {
-
- $where = "id = '1''";
-
- $data = array_map("check_input_mysql_injection", $_POST);
-
- sql_execute ("DELETE", "structure_options", $data, $where);
-
- }
-
- ?>
Dette er siden med min form.
- <?php
- include("inc/functions.php");
-
- $options_result = sql_execute ("SELECT", "structure_options", "", "");
-
- $options_row = mysql_fetch_array($options_result);
- ?>
-
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
-
- <script type="text/javascript">
- $(document).ready(function() {
-
- //if submit button is clicked
- $('#submit1').click(function () {
-
- var_form_data = $(this).serialize();
-
- $.ajax({
-
- //POST method is used
- type: "POST",
-
- //this is the php file that processes the data
- url: "inc/process.php?DO=UPDATE",
-
- dataType: "json",
-
- //pass the data
- data: var_form_data,
-
- //Do not cache the page
- cache: false,
-
- });
-
- })
-
- return false;
-
- });
- </script>
-
-
-
-
- <form id="form1" method="post">
-
- <table border="1" width="100%">
- <tr>
- <td>Titel</td>
- <td><input type="text" size="34" name="site_title" value="<?php echo $options_row["site_title"]; ?>" /></td>
- </tr>
- <tr>
- <td>Overskrift</td>
- <td><input type="text" size="34" name="site_header" value="<?php echo $options_row["site_header"]; ?>" /></td>
- </tr>
- <tr>
- <td>URL</td>
- <td><input type="text" size="34" name="site_url" value="<?php echo $options_row["site_url"]; ?>" /></td>
- </tr>
- </table>
-
- <input id="submit1" type="submit" value="Gem" />
-
- </form>
-
- <form id="form2" method="post">
-
- <table border="1" width="100%">
- <tr>
- <td>Beskrivelse</td>
- <td><input type="text" size="34" name="meta_description" value="<?php echo $options_row["description"]; ?>" /></td>
- </tr>
- <tr>
- <td>Keywords</td>
- <td><input type="text" size="34" name="meta_keywords" value="<?php echo $options_row["keywords"]; ?>" /></td>
- </tr>
- <tr>
- <td>Ejer</td>
- <td><input type="text" size="34" name="meta_author" value="<?php echo $options_row["owner"]; ?>" /></td>
- </tr>
- </table>
-
- <input id="submit2" type="submit" value="Gem" />
-
- </form>
Her ligger scriptet
Indlæg senest redigeret d. 20.07.2012 07:12 af Bruger #10114