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
https://forums.phpfreaks.com/topic/37640-mysql-num-rows/
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
https://forums.phpfreaks.com/topic/37640-mysql-num-rows/#findComment-180074
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
https://forums.phpfreaks.com/topic/37640-mysql-num-rows/#findComment-180079
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
https://forums.phpfreaks.com/topic/37640-mysql-num-rows/#findComment-180081
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
https://forums.phpfreaks.com/topic/37640-mysql-num-rows/#findComment-180093
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.