i am supposed to create a table with a status field using mysql which has to be enabled when the user subscribes with his email address and it has to be disabled when he unsubscribes.. i know boolean type is not there in mysql but i am not getting how to use tinyint and i dont know how to give the condition in PHP
create table using tinyint type
Page 1 of 15 Replies - 427 Views - Last Post: 15 March 2013 - 04:58 AM
Replies To: create table using tinyint type
#2
Re: create table using tinyint type
Posted 14 March 2013 - 08:39 PM
This is to send a newsletter to the email address from the database.. email address has been inserted in database and even the form is ready but i dont know hoe to set the status.. so can anybody tell me how to do it
#3
Re: create table using tinyint type
Posted 14 March 2013 - 09:42 PM
just set the tinyint to 1 for true and 0 for false... when checking in PHP, if it's 1, the user is subscribed. If it's 0, the user is not...
#4
Re: create table using tinyint type
Posted 15 March 2013 - 02:48 AM
in this code may i know what is wrong because even update is not working and even delete query is not working
but the message is displaying thats it
$id = $_GET['id'];
$email = $_POST['email'];
$conn = mysql_connect("localhost","root","");
mysql_select_db("sangeetha",$conn);
$sql = "delete from news where id='$id'";
//$sql = "delete from news where email='$email'";
//$sql = "update news set subscribed=0 where email='$email'";
$result = mysql_query($sql,$conn) or die(mysql_error());
If($result)
{
echo "You Are Unsubscribed Successfully";
}
mysql_close($conn);
but the message is displaying thats it
#5
Re: create table using tinyint type
Posted 15 March 2013 - 03:58 AM
Alright well you needa look at your lines 1 and 2. Not sure if you can send post information to a URL with GET variables? I'm unsure, I'm pretty sure I tried it before and it didn't work... Maybe just a server thing though. either way, if those variables are being set correctly, next issue.
You shouldn't be using mysql_*. It's old and deprecated... But it technically still works, so next issue.
Your SQL seems fine, besides the glaring SQL injection issue. Anybody can now execute SQL code in your database - which is very bad. But, next issue.
When you say "mysql_query() or die(say error)" you're basically saying "if mysql_query (nothing) else say error", so when you do the same exact thing right below it, it's sorta repetitive. Cause if mysql_query were to return false, it would have died and your script would have stopped there. So you know by the time the script gets to if($result) whether or not the query failed.
You should be checking for the affected rows instead of whether or not the query failed. The query could succeed but nothing could have changed/
You shouldn't be using mysql_*. It's old and deprecated... But it technically still works, so next issue.
Your SQL seems fine, besides the glaring SQL injection issue. Anybody can now execute SQL code in your database - which is very bad. But, next issue.
When you say "mysql_query() or die(say error)" you're basically saying "if mysql_query (nothing) else say error", so when you do the same exact thing right below it, it's sorta repetitive. Cause if mysql_query were to return false, it would have died and your script would have stopped there. So you know by the time the script gets to if($result) whether or not the query failed.
You should be checking for the affected rows instead of whether or not the query failed. The query could succeed but nothing could have changed/
#6
Re: create table using tinyint type
Posted 15 March 2013 - 04:58 AM
then how to delete the rows based on email address which is coming from the form or how to update the subscribed field to 0 which is set to 1 based on the email address
is this query correct
update news set subscribed=0 where email='$email'
is this query correct
update news set subscribed=0 where email='$email'
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|