rhoffer21 Posted December 27, 2008 Share Posted December 27, 2008 <?php include 'config.php'; include 'opendb.php'; $game = $_POST['game']; $date = $_POST['date']; $away = $_POST['away']; $home = $_POST['home']; $time = $_POST['time']; $field = $_POST['field']; $delete = $_POST['delete']; echo "delete equals " .$delete. "<br>"; if ($delete = 1) { mysql_query('DELETE FROM schedule WHERE id = '.$game.''); echo "The game has been deleted!"; } else { mysql_query('INSERT INTO schedule(date) VALUES '.$date.' WHERE id = '.$game.''); mysql_query('INSERT INTO schedule(away) VALUES '.$away.' WHERE id = '.$game.''); mysql_query('INSERT INTO schedule(home) VALUES '.$home.' WHERE id = '.$game.''); mysql_query('INSERT INTO schedule(time) VALUES '.$time.' WHERE id = '.$game.''); mysql_query('INSERT INTO schedule(field) VALUES '.$field.' WHERE id = '.$game.''); echo "The Game has been changed succesfully!"; } include 'closedb.php'; ?> That is my code. Everytime this script is run the part beneath the if ($delete = 1) is run. I added the echo "delete equals " .$delete. "<br>"; to the page to show me what delete equals. delete equals 1 when it is supposed to and it doesnt equal 1 when its not supposed to but it runs through the part every time and it doesn't run the else part ever. any ideas? Link to comment https://forums.phpfreaks.com/topic/138574-solved-if-statement-issues/ Share on other sites More sharing options...
MadTechie Posted December 27, 2008 Share Posted December 27, 2008 if ($delete == 1) == is a compare = is for setting Link to comment https://forums.phpfreaks.com/topic/138574-solved-if-statement-issues/#findComment-724565 Share on other sites More sharing options...
MadTechie Posted December 27, 2008 Share Posted December 27, 2008 if ($delete == 1) == is a compare = is for setting also you may want to change mysql_query('INSERT INTO schedule(date) VALUES '.$date.' WHERE id = '.$game.''); mysql_query('INSERT INTO schedule(away) VALUES '.$away.' WHERE id = '.$game.''); mysql_query('INSERT INTO schedule(home) VALUES '.$home.' WHERE id = '.$game.''); mysql_query('INSERT INTO schedule(time) VALUES '.$time.' WHERE id = '.$game.''); mysql_query('INSERT INTO schedule(field) VALUES '.$field.' WHERE id = '.$game.''); to mysql_query('INSERT INTO schedule(date, away, home, time, field) VALUES ('$date', '$away', '$home', '$time', '$field') WHERE id = '.$game.''); Link to comment https://forums.phpfreaks.com/topic/138574-solved-if-statement-issues/#findComment-724567 Share on other sites More sharing options...
PFMaBiSmAd Posted December 27, 2008 Share Posted December 27, 2008 INSERT's don't have WHERE clauses. I'm going to guess that is supposed to be an UPDATE query. Link to comment https://forums.phpfreaks.com/topic/138574-solved-if-statement-issues/#findComment-724570 Share on other sites More sharing options...
MadTechie Posted December 27, 2008 Share Posted December 27, 2008 LOL, i didn't even notice Link to comment https://forums.phpfreaks.com/topic/138574-solved-if-statement-issues/#findComment-724572 Share on other sites More sharing options...
rhoffer21 Posted December 27, 2008 Author Share Posted December 27, 2008 That all worked great, the only problem im having now is that its not actually updating. I checked all the variables and they are all correct. mysql_query('UPDATE schedule SET date = '.$date.', away = '.$away.', home = '.$home.', time = '.$time.', field = '.$field.' WHERE id = '.$game.''); Link to comment https://forums.phpfreaks.com/topic/138574-solved-if-statement-issues/#findComment-724574 Share on other sites More sharing options...
MadTechie Posted December 27, 2008 Share Posted December 27, 2008 try this mysql_query('UPDATE schedule SET `date` = '.$date.', `away` = '.$away.', `home` = '.$home.', `time` = '.$time.', `field` = '.$field.' WHERE id = '.$game) or die(mysql_error()); error what the error is Link to comment https://forums.phpfreaks.com/topic/138574-solved-if-statement-issues/#findComment-724578 Share on other sites More sharing options...
rhoffer21 Posted December 27, 2008 Author Share Posted December 27, 2008 no error, its just not changing my data at all. Link to comment https://forums.phpfreaks.com/topic/138574-solved-if-statement-issues/#findComment-724582 Share on other sites More sharing options...
MadTechie Posted December 27, 2008 Share Posted December 27, 2008 try this <?php $query = "UPDATE schedule SET `date` = '$date', `away` = '$away', `home` = '$home', `time` = '$time', `field` = '$field' WHERE id = '$game'"; $result = mysql_query($query) or die($query.mysql_error()); $X = mysql_affected_rows(); echo "$query Affected: $X"; ?> Link to comment https://forums.phpfreaks.com/topic/138574-solved-if-statement-issues/#findComment-724586 Share on other sites More sharing options...
rhoffer21 Posted December 27, 2008 Author Share Posted December 27, 2008 Well that worked. IM not sure why but it did Thanks. Link to comment https://forums.phpfreaks.com/topic/138574-solved-if-statement-issues/#findComment-724589 Share on other sites More sharing options...
MadTechie Posted December 27, 2008 Share Posted December 27, 2008 review the single quotes 'UPDATE schedule SET `date` = '.$date.', its not quoting the values UPDATE schedule SET `date` = 11/22/2008' date='[/quote'] "UPDATE schedule SET `date` = '$date' UPDATE schedule SET `date` = '11/22/2008'' date='[/quote'] Link to comment https://forums.phpfreaks.com/topic/138574-solved-if-statement-issues/#findComment-724592 Share on other sites More sharing options...
rhoffer21 Posted December 27, 2008 Author Share Posted December 27, 2008 ahh i see. Thanks a lot. Link to comment https://forums.phpfreaks.com/topic/138574-solved-if-statement-issues/#findComment-724594 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.