Jump to content

error


ben1981

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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']."')";

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.