ben1981 Posted March 8, 2007 Share Posted March 8, 2007 can anyone see anything wrong with this code??? <?php require_once('DbConnector.php'); if ($HTTP_POST_VARS){ $connector = new DbConnector(); $insertQuery = "INSERT INTO customers (firstname,lastname,address) VALUES ("."'".$HTTP_POST_VARS['firstname']."', "."'".$HTTP_POST_VARS['lastname']."', ".$HTTP_POST_VARS['address']."')"; if ($result = $connector->query($insertQuery)){ echo '<center><b>Article added to the database</b></center><br>'; }else{ exit('<center>Sorry, there was an error saving to the database</center>'); } } ?> I keep getting the Sorry... message Quote Link to comment Share on other sites More sharing options...
artacus Posted March 8, 2007 Share Posted March 8, 2007 Well it would be easier to debug if you had included it in code tags, indented it and included the error message Quote Link to comment Share on other sites More sharing options...
ben1981 Posted March 8, 2007 Author Share Posted March 8, 2007 is that better, sorry i'm new to this Quote Link to comment Share on other sites More sharing options...
artacus Posted March 8, 2007 Share Posted March 8, 2007 Getting there. What is the error message? Is it from MySQL or from PHP? Quote Link to comment Share on other sites More sharing options...
ben1981 Posted March 8, 2007 Author Share Posted March 8, 2007 well i get the message after the "else" command in the code which seems to say that there was a problem adding a record - but how do i find out what the problem was??? i must admit i'm using a free hosting service but it comes with php mysql so i'm wondering if they have disabled certain features hope you can help Quote Link to comment Share on other sites More sharing options...
papaface Posted March 8, 2007 Share Posted March 8, 2007 change: $insertQuery = "INSERT INTO customers (firstname,lastname,address) VALUES ("."'".$HTTP_POST_VARS['firstname']."', "."'".$HTTP_POST_VARS['lastname']."', ".$HTTP_POST_VARS['address']."')"; to $insertQuery = "INSERT INTO customers (firstname,lastname,address) VALUES ('".$HTTP_POST_VARS['firstname']."','".$HTTP_POST_VARS['lastname']."','".$HTTP_POST_VARS['address']."')"; Quote Link to comment Share on other sites More sharing options...
artacus Posted March 8, 2007 Share Posted March 8, 2007 I'm not familiar with the db abstraction class you are using. But there should be a way to get it to die and return the sql error message when you run a query. Quote Link to comment Share on other sites More sharing options...
ben1981 Posted March 8, 2007 Author Share Posted March 8, 2007 Fantastic - it now works - thanks for your quick reply and solution!! Quote Link to comment Share on other sites More sharing options...
ben1981 Posted March 8, 2007 Author Share Posted March 8, 2007 I think there is a way to get a MYSQL error report but I am so new to PHP that I dont know how to do it. must have been my code which was wrong as editing the data fixed the problem Quote Link to comment Share on other sites More sharing options...
papaface Posted March 8, 2007 Share Posted March 8, 2007 In the future try adding error_reporting(E_ALL); ini_set('display_errors', '1'); to the top of your pages inside the <?php and see if you get any errors first. Quote Link to comment Share on other sites More sharing options...
ben1981 Posted March 9, 2007 Author Share Posted March 9, 2007 thanks i have added those lines to my code. well now i can add a record. i need to find out how to edit/delete existing records. in my database will be the content of the website. things like latest news, department pages, and so on. so the customer can edit the site themselves. would it be easy for the customer to upload word docs to the site? and images? Quote Link to comment Share on other sites More sharing options...
ben1981 Posted March 9, 2007 Author Share Posted March 9, 2007 hi this code, shows me the last 5 records from my database listed with the title of each <b> WHAT'S NEW: </b><br> <?php // Require the database class require_once('includes/DbConnector.php'); // Create an object (instance) of the DbConnector $connector = new DbConnector(); // Execute the query to retrieve articles $result = $connector->query('SELECT ID,title FROM cmsarticles ORDER BY ID DESC LIMIT 0,5'); // Get an array containing the results. // Loop for each item in that array while ($row = $connector->fetchArray($result)){ echo '<p> <a href="viewArticle.php?id='.$row['ID'].'">'; echo $row['title']; echo '</a> </p>'; } ?> how can i change it so it lists every database record? Quote Link to comment Share on other sites More sharing options...
artacus Posted March 9, 2007 Share Posted March 9, 2007 Remove "LIMIT 0,5" from your query. Quote Link to comment Share on other sites More sharing options...
ben1981 Posted March 9, 2007 Author Share Posted March 9, 2007 thanks artacus as you can probably tell i am new to php.. but finding it very interesting 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.