Urgently required help. I will make a guest and it is working fine at localhost and one hosting server, but the server where actually i need that guest book cause a problem. When i add some comment it is not saved in the database and show blank spaces. www.wistech.biz/guestbook [Working 100%] www.jsiza.com/guestbook [Values are not saved in database and show blank spaces] Kindly tell me how can i sovle my problem , I urgently need this gook at "www.jsiza.com"
Set this at the top of your page which is supposed to insert the data. error_reporting(E_ALL); ini_set('display_errors', '1'); PHP: And add OR die(mysql_error()); behind all queries. You probably just have a wrong password or database name set in your configuration. If you need more help, post your code.
Thanks for your help. The code is given as under. Dear the surprizing factor is that, it is working 100% fine at the other hosting server. Code , database, database structure is 100% same. Exported from phpmyadmin of my local host and placed in the control panel of my website in mysql databases. username and password to database is also write becoz it is not giving any connection error. Plz help meeee............ <?php include ("../connection/config.php"); $getDate = date("Y-m-d g:i:s"); $sqlInsertComment = "INSERT INTO `$comments` (`sender`, `email`, `country`, `comment`, `dateTime`) VALUES ('$sender', '$email', '$country', '$comment', '$getDate')"; $resultInsertComment = mysql_query($sqlInsertComment); if($resultInsertComment) { header ("Location: ../allComments.php"); } else { header ("Location: ../errorPages/newCommentError.php"); } ?> ---------------------------------------------------------------- Config file is as under. <?php $host = "localhost"; $user = "userhere"; $password = "passwordhere"; $database = "guestbook"; $comments = "comments"; #table name mysql_connect("$host","$user","$password") or die ("<meta http-equiv=\"refresh\" content=\"0;url=errorPages/serverConnectionError.php\" />"); mysql_select_db("$database") or die ("<meta http-equiv=\"refresh\" content=\"0;url=errorPages/databaseConnectionError.php\" />"); ?>
Looks like register_globals is off on that host, hence it inserts blank data because those variables don't actually exist.
You can turn it on via your php.ini file. Just open notepad and place register_globals = on Code (markup): Save it as php.ini and upload it to the dir the script is in. <?php include ("../connection/config.php"); $getDate = date("Y-m-d g:i:s"); $sqlInsertComment = "INSERT INTO `$comments` (`sender`, `email`, `country`, `comment`, `dateTime`) VALUES ('$sender', '$email', '$country', '$comment', '$getDate')"; $resultInsertComment = mysql_query($sqlInsertComment) or die (mysql_error()); if($resultInsertComment) { header ("Location: ../allComments.php"); } else { header ("Location: ../errorPages/newCommentError.php"); } ?> PHP: Ive added the error call in the query so run it and let us know what it says.
I modify the code and add " mysql_error() " function with query , but once again it gives no error, and also blank entry is made with only date appear. As for as register_global is confirmed , Once i install oscommerce to my website and when i run it on hosted server (internet) it shows error message "register_globals" are off. If this is the problem then how can i "on" register_global at my hosting server.
Register_globals is for sure your problem, but if you're on a shared host then you probably can't get them to edit it (it's a security risk and I wouldn't recommend it anyway). I rewrite the line: $sqlInsertComment = "INSERT INTO `$comments` (`sender`, `email`, `country`, `comment`, `dateTime`) VALUES ('$sender', '$email', '$country', '$comment', '$getDate')"; PHP: It should be changed to $sqlInsertComment = "INSERT INTO `$comments` (`sender`, `email`, `country`, `comment`, `dateTime`) VALUES ('".mysql_real_escape_string($_POST['sender'])."', '".mysql_real_escape_string($_POST['email'])."', '".mysql_real_escape_string($_POST['country'])."', '".mysql_real_escape_string($_POST['comment'])."', '".mysql_real_escape_string($_POST['getDate'])."')"; PHP: It no longer needs register globals, and it's also now safe from SQL injection. Cheers
As I said you need to turn it on via the php.ini file, if you cannot do that then you need to contact your host and ask them to do it.
babaMBA: Use $_POST and $_GET arrays (don't forget about filtering input data). And there will be no problems Learn good habits in coding. Regards, M
register_globals should never be on. Use the provided super globals to access user input. Also, anyone could hack your site simply by using SQL queries in the form fields. You need to validate input and make use of the PHP functions which make user input SQL safe.