<?php
mysql_connect('localhost', 'username', 'password') or die ("Couldn't connect to database ");
mysql_select_db('movies') or die("Can't select db ". mysql_error());;
$isbn = $_POST['txtISBN'];
$title = $_POST['txtTitle'];
$rating = $_POST['txtRating'];
$query = "insert into dvds (isbn, title, rating)
values('$isbn', '$title', '$rating')";
$result = mysql_query($query) or die("can't create query ". mysql_error());
if (mysql_affected_rows() == 1) {
echo '<p>Your information has been recorded</p>';
} else {
error_log(mysql_error());
echo '<p>Something went wrong</p>';
}
}
?>
The connection is working fine, the values are getting into the variables just fine. The problem is that it isn't inserting into the database and it's also not printing either condition from the "if statement".
I'm getting the expected results from the variables. I also tried changing the insert, and that didn't work either. I've made a simple select statement work just fine, it's just this f'n insert.
flann wrote:I'm getting the expected results from the variables. I also tried changing the insert, and that didn't work either. I've made a simple select statement work just fine, it's just this f'n insert.
Do you have the correct privileges to insert into the database? (Just to make sure )
If you're asking if it works when I do the insert statement in the command line, then yes, my original insert statement worked fine in the command line.
So you're getting no output at all? Is this code in between other code so that any output might be hidden? Do you have PHP set to display errors in case there's a syntax error or something similar hanging about in the PHP?
Cool - if this is your development machine it would probably be an idea to turn display_errors on in your php.ini so that it's a bit easier to see when things are wonky