Hi all,
i am trying to check my database to see if someone hass already submitted a particular team name. so i have set up the if statment but it always returns the following:(the database is empty FYI)
0ROW EXSISTS
i thought by my code that im sating if the row is = to 0 run thi code.. if it no. display this message.,....
can anyone point me in the right direction? below is the full code of that page
<?
$Count = mysql_query("SELECT COUNT(*) FROM `group` WHERE `teamname` = '$TeamName'");
$row = mysql_fetch_array($Count, MYSQL_NUM);
echo $row[0];
if ($row=="0")
{
$sql=("INSERT INTO `group`(teamname, nickname, stadiumname, stadiumcapacity, country, league, rivalclub, town, website)
VALUES ('$TeamName', '$NickName', '$StadiumName', '$StadiumCapacity', '$country','$league', '$RivalClub', '$town', '$website')") or die(mysql_error());
}
else if ($row>"0")
{ echo "ROW EXSISTS"; }
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
?>
PHP Problem...
Moderator: General Moderators
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: PHP Problem...
Code: Select all
$rowCount = $row[0];
echo $rowCount;
if ($rowCount == 0) {
$sql=("INSERT INTO `group`(teamname, nickname, stadiumname, stadiumcapacity, country, league, rivalclub, town, website)
VALUES ('$TeamName', '$NickName', '$StadiumName', '$StadiumCapacity', '$country','$league', '$RivalClub', '$town', '$website')")
or die(mysql_error());
} else if ($rowCount > 0) {
echo "ROW EXSISTS";
}
Re: PHP Problem...
Please use the appropriate
Code: Select all
[ /code] tags when posting code blocks in the forums. Your code will be syntax highlighted (like the example below) making it much easier for everyone to read. You will most likely receive more answers too!
Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces. You can even start right now by editing your existing post!
If you are new to the forums, please be sure to read:
[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]
If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online. You'll find code samples, detailed documentation, comments and more.
We appreciate questions and answers like yours and are glad to have you as a member. Thank you for contributing to phpDN!
Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]Re: PHP Problem...
perfect. thanks.
where was i going wrong?
where was i going wrong?
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: PHP Problem...
You were comparing $row with 0 rather than $row[0], even though you'd echoed $row[0]besly98 wrote:where was i going wrong?