w1ww Posted January 27, 2008 Share Posted January 27, 2008 Hello, I'm trying to add some records to a database but it's not working and I don't why.. Can somebody check the code, please? I think the error in the query because I always get the die function error "There is a problem with our...". if (isset($_POST['continue'])){ // Caso contrario processa o form include("db.php"); // open connection $connection = mysql_connect($host, $user, $pass) or die ("No connection!"); // select database mysql_select_db($db) or die ("No database?!"); // variaveis $fname = mysql_escape_string($_POST['fname']); $lname = mysql_escape_string($_POST['lname']); $mail = mysql_escape_string($_POST['mail']); $logoname = mysql_escape_string($_POST['logoname']); $slogan = mysql_escape_string($_POST['slogan']); $description = mysql_escape_string($_POST['descri']); $website = mysql_escape_string($_POST['website']); $other = mysql_escape_string($_POST['other']); // create query $query = "INSERT INTO order (name, lastName, email) VALUES ('$fname', '$lname', '$mail')"; $result = mysql_query($query) or die ("There is a temporary problem with our service. Please try again later."); $orderid = mysql_insert_id(); $query = "INSERT INTO projects (logoText, slogan, description, other, website, orderID) VALUES ('$logoname', '$slogan', '$description' ,'$other' ,'$website', '$orderid')"; $result = mysql_query($query) or die ("There is a temporary problem with our service. Please try again later."); // close connection mysql_close($connection); } Thanks! Link to comment https://forums.phpfreaks.com/topic/87992-solved-phpmysql-problem/ Share on other sites More sharing options...
AndyB Posted January 27, 2008 Share Posted January 27, 2008 ORDER is a reserved word in MySQL. You really shouldn't use reserved words as table names or field names. You could replace order with `order`, i.e. add `backticks` but the better solution is to change the name of your table to something that isn't a reserved word. As a general rule, use helpful error messages during development. For example, this is much more helpful: $result = mysql_query($query) or die("Error ". mysql_error(). " with query ". $query); Link to comment https://forums.phpfreaks.com/topic/87992-solved-phpmysql-problem/#findComment-450218 Share on other sites More sharing options...
w1ww Posted January 27, 2008 Author Share Posted January 27, 2008 Oh! Thanks! And I just spent 3 hours on this! Link to comment https://forums.phpfreaks.com/topic/87992-solved-phpmysql-problem/#findComment-450220 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.