dadamssg Posted January 18, 2009 Share Posted January 18, 2009 so im trying to learn i can't..for the life of me..figure out why i cant execute this..its a simple two field form. i get an unexpected T_VARIABLE error on the defining the $sql line <?php /* File: processtest.php*/ include("caneck.inc"); $title = $_POST['title']; $description = $_POST['description']; $cnx = mysqli_connect($host,$user,$passwd,$dbname) $sql = "INSERT INTO test (title, description) VALUES ('$title','$description')"; $result = mysqli_query($cnx,$sql) or die ("Couldn't execute query."); include("tesdisplay.inc"); Print "The title, $title, and the description, $description, has been entered."; ?> Link to comment https://forums.phpfreaks.com/topic/141293-whats-wrong-with-my-query/ Share on other sites More sharing options...
trq Posted January 18, 2009 Share Posted January 18, 2009 The line before that one is missing the closing ; Link to comment https://forums.phpfreaks.com/topic/141293-whats-wrong-with-my-query/#findComment-739532 Share on other sites More sharing options...
dadamssg Posted January 18, 2009 Author Share Posted January 18, 2009 sorry that was the wrong code...i that but you were right, it was missing the semicolon but with this i get "Couldn't execute query" <?php /* File: processtest.php*/ include("caneck.inc"); $title = $_POST['title']; $description = $_POST['description']; $cnx = mysqli_connect($host,$user,$passwd,$dbname) $sql = "INSERT INTO test (title, description) VALUES ('$title','$description')"; $result = mysqli_query($cnx,$sql) or die ("Couldn't execute query."); include("tesdisplay.inc"); Print "The title, $title, and the description, $description, has been entered."; ?> Link to comment https://forums.phpfreaks.com/topic/141293-whats-wrong-with-my-query/#findComment-739533 Share on other sites More sharing options...
dadamssg Posted January 18, 2009 Author Share Posted January 18, 2009 i have the title set to VARYCHAR(20), description to TEXT, and then i have another column...but i didn't put NOT NULL on it.... Link to comment https://forums.phpfreaks.com/topic/141293-whats-wrong-with-my-query/#findComment-739535 Share on other sites More sharing options...
trq Posted January 18, 2009 Share Posted January 18, 2009 You need to check your form is actually being submitted. A better examples of your simple query would be.... <?php /* File: processtest.php*/ if (isset($_POST['submit'])) { // <-- name of submit button include "caneck.inc"; $title = mysql_real_escape_string($_POST['title']); $description = mysql_real_escape_string($_POST['description']); $cnx = mysqli_connect($host, $user, $passwd, $dbname) or die(mysqli_error($cnx); $sql = "INSERT INTO test (title, description) VALUES ('$title','$description')"; if ($result = mysqli_query($cnx,$sql)) { include "tesdisplay.inc"; print "The title, $title, and the description, $description, has been entered."; } else { echo "Query failed<br />$sql<br />" . mysqli_error($cnx); } } ?> ps: I'm not sure where your learning php from but include files should not be named with the inc extension, use php. Link to comment https://forums.phpfreaks.com/topic/141293-whats-wrong-with-my-query/#findComment-739542 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.