Jump to content

[SOLVED] if statement issues


rhoffer21

Recommended Posts

<?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

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.'');

 

 

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.'');

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";
?>

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']

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.