PHPOD Posted November 19, 2009 Share Posted November 19, 2009 Hi all I was hoping someone could help me with this coding issue im a bit of a noob to php but getting there slowly. I have a form that should hold user information and should using POST insert it into a database. This form works fine offline (localhost using apache) however when i upload the code the form starts to return blank variables! Online Echo result INSERT INTO contact (address, email,fname,lname, birthyear, username, joined_date, ip_address) VALUES ('', '','','','' ,'', CURDATE(), '123.123.123.12' ) However when i run the form on the localhost the echo results a full! Offline echo result INSERT INTO contact (address, email,fname,lname, birthyear, username, joined_date, ip_address) VALUES ('TEST', 'TEST','TEST','TEST','TEST' ,'TEST', CURDATE(), '123.123.123.12' ) I know for a fact that the connection to the Database is working fine as i am displaying data from it on another page ! Below is the code for the php pages and I would like to say thanks in advance for any help adddata.php <?php include_once $_SERVER['DOCUMENT_ROOT'] . '../!__ONLINE comment/includes/magicquotes.inc.php'; // use the below method to add data to the various fields function VisitorIP() { if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $TheIp=$_SERVER['HTTP_X_FORWARDED_FOR']; else $TheIp=$_SERVER['REMOTE_ADDR']; return trim($TheIp); } $ip = VisitorIP(); //* Declare variables form form page below $address = mysqli_real_escape_string($link, $_POST['address']); $email = mysqli_real_escape_string($link, $_POST['email']); $fname = mysqli_real_escape_string($link, $_POST['fname']); $lname = mysqli_real_escape_string($link, $_POST['lname']); $uname = mysqli_real_escape_string($link, $_POST['user']); $dob = mysqli_real_escape_string($link, $_POST['dob']); $sqlcode2="INSERT INTO contact (address, email,fname,lname, birthyear, username, joined_date, ip_address) VALUES ('$address', '$email','$fname','$lname','$dob' ,'$uname', CURDATE(), '$ip' )"; echo $sqlcode2; if (!mysqli_query($link, $sqlcode2)) { $error = 'Error adding submitting Product' . mysqli_error($link); include $_SERVER['DOCUMENT_ROOT'] . '../!__ONLINE comment/includes/error.html.php'; exit(); } ?> register.php <?php include $_SERVER['DOCUMENT_ROOT'] . '../!__ONLINE comment/includes//dbconnect.php'; include_once $_SERVER['DOCUMENT_ROOT'] . '../!__ONLINE comment/includes/magicquotes.inc.php'; /** * Returns true if the username has been taken * by another user, false otherwise. */ function usernameTaken($username){ global $link; if(!get_magic_quotes_gpc()){ $username = addslashes($username); } $q = "select username from users where username = '$username'"; $result = mysqli_query($link,$q); return (mysqli_num_rows($result) > 0); } /** * Inserts the given (username, password) pair * into the database. Returns true on success, * false otherwise. */ function addNewUser($username, $password) { global $link; $q = "INSERT INTO users VALUES ('$username', '$password')"; return mysqli_query($link,$q); } /** * Displays the appropriate message to the user * after the registration attempt. It displays a * success or failure status depending on a * session variable set during registration. */ function displayStatus(){ $uname = $_SESSION['reguname']; if($_SESSION['regresult']){ } else{ } unset($_SESSION['reguname']); unset($_SESSION['registered']); unset($_SESSION['regresult']); } if(isset($_SESSION['registered'])){ /** * This is the page that will be displayed after the * registration has been attempted. */ return; } /** * Determines whether or not to show to sign-up form * based on whether the form has been submitted, if it * has, check the database for consistency and create * the new account. */ if(isset($_POST['subjoin'])){ /* Make sure all fields were entered */ if(!$_POST['user'] || !$_POST['pass'] || !$_POST['fname'] || !$_POST['lname'] || !$_POST['dob'] || !$_POST['email'] ){ die('You didn\'t fill in a required field.'); } /* Spruce up username, check length */ $_POST['user'] = trim($_POST['user']); if(strlen($_POST['user']) > 20 ) { die("Sorry, the username is longer than 20 characters, please shorten it."); } /* Check if username is already in use */ if(usernameTaken($_POST['user'])){ $use = $_POST['user']; die("Sorry, the username: <strong>$use</strong> is already taken, please pick another one."); } include 'adddata.php'; /* Add the new account to the database */ $md5pass = md5($_POST['pass']); $_SESSION['reguname'] = $_POST['user']; $_SESSION['regresult'] = addNewUser($_POST['user'], $md5pass); $_SESSION['registered'] = true; header("location:../index.php"); return; } else{ include 'registarform.php'; } ?> registarform.php <?php include_once $_SERVER['DOCUMENT_ROOT'] .'../!__ONLINE comment/includes/helpers.inc.php';?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Registration Page</title> <link href="../styles/style.css" rel="stylesheet" type="text/css" /> <body> <h1>Register</h1> <div class='regformtxt'> <br>Your account gives you access to the comment section of the website <br>and also allows you to recive emails on any update to the webpage <br>If you all ready have an account you can <a href='../index.php' >sign in here</a>. <br>or go to the <a href='../index.php' >home page here</a>.<p></div> <div class='regform'> <form action="?" method="POST"> <table id="table1"> <tr><label for= "fname"><td>First Name:</td><td><input type="text" name="fname" maxlength="30"></td></tr></label> <tr><label for= "lname"><td>Last Name:</td><td><input type="text" name="lname" maxlength="30"></td></tr></label> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr> <tr><label for= "dob"><td>Birth Year:</td><td><input type="text" value ="eg 1990" name="dob" maxlength="30"></td></tr></label> <tr><label for= "email"><td>Email:</td><td><input type="text" name="email" maxlength="30"></td></tr></label> <tr><label for= "address"><td>Address:</td><td><input type="text" name="address" maxlength="30"></td></tr></label> <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Submit"></td></tr> </table> </form> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/182128-php-post-variables-empty-online-working-fine-on-localhost/ Share on other sites More sharing options...
PHPOD Posted November 19, 2009 Author Share Posted November 19, 2009 please see http://www.phpfreaks.com/forums/index.php/topic,277555.0.html for further information Link to comment https://forums.phpfreaks.com/topic/182128-php-post-variables-empty-online-working-fine-on-localhost/#findComment-961148 Share on other sites More sharing options...
cags Posted November 19, 2009 Share Posted November 19, 2009 Can I see your dbconnect.php script? Link to comment https://forums.phpfreaks.com/topic/182128-php-post-variables-empty-online-working-fine-on-localhost/#findComment-961271 Share on other sites More sharing options...
PHPOD Posted November 19, 2009 Author Share Posted November 19, 2009 Hey cags below dbconnect code as requested i know that the dbconnection is ok as i can pull data from the db and display it on other pages <?php //* Connect to database $link = mysqli_connect('localhost','root','password'); if (!$link) { $error = 'Unable to connect to db server'; include $_SERVER['DOCUMENT_ROOT'] . ' ../comment/includes//error.html.php'; exit(); } if (!mysqli_set_charset($link, 'utf8')) { $output ='Undable to set to db encoding'; include $_SERVER['DOCUMENT_ROOT'] . ' ../comment/includes//output.html.php'; exit(); } if (!mysqli_select_db($link, 'comment')) { $error ='Unable to located Company db'; include $_SERVER['DOCUMENT_ROOT'] . ' ../comment/includes//error.html.php'; exit(); } ?> Link to comment https://forums.phpfreaks.com/topic/182128-php-post-variables-empty-online-working-fine-on-localhost/#findComment-961285 Share on other sites More sharing options...
mikesta707 Posted November 19, 2009 Share Posted November 19, 2009 I don't see where $link is defined. Can you post the code that defines it? Link to comment https://forums.phpfreaks.com/topic/182128-php-post-variables-empty-online-working-fine-on-localhost/#findComment-961313 Share on other sites More sharing options...
cags Posted November 19, 2009 Share Posted November 19, 2009 Is this not doing that in the post before yours mike.... $link = mysqli_connect('localhost','root','password'); Link to comment https://forums.phpfreaks.com/topic/182128-php-post-variables-empty-online-working-fine-on-localhost/#findComment-961330 Share on other sites More sharing options...
mikesta707 Posted November 19, 2009 Share Posted November 19, 2009 Oh wow, totally missed that. Yeah the only reason I could see mysqli_real_escape_string() would return an empty string (rather than false) would be because no connection is open. Since you seem to successfully use $link in other places, i'm not so sure this is your problem. Try doing a var_dump on the $link variable before you apply the escape_string function Link to comment https://forums.phpfreaks.com/topic/182128-php-post-variables-empty-online-working-fine-on-localhost/#findComment-961335 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.