February 17, 201313 yr 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?
February 17, 201313 yr 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
February 18, 201313 yr 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 February 18, 201313 yr by JaCEnt
February 18, 201313 yr 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
February 18, 201313 yr 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>
February 18, 201313 yr Author Just put the code back in and its working now....How strange... I must have missed typed something - user error
February 18, 201313 yr 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
February 26, 201313 yr 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.
February 26, 201313 yr 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
March 20, 201313 yr 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