in try.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="en-us" http-equiv="Content-Language" /> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>ID</title> </head> <body> <form action="" method="post"> ID: <input name="Text1" type="text" /><br /> <br /> Model: <input name="Text2" type="text" /><br /> <br /> Year: <input name="Text3" type="text" /><br /> <?php if(isset($_POST['id']) && isset($_POST['model']) && isset($_POST['year'])){ $id=$_POST['id']; $model=$_POST['model'] $year=$_POST['year'] include('test1a.php'); //$sql = "INSERT into customer (name, address, phone) VALUES ('$name','$add','$phone')"; $sql = "INSERT into cars (id, model, year) VALUES ('$id','$model','$year')"; $result = db_query($sql); echo '<script type="text/javascript"> alert(\'The Data Have Been Stored~~\'); </script>'; } ?> </form> </body> </html> the database connection <?php //connection to the database & server $config_dbServerHost = '127.0.0.1'; $config_dbUsername = 'root'; $config_dbPassword = '2614352'; $config_dbName = 'examples'; $link = mysql_connect($config_dbServerHost, $config_dbUsername, $config_dbPassword) or die('Could not connect: ' . mysql_error()); mysql_select_db($config_dbName) or die('Could not select database'); function db_query($sQuery) { $aResult = @mysql_query($sQuery) or die('Query failed: ' . mysql_error() . "<br/> SQL: $sQuery"); if((substr($sQuery,0,6))=="INSERT") { $finalResult = mysql_insert_id(); } return $finalResult; } //select a database to work with //$selected = mysql_select_db("examples",$dbhandle) // or die("Could not select examples"); //fetch tha data from the database //while ($row = mysql_fetch_array($result)) { // echo "ID:".$row{'id'}." Name:".$row{'model'}." Year: ". //display the results // $row{'year'}."<br>"; /* $sql="INSERT INTO cars (id, model, year) VALUES ('$_POST[id]','$_POST[model]','$_POST[year]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; } //close the connection mysql_close($dbhandle); */ ?> can't get ti insert into the database, could you guys pls help me on it i'm new to php and don't expect i know a lot since i'm just more than a beginner... thank you
1. - Is this being hosted on your home machine, or on an actual production server? 2. - How is the script not working? It's hard to diagnose a problem when we don't have symptoms.
it's on my laptop... well i just hav no idea cause it just can't insert into my database... i have some data in my database too...just can retrieve all the data but not insert and other functions... just no idea why... as it can connect to database
the connection is ok but i can't run the try.php the error is this HTTP Error 500.0 - Internal Server Error The page cannot be displayed because an internal server error has occurred.
one reason of the internal error is, do you have a .htaccess file in your directory?? is rewrite_module in your apache enabled??
I highly doubt you need to meddle with .htaccess. Instead, post the code that allows you to get results from the database. There should be a reason it's working and your given code isn't.
Like I said, I highly doubt the problem is with .htaccess. If you want to solve the problem, refer to my previous post.