I come to you bearing a tricky pickle that has been stumping me for a good while now. Days! Weeks! Months! YEARS! Okay, so maybe not quite that long. But long enough to leave me incredibly frustrated.
I had the idea to create a personal web-based recipe box through my site so that when I come across something online, I can submit it to my recipe box, and I don’t have to worry about creating logins at every place I find a recipe.
Because of this, I had to find a way to tackle the fact that there isn’t a set number of ingredients or procedure steps, so I think building something in AJAX is probably the path my solution lies in.
So I’m learning AJAX.
This is where my problem comes in.
I created a simple form. Achingly simple. One field, one button. Just to see if I could get the database to update.
The HTML code:AJAX Recipe Form
AJAX Recipe Form
Inserting recipe via slick AJAX. Hold on just a sec…
Success! Your recipe has been sent.
PHP Code:<? //Connect to Database $database_name = "recipes"; // Set this to your Database Name $database_hostname = "recipes.julisana.com"; //set this to your hostname //(if it is on the same machine, use 'localhost' to save time in DNS lookup) $database_username ="********"; // Set this to your MySQL username $database_password ="********"; // Set this to your MySQL password $db = mysql_connect($database_hostname, $database_username, $database_password) or die("Could not connect to the host!"); mysql_select_db($database_name) or die("Could not connect to the database"); //Register your POST variables $name = $_POST['yourRecipeName']; //Insert those into the database $InsertQuery = "INSERT INTO test (name) VALUES (" . $name . ")"; $result = mysql_query($InsertQuery); mysql_close($db); if ($InsertQueryResult) $return_value = "Insertion Successful!"; else $return_value = "Insertion Failed."; // Include Zip for debugging purposes echo $return_value; // This will become the response value for the XMLHttpRequest object ?>
After getting so frustrated at things not working, I started throwing in alert boxes left right and sideways to try and catch where my error was taking place. First, I put one checking my XMLHttpRequest object. It never threw anything back at me, so I took it back out.
Second, I put one to display the xmlhttp.responseText data. This gave me some very interesting results, because the alert box that popped up had the HTTP 503 error data in it.
So what can I do to get rid of this error?