Jump to content

Recommended Posts

Hi I have done this IF statment using PHP and MYSQL so far and its not showing the results I want its 1:18am and I need to get it done now! :( can anybody help, please..

 

 

$result = mysql_query("SELECT * FROM People WHERE Access='1'");

if ($result)

  {

  echo"Access";

  }

else

  {

  echo"No Access";

  }

?>  :shrug: :shrug:

Link to comment
https://forums.phpfreaks.com/topic/210097-mysql-query-help/
Share on other sites

Hi ix.selken, this is the code: (I am using Phpmyadmin for mysql database and dreamweaver to make the php in)

 

 

<?php

$con = mysql_connect("********","********","********");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("names", $con);

 

$result = mysql_query("SELECT * FROM People WHERE Access='1'");

if ($result)

  {

  echo"Access";

  }

else

  {

  echo"No Access";

  }

?>

 

 

 

Hi abdbuet oh rite thats cool but I need an IF statement in there as I need 2 optional outcomes, thats the thing. I just need it to say if value in the "Access" colum equlas "1" then it will "Access" the user if not "No Access", Thanks.

 

 

Link to comment
https://forums.phpfreaks.com/topic/210097-mysql-query-help/#findComment-1096533
Share on other sites

I also forgot to add that When I run this query it only displays one output either "Access" or "No Access".  When I change the value to "0" it still stays the same output as before. so the query does work it just doesn't show either option when the value is changed to either "1" or "0", if you get me, thanks.

Link to comment
https://forums.phpfreaks.com/topic/210097-mysql-query-help/#findComment-1096542
Share on other sites

mysql_query() for a SELECT query either returns a result resource if the query executed without error or it returns a FALSE value if the query fails due to an error. A query that matches zero rows is a successful query and returns a result resource.

 

Your if/else code -

if ($result)
  {
  echo"Access";
  }
else
  {
  echo"No Access";
  }

 

will echo "Access" as long as the query executes without any errors, even if it matches zero rows.

 

You would want to use mysql_num_rows() inside the TRUE branch of the if/else statement to find out if the query returned any rows.

 

Also, your query makes little sense. You are only asking if there are any rows with Access='1'. Do you in fact want to test if a specific visitor has his access value set to 1?

Link to comment
https://forums.phpfreaks.com/topic/210097-mysql-query-help/#findComment-1096688
Share on other sites

Hi PFMaBiSmAd, oh rite so what I am trying to do is, I have made a visual basic program were when the member log s in it sends a value "1" to the mysql n wen the member logs out it sends a value "0" to the mysql.

 

So im using this php and mysql to connect to databse so when user log s  in, the php will pik up on the databse and the value wil be"1" it will show a red image in the php, then when user logs out it that value in mysql change to "0" then the colours goes green in the php, this is what im trting to do but not working this is the code I got so far, please let me know. i dont think the "mysql_num_rows()" will work for what I am trying to do.

 

 

<?php

$con = mysql_connect("*****","*****","*****");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("table");

 

$query = mysql_query("SELECT * FROM 'people' WHERE 'Access'='1'");

 

if ($query)

  {

  echo'<img src="red.jpg">';

  }

else

  {

  echo'<img src="green.jpg">';   

  }

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/210097-mysql-query-help/#findComment-1096711
Share on other sites

The following link is the definition of what mysql_query() returns, which I repeated in the post I wrote above - http://php.net/mysql_query

 

If you are not gong to read and follow the information that exists for a programming language, you will not be able to write code that works.

Link to comment
https://forums.phpfreaks.com/topic/210097-mysql-query-help/#findComment-1096713
Share on other sites

oh im not sure on any of these -  mysql_fetch_array()  mysql_num_rows()  mysql_affected_rows() i tired to add it to the code but nothing happens or just one image would appear and they are not responding to the actual databse bieng updating. i am a bit of a NOOB unfortunantly.

Link to comment
https://forums.phpfreaks.com/topic/210097-mysql-query-help/#findComment-1096756
Share on other sites

mmmmm I did try it but nothing getting done right the code is not repeating  and sometimes causes errors. i have a seperate program that updates the value of the field in a table from "1" to "0" all the time when someone logs in and out so its allways getting updated i need php code to get this ALL the time,

 

can someone write the code giving indication what to do, been on this for 3 days got 2 days to finish this :( if you could would be much appriciated...

Link to comment
https://forums.phpfreaks.com/topic/210097-mysql-query-help/#findComment-1097126
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.