...

View Full Version : Setup WAMPSERVER?



fleewood
08-11-2010, 10:50 PM
Hi, I have just downloaded WAMPSERVER 2.0i and I don't think it's working properly, I have Windows 7 64bit and I don't know if thats causing the problem. I am making a script with jquery and php, the php script keeps coming up with an error in Firebug.

I click the submit buttom on my form and in the Firebug box it shows all the php script and an error underneath saying

"no element found

?> submit_to_db.php(line 18)"


These are the main codes


index.html


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>

<script type="text/javascript">
$(function() {
$('#submit').click(function() {
$('#container').append('<img src="loading.gif" alt="Currently Loading" id="loading" />');

var name = $('#name').val();
var email = $('#email').val();
var comments = $('#comments').val();

$.ajax({
url: 'submit_to_db.php',
type: 'POST',
data: 'name=' + name + '&email=' + email + '&comments=' + comments,

success: function(result) {

console.log(result);

}

});

return false;

});
});
</script>

</head>
<body>
<form method="post" action="submit_to_db.php">
<div id="container">
<label for="name">Name:</label>
<input type="text" name="name" id="name" />

<label for="email">E-Mail:</label>
<input type="text" name="email" id="email" />

<label for="comments">Comments:</label>
<textarea name="comments" id="comments" rows="5" cols="35"></textarea>
<br/>
<input type="submit" name="submit" id="submit" value="Go!" />
</div>
</form>


submit_to_db.php


<?php

$conn = new mysqli('localhost', 'root', '', 'my_db');
$query = "INSERT into comments(name, email, comments) VALUES (?, ?, ?)";

$stmt = $conn->stmt_init();
if($stmt->prepare($query)) {
$stmt->bind_param('sss', $_POST['name'], $_POST['email'], $_POST['comments']);
$stmt->execute();
}

if($stmt) {
echo "Thank you. We'll be in touch with you shortly!";
} else {
echo "There was a problem. Please try again later.";
}

?>


Thanks

Fou-Lu
08-11-2010, 11:14 PM
Sounds like your Apache is not configured to execute .php file using PHP.
Open your httpd.conf file (located in you're Apache/conf directory), and search for AddType. If you don't find one thats like so:


AddType application/x-httpd-php .php

Go ahead and add that and restart your apache service.

Try that and post back if its still a problem. The firebug error is because its trying to interpret the <?php ....?> as a tag, which of course doesn't exist.


Otherwise, it looks ok, so I'm fairly certain this is an Apache configuration issue, so I'll move it to the appropriate forum.

fleewood
08-11-2010, 11:24 PM
I searched for that bit of text and it was already there. What else could be the problem?

Fou-Lu
08-11-2010, 11:25 PM
When you access the page, you are doing so from a web-browser and typing it as a url right? So its http:// and not file://?

fleewood
08-14-2010, 08:35 PM
it doesn't work when I type http:// infront of it, how do I make it work?

fleewood
08-14-2010, 08:45 PM
doesnt matter i've got it. But im getting an error now saying



console is not defined
console.log(result) submit_to_db(line 26)

fleewood
08-14-2010, 08:50 PM
haha no thats fine aswell, i didnt enter anything into the field!! thanks for the help.

Fou-Lu
08-14-2010, 09:20 PM
So you got it all sorted out?
If I had to guess it, you probably just didn't have either http://127.0.0.1 or http://localhost in the address. This is required when processing PHP through your localsystem apache (PHP is also runnable from the command line, but you couldn't add your JS directly to it).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum