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', 'johnbizzle@bizzle.com', 'Please work', '2007-02-96');");
  
  ?>

Link to comment
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', 'johnbizzle@bizzle.com', 'Please work', '2007-02-96');", $db_link);

 

Link to comment
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', 'johnbizzle@bizzle.com', '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
Share on other sites

It should give you some kind of error.  I would try to debug it by turn on error reporting:

 

place this line at the very first of your php script:

 

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

 

post any error, warning you received.

Link to comment
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', 'johnbizzle@bizzle.com', '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
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.