Can I see more of the code, please?
| SitePoint Sponsor |
Can I see more of the code, please?
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
Here it is:
It works fine when I use this:
$query = "INSERT INTO test2 (play_date) VALUES ('2008:10:10 10:10:10')";
This does not work:
$query = "INSERT INTO test2 (play_date) VALUES ('$play_date')";
Could there be something wrong with my mysql database setup in Hostmonster?
I've tried formatting play_date to DATETIME and TIMESTAMP...both seem to accept the Y-m-d H:i:s format if you give them direct numbers.
<?php # Script 13.6
// Include the configuration file for error management and such.
require_once ('./includes/config.inc.php');
// Set the page title and include the HTML header.
$page_title = 'Test';
include ('./includes/header.html');
if (isset($_POST['submitted'])) { // Handle the form.
require_once ('../mysql_connect.php'); // Connect to the database.
// Check for a play date
if (!empty($_POST['play_date'])) {$play_date= escape_data($_POST['play_date']);
} else {
$play_date= FALSE;
echo '<p><font color="red" size="+1">Please check the box!</font></p>';
}
if ($play_date) { // If everything's OK.
// Add the user.
$query = "INSERT INTO test2 (play_date) VALUES ('2008:10:10 10:10:10')";
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
if (mysql_affected_rows() == 1) { // If it ran OK.
echo $query;
// Finish the page.
echo '<h3>Thank you for signing up. See you on Sunday!</h3>';
include ('./includes/footer.html'); // Include the HTML footer.
exit();
} else { // If it did not run OK.
echo '<p><font color="red" size="+1">You could not be registered due to a system error. We apologize for any inconvenience.</font></p>';
}
} else { // If one of the data tests failed.
echo '<p><font color="red" size="+1">Please try again.</font></p>';
}
mysql_close(); // Close the database connection.
} // End of the main Submit conditional.
?>
<h1>Sign me up!</h1>
<?
$timezone = date_default_timezone_set("America/Chicago");
$date1=strtotime("now");
$play_date = date("Y-m-d H:i:s", strtotime("Sunday", $date1));
echo $play_date;
$date2=strtotime("last week");
$lastweek_date = strtotime("Sunday", $date2);
echo date ("l F j, Y", $lastweek_date);
$user_id=$_SESSION['user_id'];
?>
<form action="test.php" method="post">
<fieldset>
<p><b>Sign me up to play this <?php echo date ($play_date);?> </b> <input type="radio"
name="play_date" value="$play_date"/></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Sign me up!" /></div>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php // Include the HTML footer.
include ('./includes/footer.html');
?>
Apache version 1.3.37 (Unix)
PHP version 5.1.6
MySQL version 5.0.27-standard-log
Operating system Linux
I've found your problem:
change it to:PHP Code:<p><b>Sign me up to play this <?php echo date ($play_date);?> </b> <input type="radio"
name="play_date" value="$play_date"/></p>PHP Code:<p><b>Sign me up to play this <?php echo date ($play_date);?> </b> <input type="radio"
name="play_date" value="<?php echo $play_date; ?>"/></p>
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
IT WORKS!!!
Thanks so much for sticking with me Arkinstall! You Rock!!
I'm sure I'll have more questions as I try to develop my little fun website...but man...that problem was killing me...thanks so much!
newb40
Apache version 1.3.37 (Unix)
PHP version 5.1.6
MySQL version 5.0.27-standard-log
Operating system Linux
Its alright![]()
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
Bookmarks