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

 

 

Link to comment
Share on other sites

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