Question about php code.?

  • Thread starter Thread starter WYSIWYG
  • Start date Start date
W

WYSIWYG

Guest
Hi. in php i have the below code:

$results = mysql_query
("select user from lecturer where user =
'$_POST[user]'");

This i believe puts a list of results in the $results record set. Now... i am doing this so that a list will be produced in the record sec that has the same name as the variable $_POST[user] which is from a form. I am doing this to check if the user name given by the form is availible. If the record set is empty the name given by the form can not be in use.

The part of code i am not sure about is next. I have:

if ($row_results == 0) {mysql_query("INSERT INTO........

Its specifically the if ($row_results == 0) part i am unsure about. I beleive it means if the number of rows in the record set is equal to 0 do the following thing.... is this true for what it means? If it does not mean this what do i have to add or change to make it do this. Thanks.
 
Best place for answer for php..

command line irc client: ' irssi '
server: irc.freenode.net
channel: #php

after installing, open it.
- connect to a server ' /server irc.freenode.net '
- join a channel ' /join #php '
- be polite, know how to paste code (rafb.net/paste), there are 100s of users to help you.
==============================

Firstly.. check the input for security sake
- htmlentities($_POST['user']) or stripslashes($_POST['user'])
- google 'SQL injection attack'

Check here

- [ http://ca3.php.net/mysql_query ] example # 2
- [ http://ca3.php.net/manual/en/function.mysql-result.php ] example 1

mysql_result() is what your looking for..

<code>
$result = mysql_query('SELECT name FROM work.employee');
if (!$result) {
die('Could not query:' . mysql_error());
}
</code>
 
Well, I don't know what you put into $row_results, but mysqli_num_rows() will help you out. Put in there the variable which has the selected data.
 
Back
Top