Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

SQL disconnected

baebae Posts: 45Member
let see my php code.Here, there are 3 files.
1.














Name
1.


2.


3.

4.

5.








Title
Description
Year

2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
Total Pages






2.receive file

<?php
include('connect_login.php');
$title = $_POST['title'];
$description = $_POST['description'];
$std_name = $_POST['std_name'];
$total_pages = $_POST['total_pages'];


$sql = "INSERT INTO `text`.`developer` (`id` ,`title` ,`description` ,`year` ,`std_name` ,`total pages` )VALUES ('', '$title', '$description', '', '$std_name', '$total_pages');";

mysql_query($sql);

?>

3. database connected file

<?php
$db_host="localhost";
$db_database="text";
$db_username="root";
$db_password="4710180";



$connection = mysql_connect($db_host, $db_username, $db_password);
if (!$connection){
die ("Could not connect to the database: <br />". mysql_error());
}
// Select the database
$db_select=mysql_select_db($db_database);
if (!$db_select)
{
die ("Could not select the database:
". mysql_error());
}
?>

i use appserv .yet i can not connect to database please tell me how to edit the code correctly?




thanks indeed

Comments

  • tradmtradm Posts: 49Member
    Make sure 'thankstudent.php' and 'connect_login.php' are in the same folder.

    You can check the Databse connection from command prompt by;

    1. Open command prompt - (start > Run > type CMD)
    2. While in the cmd prompt, type:
    [b] mysql -h 127.0.0.1 -u root -p[/b]
    Enter your password (the one you have used on the script) [color=Grey]4710180[/color]

    Let me know if you will be able to connect.

  • baebae Posts: 45Member
    the result is Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 182
    Server version : 5.0.51b-community-nt-log MySQL Community Edition (GPL)

    Type ' help;' or 'h' for help. Type 'c' to clear the buffer.

    mysql>
  • baebae Posts: 45Member
    both files are same folder
  • tradmtradm Posts: 49Member
    bae,

    Can you replace your thankstudent.php with this one.

    [code]<?php
    require_once('connect_login.php');
    $title = $_POST['title'];
    $description = $_POST['description'];
    $std_name = $_POST['std_name'];
    $total_pages = $_POST['total_pages'];


    $sql = "INSERT INTO `text`.`developer` (`id` ,`title` ,`description` ,`year` ,`std_name` ,`total pages` )VALUES ('', '$title', '$description', '', '$std_name', '$total_pages');";
    echo $sql;
    echo "<br>";
    mysql_query($sql) or die(mysql_error());
    echo "Done";

    ?>[/code]

    Fill your form and submit.

    Am interested with the output from the web browser after you submit the form.


    Finally, if you can, send me the schema for the database table ;
    Do the following
    [italic]Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 6 to server version: 4.0.24-nt-log

    Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

    mysql> [b]DESCRIBE text.developer;[/b][/italic]


Sign In or Register to comment.