anon Posted January 1, 2008 Share Posted January 1, 2008 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 More sharing options...
Barand Posted January 1, 2008 Share Posted January 1, 2008 put echo '<pre>', print_r($_POST, true), '</pre>'; at the beginning to check if POST vars are sent as expected Link to comment https://forums.phpfreaks.com/topic/83965-solved-inserting-data-into-database/#findComment-427275 Share on other sites More sharing options...
anon Posted January 1, 2008 Author Share Posted January 1, 2008 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 https://forums.phpfreaks.com/topic/83965-solved-inserting-data-into-database/#findComment-427284 Share on other sites More sharing options...
revraz Posted January 1, 2008 Share Posted January 1, 2008 Try $URL = mysql_real_escape_string($_POST['URL']); Link to comment https://forums.phpfreaks.com/topic/83965-solved-inserting-data-into-database/#findComment-427298 Share on other sites More sharing options...
PFMaBiSmAd Posted January 1, 2008 Share Posted January 1, 2008 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 https://forums.phpfreaks.com/topic/83965-solved-inserting-data-into-database/#findComment-427307 Share on other sites More sharing options...
anon Posted January 1, 2008 Author Share Posted January 1, 2008 Quote Try $URL = mysql_real_escape_string($_POST['URL']); Yes, i tried that not 10 minutes ago and it worked. Thanks anyway though. Link to comment https://forums.phpfreaks.com/topic/83965-solved-inserting-data-into-database/#findComment-427328 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.