sando Posted December 15, 2007 Share Posted December 15, 2007 I am trying to add an "add page" area to my cms. Here is the code so far: Add.php (The HTML form) <?require_once "../includes/db.inc.php"; admin_session();?> <form id="addform" name="addform" method="post" action="insert_page.php"> Page Title: <input name="page_name" type="text" id="page_name" /> <input name="status" type="hidden" id="status" value="Active"> <input name="content" type="hidden" id="content" value="Default Page Content"> <input type="submit" name="Submit" value="Submit" /> </form> Insert.php (The process) <? // Connect database. require_once "../includes/db.inc.php"; admin_session(); // Get values from form. $page_name=$_POST['page_name']; $status=$_POST['status']; $content=$_POST['content']; // Insert all parameters into database. mysql_query("insert into static_page_name(page_name, status, ) values('$page_name', '$status', '$content')"); // Close database connection mysql_close(); ?> The table is static_page_name containing: static_page_id, content, page_name, status When I submit the form it calls insert.php which opens leaving a blank screen. Nothing gets added to the database but no error messages show? What am I doing wrong? Any help appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
asmith Posted December 15, 2007 Share Posted December 15, 2007 mysql_query("insert into static_page_name(page_name, status, ) values('$page_name', '$status', '$content')") or die(mysql_error()); it will show you why it do not record to mysql table. i do believe your mysql_query needs a connection as the secodn argument like : $conn = mysql_connect("localhost","name","password"); mysql_query($sql, $conn); if didn't worked i must see your include codes. Quote Link to comment Share on other sites More sharing options...
sando Posted December 15, 2007 Author Share Posted December 15, 2007 When I add the or die(mysql_error() I get this output: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') values('Test', 'Active', 'Insert Page Contents')' at line 1 Quote Link to comment Share on other sites More sharing options...
sando Posted December 15, 2007 Author Share Posted December 15, 2007 I have now added the connection directly to my file $conn = mysql_connect("localhost","user","pass"); mysql_query($sql, $conn); Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') values('test1', 'Active', 'Insert Page Contents')' at line 1 Quote Link to comment Share on other sites More sharing options...
sando Posted December 15, 2007 Author Share Posted December 15, 2007 Any ideas? ??? Quote Link to comment Share on other sites More sharing options...
asmith Posted December 16, 2007 Share Posted December 16, 2007 as it says you have a synax error : after "," you have only a space, you have 3 values , so you must give mysql 3 columns . or if you have 2 columns , give it 2 values . your line should be at last : (i removed your content from value parathes) mysql_query("insert into static_page_name(page_name, status) values('$page_name', '$status')") or die(mysql_error()); or (add a column to column parathes ) (i added the "content") mysql_query("insert into static_page_name(page_name, status,content) values ('$page_name', '$status', '$content')") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
sando Posted December 16, 2007 Author Share Posted December 16, 2007 Now working, thanks for the advise, the code at the end: <?php // Connect 2 db. $dbhost = 'localhost'; $dbuser = 'dbuser'; $dbpass = 'dbpass'; $dbname = 'dbname'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Connection Error'); mysql_select_db($dbname); //Check for admin. require_once "../includes/config.inc.php"; admin_session(); // Get form values. $page_name=$_POST['page_name']; $status=$_POST['status']; $content=$_POST['content']; //Enter info into db. mysql_query("insert into web_page_name(page_name, status,content) values ('$page_name', '$status', '$content')") or die(mysql_error()); echo ("Done"); //finished. mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
corbin Posted December 16, 2007 Share Posted December 16, 2007 It might be worth noting that unless magic quotes are on (I hate magic quotes), that has the potential to syntax error if any input contains a '. That would make it something like VALUES('The Page', 'Some Status', 'It's cold outside') Without magic quotes, you would need to do addslashes() so It's cold outside would become It\'s cold out side. 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.