Jump to content

PHP and database


common

Recommended Posts

Hi

 

I am new at connecting a DB to a website. The only DB program that I have is MS Access, I know many people don't like it, but I am just starting with it.

 

I have visited w3schools and tried something out. I want to view all the data in one table, like for a hardware company, and I got that right, but know I want to create a page that inserts data into the table.

This is my code:

 

if(isset($_POST['inserted']))

{

    $table=$_POST['table'];

    $name=$_POST['p_name'];

    $descript=$_POST['p_descript'];

    $price=$_POST['p_price'];

 

  $conn=odbc_connect('wk','','');

  if(!$conn){exit("Connection Failed: ".$conn);}

 

 

  $sql="INSERT INTO $table (P_CODE,P_NAME,P_DESCRIPT,P_PRICE,P_PIC)

        VALUES (12,'$name','$descript','$price','12')";

 

 

  print "1 record added!";

 

  odbc_close($conn);

}

 

else

{

  include('include/insertForm.php');

}

 

The form I insert only gets the info to insert in the name, description, price collumns.

 

I have XAMPP on my computer, and according to w3schools I have to go in my control pannel to add th database(named 'wk') to the odbc... When I run the code it goes through and show that one record is added, but nothing change in the database??

 

Can anyone help me with that please, and if you know about an other program than MS Access can you tell me please? And weather this will still work on a host server.

Link to comment
https://forums.phpfreaks.com/topic/163208-php-and-database/
Share on other sites

Hey, I'm not familiar with MS Access, but are you executing your query?

 

  $sql="INSERT INTO $table (P_CODE,P_NAME,P_DESCRIPT,P_PRICE,P_PIC)
        VALUES (12,'$name','$descript','$price','12')";
                  
         
  print "1 record added!";

 

You just seem to be assigning a string to $sql and printing out another string. The query is never executed.

Link to comment
https://forums.phpfreaks.com/topic/163208-php-and-database/#findComment-861131
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.