Akenatehm Posted December 5, 2008 Share Posted December 5, 2008 Hey Guys, I am getting the following error: Could not insert commentUnknown column 'test' in 'field list' Where 'test' is the data I inputted. Here is the script: <?php include "connect.php"; // Checks the database for a user with a particular user name $check = mysql_query("select ID from users where username='$username' limit 1;"); // get a row count of the number of rows found if(mysql_num_rows($check) == 1) { echo "Username Already In Use."; } else { if(isset($_POST['submit'])) { $username=$_POST['username']; $password=$_POST['password']; $email=$_POST['email']; if(strlen($username)<1) { print "You did not enter a username."; } else if(strlen($password)<1) { print "You did not enter a password."; } else { $insert = sprintf("INSERT INTO `users` (username,password,email) VALUES (%s,%s,%s)", mysql_real_escape_string($username), mysql_real_escape_string($password), mysql_real_escape_string($email)); mysql_query($insert) or die("Could not insert comment" . mysql_error()); echo "User Added. <a href=\"index.php\">Click here</a> To Go Home."; } } } ?> and here is the page with the form: <?php session_start(); // is the one accessing this page logged in or not? if (!isset($_SESSION['db_is_logged_in']) || $_SESSION['db_is_logged_in'] !== true) { // not logged in, move to login page header('Location: login.php'); exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Relay Administration Panel - Add User</title> <link rel="stylesheet" href="styles.css" /> </head> <body bgcolor="#3d3d3d"> <div> <img src="images/header.png" /> </div> <br /> <table width="737px" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="150" valign="top" bgcolor="#4e4a49"><a href="index.php"><img src="images/home.png" width="150" height="40" border="0" /></a><a href="add_user.php"><img src="images/add_user.png" width="150" height="40" border="0" /></a><a href="delete_user.php"><img src="images/delete_user.png" width="150" height="40" border="0" /></a> <a href="add_admin.php"><img src="images/add_admin.png" width="150" height="40" border="0" /></a><a href="scripts/logout.php"><img src="images/logout.png" width="150" height="40" border="0" /></a></td> <td width="3"></td> <td width="577" valign="top" bgcolor="#4e4a49"> <p class="header"> <b>Add User Form</b> </p> <form action="scripts/add_user_script.php" method="post" id="add_user"> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td width="84" align="right"><p class="text"><b>Username:</b> </p> </td> <td width="653"><input type="text" name="username" id="username" /></td> </tr> <tr> <td align="right"><p class="text"><b>Password:</b> </p></td> <td><input type="password" name="password" id="password" /></td> </tr> <tr> <td align="right"><p class="text"><b>Email:</b> </p></td> <td><input type="text" name="email" id="email" /></td> </tr> <tr> <td> </td> <td><input type="reset" name="reset" id="reset" value="Reset" /> <input name="submit" type="submit" id="submit" value="Submit"/></td> </tr> </table> </form> <p class="text"> </p> </td> </tr> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/135716-insert-script-error/ Share on other sites More sharing options...
Xyphon Posted December 5, 2008 Share Posted December 5, 2008 That means in the database, in your comments table, the column 'test' is not there, it does not exist. Maybe you defined it or spelled it wrong? Maybe you forgot to add it? Link to comment https://forums.phpfreaks.com/topic/135716-insert-script-error/#findComment-707130 Share on other sites More sharing options...
Akenatehm Posted December 5, 2008 Author Share Posted December 5, 2008 I haven't defined a table called 'test' anywhere in these scripts. Link to comment https://forums.phpfreaks.com/topic/135716-insert-script-error/#findComment-707135 Share on other sites More sharing options...
Brian W Posted December 5, 2008 Share Posted December 5, 2008 try "INSERT INTO `users` (`username`,`password`,`email`) VALUES (%s,%s,%s)" for testing reasons. also use mysql_query($insert) or die("Could not insert comment" . mysql_error().'<br>'.$insert); that way you can see the query. if that doesn't work, let us know what the query is (copy and past the output of the error report above) Link to comment https://forums.phpfreaks.com/topic/135716-insert-script-error/#findComment-707137 Share on other sites More sharing options...
Akenatehm Posted December 5, 2008 Author Share Posted December 5, 2008 Ok, here's the error output: Could not insert commentUnknown column 'test' in 'field list' INSERT INTO `users` (`username`,`password`,`email`) VALUES (test,test,test) Link to comment https://forums.phpfreaks.com/topic/135716-insert-script-error/#findComment-707141 Share on other sites More sharing options...
PFMaBiSmAd Posted December 5, 2008 Share Posted December 5, 2008 Strings must be encloses in single-quotes so that they are treated as string data instead of identifiers and column names. Link to comment https://forums.phpfreaks.com/topic/135716-insert-script-error/#findComment-707144 Share on other sites More sharing options...
Brian W Posted December 5, 2008 Share Posted December 5, 2008 "INSERT INTO `users` (`username`,`password`,`email`) VALUES ('%s','%s','%s')" viola! try that Link to comment https://forums.phpfreaks.com/topic/135716-insert-script-error/#findComment-707149 Share on other sites More sharing options...
Akenatehm Posted December 5, 2008 Author Share Posted December 5, 2008 Thanks Guys for Your Help. Link to comment https://forums.phpfreaks.com/topic/135716-insert-script-error/#findComment-707153 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.