mcolton Posted March 5, 2014 Share Posted March 5, 2014 I'm having trouble with the attached code. I'm not getting any error messages and the code is progressing to the next step correctly. It's just not creating a new record in the table. Thanks for any help trynewregistration.php Link to comment Share on other sites More sharing options...
justsomeguy Posted March 5, 2014 Share Posted March 5, 2014 Where did you get that code from? It looks extremely old. It is using the outdated mysql extension instead of mysqli or PDO, and it looks like it is relying on the ancient register_globals feature. The variables in the queries do not exist, they have not been defined. Link to comment Share on other sites More sharing options...
mcolton Posted March 5, 2014 Author Share Posted March 5, 2014 I inherited it. I'm not a sql programmer. I do program html.I think the variables are defined in the "registrationform" in the html script below the php code.I know some of it is working because "newregistration2.php" is working (line 172).Thanks for replying Link to comment Share on other sites More sharing options...
justsomeguy Posted March 5, 2014 Share Posted March 5, 2014 You might want to compare the PHP code in the two files to check for differences. The major reason why that code is not working is because the variables in the query aren't defined. For example, the first query uses $fname and $lname variables, which you see getting defined on the top of the code. They get their values from $_POST. $_POST contains all of the data submitted by a form using the post method. So that form had fields with names "fname" and "lname", so those values are retrieved from $_POST['fname'] and $_POST['lname']. The second query uses a bunch of other variables, $xfname, $xlname, $xemail, etc. Those don't get defined anywhere. They may be inside $_POST also.I mentioned register_globals because, if that setting is enabled, then PHP will automatically create variables from things like $_POST. So if $_POST contains a variable called $_POST['xfname'], then PHP would automatically create a variable called $xfname with the value from $_POST. The register_globals setting was disabled by default in PHP 4.2, which was released in 2002. The register_globals feature was completely removed in PHP 5.4. So that's why I assumed that is old code.If you want to see what is in $_POST from the form, you can print_r to print the whole thing out:print_r($_POST);http://www.php.net/manual/en/function.print-r.phpThat will list everything in $_POST. If you do see values for things like xfname, xlname, xemail, etc, then you can define those variables with the values from $_POST. You'll need to use mysql_real_escape_string to sanitize the data and protect the database though. e.g.: $xfname = mysql_real_escape_string($_POST['xfname']);$xlname = mysql_real_escape_string($_POST['xlname']);...You should also add mysql_real_escape_string to the fname and lname that are already defined on top.http://www.php.net/manual/en/function.mysql-real-escape-string.php Link to comment Share on other sites More sharing options...
mcolton Posted March 6, 2014 Author Share Posted March 6, 2014 Sorry but I'm even more confused now. Let me make sure you know what the intention of the code is.A user puts in his first and last name (in a previous file). I look to find an existing record in the db with those names.If it finds one, they are told that they have already have entered their data (already-registered.htm line 15).If not, I create a new record and insert the values from the html script.eg: line 183 they input their email address (field name = xemail).I know the values are moving onto "newregistration2.php" (line 172) because that program sends out an email and I'm gettingan email with the correct field data. (I've attached that program this time) Maybe I should move the "insert into" to newregistration2.php where I know all the fields are correct.Or do you think I should rewrite the whole thing.Is there a good online tutorial for new code I should be using?Thanks for all your help newregistration2.php Link to comment Share on other sites More sharing options...
mcolton Posted March 6, 2014 Author Share Posted March 6, 2014 Just an update. I moved the "insert into" to newregistration2.php where I know all the fields are correct.I got it to work correctly.Do you still think I should rewrite the whole thing.Is there a good online tutorial for new code I should be using?Thanks for all your help Link to comment Share on other sites More sharing options...
justsomeguy Posted March 6, 2014 Share Posted March 6, 2014 It would probably be good to learn the modern way to use a database with PHP, rather than the deprecated mysql extension. There's an introduction to PDO with some more links here:http://www.dreamincode.net/forums/topic/214733-introduction-to-pdo/ Link to comment Share on other sites More sharing options...
mcolton Posted March 6, 2014 Author Share Posted March 6, 2014 Thanks for your help. Like I said, I have it working but I'll look to update it Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now