Note that there are some explanatory texts on larger screens.

plurals
  1. POForm post not working
    primarykey
    data
    text
    <p>I have coded the following and its posting the data as I can see it in console. However, it does not seem to add to the database. I think it could be my condition in the process.php file for action: add_new, but I'm not sure.</p> <p>Not a huge person on PHP so unsure how to see why it's failing but it's returning successfully to the AJAX, I think but not adding to database, so I assume it might be what I said above.</p> <pre><code>if($_POST['action'] == "add_new"){ </code></pre> <p>jQuery and Form:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function(){ $('div.success').hide(); $("form#add_new").submit(function() { var started = "&lt;?php echo time(); ?&gt;"; var duration = $('#duration').val(); var ticket_price = $('#ticket_price').val(); var win_percentage = $('#win_percentage').val(); var description = $('#description').val(); var available = $('#available').val(); var action = "add_new"; $.ajax({ type: "POST", url: "/admin/process.php", data: { started: started, duration: duration, ticket_price: ticket_price, win_percentage: win_percentage, description: description, available: available, action: action }, dataType: 'json', success: function(data){ $('form#add_new').hide(function(){$('div.success').fadeIn();}); } }); return false; }); }); </code></pre> <p></p> <pre><code>&lt;div class="success"&gt;successfully added new ticket&lt;/div&gt; &lt;form id="add_new" method="post" class="form-horizontal"&gt; &lt;fieldset&gt; &lt;div class="control-group"&gt; &lt;label for="duration" class="control-label"&gt;Duration (days)&lt;/label&gt; &lt;div class="controls"&gt; &lt;input type="text" id="duration" class="input-xlarge" value="" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="control-group"&gt; &lt;label for="ticket_price" class="control-label"&gt;Ticket Price&lt;/label&gt; &lt;div class="controls"&gt; &lt;input type="text" id="ticket_price" name="ticket_price" class="input-xlarge" value="" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="control-group"&gt; &lt;label for="available" class="control-label"&gt;Available to be Won(%)&lt;/label&gt; &lt;div class="controls"&gt; &lt;input type="text" id="available" name="available" class="input-xlarge" value="" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="control-group"&gt; &lt;label for="win_percentage" class="control-label"&gt;Percentage of Winners&lt;/label&gt; &lt;div class="controls"&gt; &lt;input type="text" id="win_percentage" name="win_percentage" class="input-xlarge" value="" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="control-group"&gt; &lt;label for="description" class="control-label"&gt;Description&lt;/label&gt; &lt;div class="controls"&gt; &lt;textarea rows="4" id="description" name="description" class="input-xlarge"&gt;&lt;/textarea&gt; &lt;span class="help-block"&gt;Automatic resize&lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="control-group"&gt; &lt;div class="controls"&gt; &lt;button class="btn btn-gebo" type="submit"&gt;Save changes&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;/form&gt; </code></pre> <p><code>process.php</code>:</p> <pre><code>&lt;?php include "../utils.php"; // Add new raffle ticket if($_POST['action'] == "add_new"){ $started = $_POST['started']; $duration = $_POST['duration']; $ticket_price = $_POST['ticket_price']; $win_percentage = $_POST['win_percentage']; $description = mysql_real_escape_string($_POST['description']); $available = $_POST['available']; my_query("INSERT INTO " . $db_prefix . " (lotteries(started, duration, ticket_price, win_percentage, description,available) values) VALUES ('$started','$duration','$ticket_price','$win_percentage','$description','$available')"); mysql_query($add_to_shelf) or die(mysql_error()); } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload