Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving some trouble getting my classes to work together
    primarykey
    data
    text
    <p>I am working on a simple ruby assignment and I am getting and internal server error. I am assuming it is in how I am tying my classes together.</p> <p>EDIT: I updated it and now I am just not inserting to the database. The point of issue is where I call "result = @dbh.query(query)"</p> <p>This is my first page:</p> <pre><code>#!/usr/local/bin/ruby require 'cgi' require 'mysql' load 'pizzaClass.cgi' cgi = CGI.new puts "Content-type: text/html\n\n" db = Database_obj.new pizza = Pizza.new(db) submit = cgi['submit'] size = cgi['size'] topping1 = cgi['topping1'] topping2 = cgi['topping2'] name = cgi['name'] if submit == 'Order' pizza.new_pizza(size,topping1,topping2,name) end puts &lt;&lt;HTML &lt;form name="pizza" id="pizza" method="post" action="db.cgi"&gt; &lt;select name="size" id="size"&gt; &lt;option value="small"&gt;Small&lt;/option&gt; &lt;option value="medium"&gt;Medium&lt;/option&gt; &lt;option value="large"&gt;Large&lt;/option&gt; &lt;/select&gt; &lt;br /&gt;&lt;br /&gt; &lt;label for="topping1"&gt;Topping 1: &lt;input type="text" name="topping1" id="topping1" /&gt;&lt;/label&gt; &lt;br /&gt;&lt;br /&gt; &lt;label for="topping2"&gt;Topping 2: &lt;input type="text" name="topping2" id="topping2" /&gt;&lt;/label&gt; &lt;br /&gt;&lt;br /&gt; &lt;label for="name"&gt;Name: &lt;input type="text" name="name" id="name" /&gt;&lt;/label&gt; &lt;br /&gt;&lt;br /&gt; &lt;input type="submit" name="submit" id="submit" value="Order" /&gt; &lt;/form&gt; HTML </code></pre> <p>This is my pizzaClass.cgi</p> <pre><code> class Database_obj attr_accessor :dbh def initialize() @dbh = Mysql.real_connect("localhost", "ljackson42001", "password", "ljackson42001") end def query_db(query) result = @dbh.query(query) end def get_results() result.each do |row| puts row end end end class Pizza def initialize(db) @dbh=db end def new_pizza(size,topping1,topping2,name) query = "INSERT INTO pizza VALUES(0,#{size},#{topping1},#{topping2},#{name})" @dbh.query_db(query) puts "two" end end </code></pre> <p>Any help would be appreciated, <br /> Levi</p>
    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.
    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