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
https://forums.phpfreaks.com/topic/83965-solved-inserting-data-into-database/
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.

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.