PHP Newby Posted November 22, 2006 Share Posted November 22, 2006 I'm a bit new to PHP and I have a question. It might be a little hard to answer but, here it is.This is the snipet I'm having problems with:[code]CODE $name = $_POST['name']; $price = $_POST['price']; $item = $_POST['item']; $date = $_POST['date']; $query = "INSERT INTO `secondlifetrans` ( `Name` , `Item` , `Price` , `Date` )VALUES ('$name', '$item', '$price', '$date');";[/code]This, for some reason, outputs empty strings into the sql database, but I'm sure all the variables are completly defined. Any help, anyone? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted November 22, 2006 Share Posted November 22, 2006 The manual states:[quote]The query string should not end with a semicolon.[/quote]http://www.php.net/mysql_query#AEN116010 Quote Link to comment Share on other sites More sharing options...
jawapro Posted November 22, 2006 Share Posted November 22, 2006 Comment out the SQL part and echo:$name $price$item $date to make sure you are actually getting the values from the previous script.-------Modify-------Not really sure that the semi-colon causes the problem. I know it isnt needed - but I didnt think it killed it either. Quote Link to comment Share on other sites More sharing options...
PHP Newby Posted November 22, 2006 Author Share Posted November 22, 2006 Okay thanks very much. If I come across further problems I will reply this thread. Quote Link to comment Share on other sites More sharing options...
jawapro Posted November 22, 2006 Share Posted November 22, 2006 Did it fix the problem? Quote Link to comment Share on other sites More sharing options...
trq Posted November 22, 2006 Share Posted November 22, 2006 [quote]The query string should not end with a semicolon.[/quote]Why would the manual say that? Ending an SQL query with a semicolon is perfectly valid SQL. The php manual should stick to php. Quote Link to comment Share on other sites More sharing options...
jawapro Posted November 22, 2006 Share Posted November 22, 2006 It says that because when you run SQL from PHP it ADDS a semi-colon at the end.So you'd end up with ;;.But I dont think it kills it - its just not necessary Quote Link to comment Share on other sites More sharing options...
PHP Newby Posted November 22, 2006 Author Share Posted November 22, 2006 No, It did not fix the problem. Well, changing everything to $_GET worked, but it outputs everything into one column now.... Quote Link to comment Share on other sites More sharing options...
jawapro Posted November 23, 2006 Share Posted November 23, 2006 If you were using GET to post the variables and using POST to read them it wouldnt have worked.When you say it outputs everything into one column what do you mean?JP Quote Link to comment Share on other sites More sharing options...
ataria Posted November 23, 2006 Share Posted November 23, 2006 How is the page set up? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.