Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP Query MySQL with POST variable

Featured Replies

Evening all, I have a PHP\MySQL registration script which I'm looking to amend.

 

Currently you register using your Name, Company Name and Email Address. From there, your username and password are emailed to you.

 

A problem I have come across is anyone can register as the same company and this would prove troublesome for future use.

 

What I am looking to do is query the database and if an entry already exists for that company, die;

 

$company = mysql_real_escape_string($_POST['company']);
$query= "SELECT * FROM members WHERE company = '$company'"; 
$result = mysql_query($query) or die ("Error in query: $query " . mysql_error()); 
$row = mysql_fetch_array($result); 
$num_results = mysql_num_rows($result); 
if ($num_results > 0)
{
$err[]='Your company is already registered, please contact your admin user!';
}

However, that is showing a resource error.

 

Can anyone shed any light on what I am doing wrong?

Evening all, I have a PHP\MySQL registration script which I'm looking to amend.

 

Currently you register using your Name, Company Name and Email Address. From there, your username and password are emailed to you.

 

A problem I have come across is anyone can register as the same company and this would prove troublesome for future use.

 

What I am looking to do is query the database and if an entry already exists for that company, die;

 

$company = mysql_real_escape_string($_POST['company']);
$query= "SELECT * FROM members WHERE company = '$company'"; 
$result = mysql_query($query) or die ("Error in query: $query " . mysql_error()); 
$row = mysql_fetch_array($result); 
$num_results = mysql_num_rows($result); 
if ($num_results > 0)
{
$err[]='Your company is already registered, please contact your admin user!';
}

However, that is showing a resource error.

 

Can anyone shed any light on what I am doing wrong?

Whats the exact error it is showing? and why still use the mysql set of functions php.net warns against this. You should be using either mysqli or PDO

  • Author

Whats the exact error it is showing? and why still use the mysql set of functions php net warns against this. You should be using either mysqli or PDO

 

Sorry, its "Error in query: Resource id #6" I'm still picking up PHP as I go along, I'll look into mysqli

Edited by JaCEnt

 

 

Sorry, its "Error in query: Resource id #6" I'm still picking up PHP as I go along, I'll look into mysq

 

 

Sorry, its "Error in query: Resource id #6" I'm still picking up PHP as I go along, I'll look into mysqli

 

Can i see your html that holds the company name? that your posting into your query

  • Author

Can i see your html that holds the company name? that your posting into your query

 

                                <form action="" method="post">
                                        <h1>Not a member yet? Sign Up!</h1>

                    <?php

                                                if($_SESSION['msg']['reg-err'])
                                                {
                                                        echo '<div class="err">'.$_SESSION['msg']['reg-err'].'</div>';
                                                        unset($_SESSION['msg']['reg-err']);
                                                }

                                                if($_SESSION['msg']['reg-success'])
                                                {
                                                        echo '<div class="success">'.$_SESSION['msg']['reg-success'].'</div>';
                                                        unset($_SESSION['msg']['reg-success']);
                                                }
                                        ?>

                                        <label class="grey" for="fullName">Full Name:</label>
                                        <input class="field" type="text" name="fullName" id="fullName" value="" size="23" />
                                        <label class="grey" for="company">Company:</label>
                                        <input class="field" type="text" name="company" id="company" value="" size="23" />
                                        <label class="grey" for="email">Email:</label>
                                        <input class="field" type="text" name="email" id="email" size="23" />
                                        <label>A password will be e-mailed to you.</label>
                                        <input type="submit" name="submit" value="Register" class="bt_register" />
                                </form>

  • Author

Just put the code back in and its working now....How strange... I must have missed typed something - user error :)

Just put the code back in and its working now....How strange... I must have missed typed something - user error :)

Glad you got it working :) if you have anymore questions feel free to ask

PHP.net does warn against using mysql_...this will be phased out in the upcoming year so you need to learn mysqli or PDO as your site will cease to work afterward.

PHP.net does warn against using mysql_...this will be phased out in the upcoming year so you need to learn mysqli or PDO as your site will cease to work afterward.

No matter how many times u tell php this they still use mysql cause they claim mysqli and PDO is harder to learn or they just don't wanna change their entire site

  • 3 weeks later...

I think the best option is to work in some frameworks like codeigniter so that we don't need to worry about the connections. They will regularly update everything..

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.