Jump to content

[SOLVED] Inserting data into database


anon

Recommended Posts

I have a form which has one field; url. This field should post its variable to a mysql table called addurl.

 

I already have the whole thing set up. Problem is that when i check what values are in the table they are blank. There is no value.

 

// prepare form values for insert
$URL = mysql_real_escape_string($_POST['url']);

// Make mysql connection below

$sql = "INSERT INTO `addurl` (`u_link`) VALUES ('$URL')";
$res = mysql_query($sql) or die(mysql_error());
  if(!$res){
  echo "Could not enter data";
  } else {
  echo "data entered into database";
  }
  ?>
</html>

Link to comment
Share on other sites

Thanks. This is what I get

 

Array
(
    [url] => http://www.yahoo.com
    [add] => Submit
)

data entered into database

 

The thing is that it does show that there's an entry. But when you check the field its just blank.

Link to comment
Share on other sites

Since there is a comment in the posted code about making a "mysql connection" after the mysql_real_escape_string() function call, I would guess that the mysql_real_escape_string() function call is failing since it requires a connection to a database server.

 

Check your web server log for errors.

 

Also, when learning php, developing php code, or debugging php code, always turn on full php error_reporting and display_errors in your php.ini or a .htaccess file to get php to help you. This will help pinpoint why code does not work due to basic  problems a majority of the time.

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.