nobackseat88
03-14-2008, 01:40 AM
It won't let me do this correctly? Im am trying to put a code in variables. Is this possible? Havn't gotten it to work. Let me know what you think.
What the following code is trying to accomplish is to connect to a database, get info whether or not something is set, and then depeding on whether or not it is set, display random events, where one event is trying to update something in a database.
<?php
mysql_connect("localhost", "database", "pass") or die(mysql_error());
echo "Connected to MySQL<br />";
$lala = mysql_query("SELECT * FROM event");
while($row = mysql_fetch_array($lala))
{
$txt = $row['event'];
if ($txt == "Y"){
$display = "no";
}
else {
$display = "yes";
}
if ($display == "yes"){
$quotes[] = "Random event 1
$result = mysql_query("UPDATE event SET event='Y' WHERE event='N'")
or die("Could not update");
$result = mysql_query("SELECT * FROM event WHERE event='Y'")
or die(mysql_error());";
$quotes[] = "Random Event 2";
$quotes[] = "Random Event 3";
$quotes[] = "Random Event 5";
$quotes[] = "Random Event 6";
$quotes[] = "Random Event 7";
srand ((double) microtime() * 1000000);
$randomquote = rand(0,count($quotes)-1);
echo "<p>" . $quotes[$randomquote] . "</p>";
}
else { echo "You've already got the random event!";
}
?>
I know there's something wrong this:
Line 15 $quotes[] = "Random event 1
Line 16 $result = mysql_query("UPDATE event SET event='Y' WHERE
Line 17 event='N'")
Line 18 or die("Could not update");
But I don't know what to do. If it put it as an echo statement inside the variable it messes it up more. In any event, I am getting this error:
Parse error: syntax error, unexpected T_STRING in /home/username/public_html/test/event.php on line 15
What the following code is trying to accomplish is to connect to a database, get info whether or not something is set, and then depeding on whether or not it is set, display random events, where one event is trying to update something in a database.
<?php
mysql_connect("localhost", "database", "pass") or die(mysql_error());
echo "Connected to MySQL<br />";
$lala = mysql_query("SELECT * FROM event");
while($row = mysql_fetch_array($lala))
{
$txt = $row['event'];
if ($txt == "Y"){
$display = "no";
}
else {
$display = "yes";
}
if ($display == "yes"){
$quotes[] = "Random event 1
$result = mysql_query("UPDATE event SET event='Y' WHERE event='N'")
or die("Could not update");
$result = mysql_query("SELECT * FROM event WHERE event='Y'")
or die(mysql_error());";
$quotes[] = "Random Event 2";
$quotes[] = "Random Event 3";
$quotes[] = "Random Event 5";
$quotes[] = "Random Event 6";
$quotes[] = "Random Event 7";
srand ((double) microtime() * 1000000);
$randomquote = rand(0,count($quotes)-1);
echo "<p>" . $quotes[$randomquote] . "</p>";
}
else { echo "You've already got the random event!";
}
?>
I know there's something wrong this:
Line 15 $quotes[] = "Random event 1
Line 16 $result = mysql_query("UPDATE event SET event='Y' WHERE
Line 17 event='N'")
Line 18 or die("Could not update");
But I don't know what to do. If it put it as an echo statement inside the variable it messes it up more. In any event, I am getting this error:
Parse error: syntax error, unexpected T_STRING in /home/username/public_html/test/event.php on line 15