Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

PHP Code Help

Asked Modified Viewed 5,822 times
A
afoster
A
  • Senior Member, joined since
  • Contributed 725 posts on the community forums.
  • Started 128 threads in the forums
  • Started this discussions
asked
Senior Member

Let me preface this by saying this is not php-fusion related. I am trying to put together a webform and the data collected is inserted into a mysql database. Everything seems to be working except that I need to validate one of the entries to ensure that the data entered is not already in the table column. I have tried many pieces of code, none of which seem to work. I have read about making the column UNIQUE but I have also read that it is better to use a SELECT statement to do this which is how I have tried to accomplish this. The column in question is the WSBNo. As I mentioned above, the form is working but will/does not validate that column. This is the code I am using in the form processor form:

$query = "SELECT COUNT(*) FROM fusion_players17 WHERE WSBNo = (' . mysql_real_escape_string(WSBNo) .')";
      //$query = "SELECT FROM fusion_players17 WHERE WSBNo = '$WSBNo'";
      $result = mysql_query($query);
      if (mysql_result($result, 0, 0) > 0){
      //if (mysql_result($result) >0){
    // some data matched
   echo "<center>";
   echo "That Square Has Been Taken, Go Back And Pick Another Square";
   echo "</center>";
}
else {
       
        $sql = "INSERT INTO fusion_players17 (user_name, name, address, city, state, zip, email, password, Reg, SurvI, SurvII, BTL, Play, WSB, CPP, Marg, total, WSBNo)
                VALUES ('$user_name', '$name', '$address', '$city', '$state', '$zip', '$email', '$password', '$Reg', '$SurvI', '$SurvII', '$BTL', '$Play', '$WSB', '$CPP', '$Marg', '$total', '$WSBNo')";
        if (!mysql_query($sql,$connection)){
            die('Error: ' . mysql_error());


If more information is needed, let me know and thanks in advance for any assistance provided.
0 replies

27 posts

F
Falk
F
Falk 131
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 11 questions
answered
Super Admin

That goes for you and me both ;)
intval is instead of isnum() ( a function we have in 7 and 9 or Defender that auto sanitize in 9 ) your database was fully open for sql injection before that little extra check in the query. Figured I would take the time and help you out with this one since I got help from you. Chan needed a few days extra to lay a new Theme base before we need to focus fully on this upgrade here.
Best of luck with the project!
0 replies

Labels

None yet

Statistics

  • Views 0 views
  • Posts 27 posts
  • Votes 0 votes
  • Topic users 2 members

2 participants

F
F
Falk 131
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 11 questions
A
A
  • Senior Member, joined since
  • Contributed 725 posts on the community forums.
  • Started 128 threads in the forums
  • Started this discussions

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet