Jump to content

PHP noob....


johnmark

Recommended Posts

Hey, i know this is going to be really nooby but i'm having trouble with this simple php database connect code. It's not inserting anything into my table, please help. NOTE: In the real file, I have the strings filled out.

 

<?php
      $database_host = "";
  $database_username = "";
  $database_password = "";

  mysql_connect($database_host, $database_username, $database_password);
  
  mysql_select_db("jb");
  
  mysql_query("INSERT INTO John (Name, Email, Definition, Date) VALUES ('John Bizzle', '[email protected]', 'Please work', '2007-02-96');");
  
  ?>

Link to comment
https://forums.phpfreaks.com/topic/37283-php-noob/
Share on other sites

mysql_connect return a database link, so you should use this link in the mysql_query to database:

 

$db_link = mysql_connect($database_host, $database_username, $database_password);

mysql_select_db("jb");

 

$resultSet = mysql_query("INSERT INTO John (Name, Email, Definition, Date) VALUES ('John Bizzle', '[email protected]', 'Please work', '2007-02-96');", $db_link);

 

Link to comment
https://forums.phpfreaks.com/topic/37283-php-noob/#findComment-178128
Share on other sites

You dont need to use the database link. Try this....

 

<?php
  $database_host = "";
  $database_username = "";
  $database_password = "";
  
  mysql_connect($database_host, $database_username, $database_password) or die("Unable to connect");
  mysql_select_db("jb") or die("Unable to select db");

  $sql = "INSERT INTO John (Name, Email, Definition, `Date`) VALUES ('John Bizzle', '[email protected]', 'Please work', '2007-02-96');"
  if (mysql_query($sql)) {
    echo "Insert success";
  } else {
    echo mysql_error();
  }

?>

 

 

PS; Date is a reserved word in sql. Hence the surrounding backticks.

 

 

Link to comment
https://forums.phpfreaks.com/topic/37283-php-noob/#findComment-178136
Share on other sites

When you run this code?

 

<?php
  $database_host = "";
  $database_username = "";
  $database_password = "";
  
  mysql_connect($database_host, $database_username, $database_password) or die("Unable to connect");
  mysql_select_db("jb") or die("Unable to select db");

  $sql = "INSERT INTO John (Name, Email, Definition, `Date`) VALUES ('John Bizzle', '[email protected]', 'Please work', '2007-02-96');"
  if (mysql_query($sql)) {
    echo "Insert success";
  } else {
    echo mysql_error();
  }

?>

 

Are you sure php is working properly?

Link to comment
https://forums.phpfreaks.com/topic/37283-php-noob/#findComment-178170
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.