anon Posted December 11, 2007 Author Share Posted December 11, 2007 So whole INSERT script would look like: <? if(isset($_POST['name'])){ $name = $_POST['name']; $url = $_POST['url']; $description = $_POST['description']; $query = "INSERT INTO `db_table` (`id`,`name`) VALUES ('','$name')"; $run = mysql_query($query); } ?> What do i add at the "INSERT INTO 'db_table' ....... part. It only lists the name variable Quote Link to comment Share on other sites More sharing options...
p2grace Posted December 11, 2007 Share Posted December 11, 2007 The whole insert statement would look like this: <? if(isset($_POST['name'])){ $name = $_POST['name']; $url = $_POST['url']; $description = $_POST['description']; $query = "INSERT INTO `db_table` (`id`,`name`,`url`,`description`) VALUES ('','$name','$url','$description')"; $run = mysql_query($query); } ?> Quote Link to comment Share on other sites More sharing options...
anon Posted December 11, 2007 Author Share Posted December 11, 2007 Where do i specify host name and so on? Quote Link to comment Share on other sites More sharing options...
p2grace Posted December 11, 2007 Share Posted December 11, 2007 For best practice you'd usually put that information into a file and include it. The code itself would need to be above the insert query. Here's how to connect: define("DB_USER","username"); define("DB_PASS","password"); define("DB_DATABASE","database"); mysql_connect('localhost',DB_USER,DB_PASS); @mysql_select_db(DB_DATABASE) or die("Unable to select database!"); mysql_query("SET NAMES 'utf8'"); Quote Link to comment Share on other sites More sharing options...
anon Posted December 11, 2007 Author Share Posted December 11, 2007 I get this error Parse error: syntax error, unexpected T_LOGICAL_OR in /home/redzero/public_html/direx/addurl.php on line 8 Line 8 is @mysql_select_db(DB_DATABASE) or die("Unable to select database!"); Quote Link to comment Share on other sites More sharing options...
p2grace Posted December 11, 2007 Share Posted December 11, 2007 I've used that code a hundred times, there must be something else that's breaking before. Can you post the code for me. Quote Link to comment Share on other sites More sharing options...
anon Posted December 11, 2007 Author Share Posted December 11, 2007 Here it is: define("DB_USER","*****"); define("DB_PASS","****"); define("DB_DATABASE","direx"); mysql_connect('localhost',DB_USER,DB_PASS); @mysql_select_db(DB_DATABASE) or die("Unable to select database!"); mysql_query("SET NAMES 'utf8'"); if(isset($_POST['name'])){ $name = $_POST['name']; $url = $_POST['url']; $description = $_POST['description']; $query = "INSERT INTO `addtable` (`id`,`Name`,`URL`,`Description`) VALUES ('','$name','$url','$description')"; $run = mysql_query($query); } ?> I did substitute the user and password; just keeping private Quote Link to comment Share on other sites More sharing options...
p2grace Posted December 11, 2007 Share Posted December 11, 2007 There's html syntax in the code that must have been placed when you copied it. It must look identical to this: define("DB_USER","*****"); define("DB_PASS","****"); define("DB_DATABASE","direx"); mysql_connect('localhost',DB_USER,DB_PASS); @mysql_select_db(DB_DATABASE) or die("Unable to select database!"); mysql_query("SET NAMES 'utf8'"); if(isset($_POST['name'])){ $name = $_POST['name']; $url = $_POST['url']; $description = $_POST['description']; $query = "INSERT INTO `addtable` (`id`,`Name`,`URL`,`Description`) VALUES ('','$name','$url','$description')"; $run = mysql_query($query); } ?> Quote Link to comment Share on other sites More sharing options...
anon Posted December 11, 2007 Author Share Posted December 11, 2007 same parse error but on line 9, same as original parse error. Wtf Quote Link to comment Share on other sites More sharing options...
p2grace Posted December 11, 2007 Share Posted December 11, 2007 Try removing mysql_query("SET NAMES 'utf8'"); Quote Link to comment Share on other sites More sharing options...
anon Posted December 11, 2007 Author Share Posted December 11, 2007 That's on line 10, but tried nonetheless Quote Link to comment Share on other sites More sharing options...
p2grace Posted December 11, 2007 Share Posted December 11, 2007 What verison of php and mysql are you using? Quote Link to comment Share on other sites More sharing options...
anon Posted December 11, 2007 Author Share Posted December 11, 2007 The latest i'm sure. I'm on CPanel 11 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.