Jump to content

mysql num rows


only one

Recommended Posts

heres my code

$checkuser = mysql_query("SELECT username FROM clanapps WHERE username = '$username'");
$username_exist = mysql_num_rows($checkuser);

 

heres the error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/www/d-pures.freehostia.com/pages/Apply.php on line 9

 

 

Link to comment
Share on other sites

<?php

if (isset($_POST["clan"])) {

$username = $_POST["user"];

if($clan==NULL) {

echo "A field was left blank.";

}else{

$checkuser = mysql_query("SELECT username FROM clanapps WHERE username='$username'");

$username_exist = mysql_num_rows($checkuser);

 

if ($username_exist>0) {

echo "You have already applied";

}else{

$query = "INSERT INTO clanapps (`username`, `clan`) VALUES('$username','$clan)";

mysql_query($query) or die(mysql_error());

echo "you succefully applied for $clan";

}}}

?>

Link to comment
Share on other sites

hmm.

Try:

<?php
if (isset($_POST["clan"])) {
$username = $_POST['user'];
if($clan==NULL) {
echo "A field was left blank.";
}else{
$checkuser = mysql_query("SELECT `username` FROM `clanapps` WHERE `username`='".$username."'");
$username_exist = mysql_num_rows($checkuser);

if ($username_exist>0) {
echo "You have already applied";
}else{
$query = "INSERT INTO clanapps (`username`, `clan`) VALUES('$username','$clan)";
mysql_query($query) or die(mysql_error());
echo "you succefully applied for $clan";
}}}
?>

Link to comment
Share on other sites

You are missing a ' in this line;

 

$query = "INSERT INTO clanapps (`username`, `clan`) VALUES('$username','$clan)";

 

It should look like this;

 

$query = "INSERT INTO clanapps (`username`, `clan`) VALUES('$username','$clan')";

 

It might not be actually inserting the info because of the error in that syntax.

Link to comment
Share on other sites

oops just realised, i didnt coppy the full error, if it makes much difference

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/www/d-pures.freehostia.com/pages/Apply.php on line 9

Unknown column 'username' in 'field list'

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.