ok back again for some help...
I have created a table with entires. I would like to be able to check this table when a new entry is being inserted so I don't have duplicates.
I have highlighted the line of code that is giving me trouble below. I get an error that reads "Parse error: syntax error, unexpected T_VARIABLE in /home2/whackand/public_html/index_files/basic_db_wiki.php on line 68" and I can't seem to figure out how to fix it.
I know it is probably a simple fix. Any help is appreciated.
Code:<html> <head> <?php //Checking database for existance of table function table_exists($table, $db) { //retrives the whole list of tables from database $tables_check = mysql_list_tables($db); echo mysql_list_tables($db) . "<br />"; //cycles through the list checking each entry while (list ($temp) = mysql_fetch_array($tables_check)) { if ($temp == $table) { return true; } } return false; } ?> </head> <body> <?php //declaration of variables //creating connection to server $con = mysql_connect("localhost","username","password") or die('Could not connect to server' . mysql_error()); $table = "entries"; $db = "whackand_wikieng"; //create table "entries" process mysql_select_db($db, $con); $crt_table = "CREATE TABLE $table ( Number int NOT NULL AUTO_INCREMENT, PRIMARY KEY(Number), Name varchar(30), ClassLt varchar(4), ClassNo int(4), Semester varchar(10), Professor varchar(30), Type varchar(5) )"; //insert values into "entries" process mysql_select_db($db, $con); $insert_value = "INSERT INTO $table (Name, ClassLt, ClassNo, Semester, Professor, Type) VALUES ('$_POST[Name]', '$_POST[ClassLt]', '$_POST[ClassNo]', '$_POST[Semester]', '$_POST[Professor]', '$_POST[Type]')"; //getting entries from table for evaluation mysql_select_db($db, $con); $result = mysql_query(SELECT * FROM $table WHERE $name = '$_POST[Name]', $con); //execution of page //checking for table existance if(!table_exists($table, $db)) { mysql_query($crt_table, $con) or die('Could not create table' . mysql_error()); } //checking for value in table, if it doesnt exist, insert value if(mysql_num_rows($result)) { echo "The entry already exists." } else { mysql_query($insert_value); } //closing server connection mysql_close($con); echo "Sup."; ?> </body> </html>


Reply With Quote
Bookmarks