GreenUser Posted June 26, 2008 Share Posted June 26, 2008 Hi all! My $_POST['when'] is not doing what I want. How can I rename it? It is taking a user submitted javascript calender date, which is set to be in mysql format. The code worked fine until I added this. I tried using DATE(), and DATE() 'when' ,'' and 'DATE: Manual Date', 'when' each on its own, to substitute but that didn't work. <?php if(isset($_POST['submit'])) { $sql = "INSERT INTO stories(cat_id, username, dateposted, location, when, datename, body, fri, fun, soh, con, sma, sex, hyg, mes, aut, est) VALUES('".$_POST['cat']."', '".$_SESSION['SESS_USERNAME']."', NOW(), '".$_POST['location']."', '".$_POST['when']."', <--- the problem '".$_POST['datename']."', '".$_POST['body']."', ".$_POST['fri'].", ".$_POST['fun'].", ".$_POST['soh'].", ".$_POST['con'].", ".$_POST['sma'].", ".$_POST['sex'].", ".$_POST['hyg'].", ".$_POST['mes'].", ".$_POST['aut'].", ".$_POST['est'].")"; ?> I can post the rest of the script but after mysql error and php error results I have narrowed it down to this. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/ Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 what is the value of $_POST['when'] and what is the datatype of the 'when' column? Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-574700 Share on other sites More sharing options...
GreenUser Posted June 26, 2008 Author Share Posted June 26, 2008 Datatype for 'when' column is simply Date. Value format is yyyy-mm-dd. <tr> <td>When</td> <td><input type="text" name="when"><a href="javascript:cal9.popup();"><img src="img/cal.gif"></a></td> </tr> Sorry to have left that out. Mysql Server V. is 5.0 and PHP is 5.2.1 Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-574727 Share on other sites More sharing options...
GreenUser Posted June 26, 2008 Author Share Posted June 26, 2008 *bump* For us night owl's Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-574800 Share on other sites More sharing options...
mmarif4u Posted June 26, 2008 Share Posted June 26, 2008 Before inserting, try to echo the 'when' variable,that either value is coming from the form or not. Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-574804 Share on other sites More sharing options...
GreenUser Posted June 26, 2008 Author Share Posted June 26, 2008 Thank you, fun exercise. Echoing that value results just perfectly. 2005-01-24 Like that. Hm, getting closer. I echoed echo "You entered: ".$_POST['when']; Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-574811 Share on other sites More sharing options...
mmarif4u Posted June 26, 2008 Share Posted June 26, 2008 After your query type this: echo $sql; It will show that either the query have the date value or not. if not then there is a problem in the code and may be in the table structure. Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-574823 Share on other sites More sharing options...
GreenUser Posted June 26, 2008 Author Share Posted June 26, 2008 Results are INSERT INTO stories(cat_id, username, dateposted, location, when, datename, body, fri, fun, soh, con, sma, sex, hyg, mes, aut, est) VALUES('1', 'John', NOW(), 'Alabama', 2008-06-15, 'adsfadsfadsfdsf', 'adsfadsfadsfadsfadsfadsfadsf', 7, 7, 7, 7, 7, 7, 7, 7, 7, 7) I thought I could replace '".$_POST['when']."', with 'DATE: Manual Date', 'when' Not sure how to set this one up. ??? Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-574840 Share on other sites More sharing options...
mmarif4u Posted June 26, 2008 Share Posted June 26, 2008 It means that query has the date value.Did your mysql query error reporting in ON. I mean after your query: $tab=mysql_query($sql) or die(mysql_error()); Just add this: or die(mysql_error()); Did you get any error. Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-574851 Share on other sites More sharing options...
GreenUser Posted June 26, 2008 Author Share Posted June 26, 2008 Here it gets You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'when, datename, body, fri, fun, soh, con, sma, sex, hyg, mes, aut, est) VALUE' at line 1 ... So, that narrows it down to the 'when' value, right? Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-574855 Share on other sites More sharing options...
mmarif4u Posted June 26, 2008 Share Posted June 26, 2008 Can you post the code. Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-574860 Share on other sites More sharing options...
GreenUser Posted June 26, 2008 Author Share Posted June 26, 2008 <?php session_start(); require("config.php"); require("db.php"); if(isset($_POST['submit'])) { $sql = "INSERT INTO stories(cat_id, username, dateposted, location, when, datename, body, fri, fun, soh, con, sma, sex, hyg, mes, aut, est) VALUES('".$_POST['cat']."', '".$_SESSION['SESS_USERNAME']."', NOW(), '".$_POST['location']."', ".$_POST['when'].", '".$_POST['datename']."', '".$_POST['body']."', ".$_POST['fri'].", ".$_POST['fun'].", ".$_POST['soh'].", ".$_POST['con'].", ".$_POST['sma'].", ".$_POST['sex'].", ".$_POST['hyg'].", ".$_POST['mes'].", ".$_POST['aut'].", ".$_POST['est'].")"; mysql_query($sql); header("Location: " . $config_basedir . "/index.php"); } else { require("header.php"); ?> <div id=main1> <form name="addstory" action="<?php echo $SCRIPT_NAME ?>" method="post"> <table> <tr> <td colspan='2'>Enter form.</td> </tr> <tr> <td>This was a</td> <td> <select name="cat"> <?php $catsql = "SELECT * FROM categories;"; $catres = mysql_query($catsql); while($catrow= mysql_fetch_assoc($catres)) { echo "<option value='" . $catrow['id'] . "'>" . $catrow['category'] . "</option>"; } ?> </select> </td> </tr> <tr> <td>Location</td> <td><select name="location"> <option value ="Alabama">Alabama</option> <option value ="California">California</option> <option value ="Colorado" selected="selected">Colorado</option> <option value ="New Hampshire">New Hampshire</option> <option value ="Massachusetts">Massachusetts</option> <option value ="Montana">Montana</option> </select></td> </tr> //////////////////////////// <tr> <td>When</td> <td><input type="text" name="when"><a href="javascript:cal9.popup();"><img src="img/cal.gif"></a></td> </tr> /////////////////////////// <tr> <td>Name (Of Your Date)</td> <td><input type="text" name="datename"></td> </tr><tr> <td>Rate Your Date</td> <td><textarea name="body" rows="10" cols="50"></textarea></td> </tr><tr> <td colspan='2'>rate these qualities from 1 to 10 (10 being ideal).</td> </tr> <tr> <td>fri</td> <td> <input type="radio" name="fri" value=1>1</option> <input type="radio" name="fri" value ="2">2</option> <input type="radio" name="fri" value ="3">3</option> <input type="radio" name="fri" value ="4">4</option> <input type="radio" name="fri" value ="5">5</option> <input type="radio" name="fri" value ="6">6</option> <input type="radio" name="fri" value ="7">7</option> <input type="radio" name="fri" value ="8">8</option> <input type="radio" name="fri" value ="9">9</option> <input type="radio" name="fri" value ="10">10</option> </td></tr><tr> <td>Fun</td> <td> <input type="radio" name="fun" value=1>1</option> <input type="radio" name="fun" value ="2">2</option> <input type="radio" name="fun" value ="3">3</option> <input type="radio" name="fun" value ="4">4</option> <input type="radio" name="fun" value ="5">5</option> <input type="radio" name="fun" value ="6">6</option> <input type="radio" name="fun" value ="7">7</option> <input type="radio" name="fun" value ="8">8</option> <input type="radio" name="fun" value ="9">9</option> <input type="radio" name="fun" value ="10">10</option> </td></tr><tr> <td>soh</td> <td> <input type="radio" name="soh" value ="1">1</option> <input type="radio" name="soh" value ="2">2</option> <input type="radio" name="soh" value ="3">3</option> <input type="radio" name="soh" value ="4">4</option> <input type="radio" name="soh" value ="5">5</option> <input type="radio" name="soh" value ="6">6</option> <input type="radio" name="soh" value ="7">7</option> <input type="radio" name="soh" value ="8">8</option> <input type="radio" name="soh" value ="9">9</option> <input type="radio" name="soh" value ="10">10</option> </td></tr><tr> <td>con</td> <td> <input type="radio" name="con" value ="1">1</option> <input type="radio" name="con" value ="2">2</option> <input type="radio" name="con" value ="3">3</option> <input type="radio" name="con" value ="4">4</option> <input type="radio" name="con" value ="5">5</option> <input type="radio" name="con" value ="6">6</option> <input type="radio" name="con" value ="7">7</option> <input type="radio" name="con" value ="8">8</option> <input type="radio" name="con" value ="9">9</option> <input type="radio" name="con" value ="10">10</option> </td></tr><tr> <td>sma</td> <td> <input type="radio" name="sma" value ="1">1</option> <input type="radio" name="sma" value ="2">2</option> <input type="radio" name="sma" value ="3">3</option> <input type="radio" name="sma" value ="4">4</option> <input type="radio" name="sma" value ="5">5</option> <input type="radio" name="sma" value ="6">6</option> <input type="radio" name="sma" value ="7">7</option> <input type="radio" name="sma" value ="8">8</option> <input type="radio" name="sma" value ="9">9</option> <input type="radio" name="sma" value ="10">10</option> </td></tr><tr> <td>sex</td> <td> <input type="radio" name="sex" value ="1">1</option> <input type="radio" name="sex" value ="2">2</option> <input type="radio" name="sex" value ="3">3</option> <input type="radio" name="sex" value ="4">4</option> <input type="radio" name="sex" value ="5">5</option> <input type="radio" name="sex" value ="6">6</option> <input type="radio" name="sex" value ="7">7</option> <input type="radio" name="sex" value ="8">8</option> <input type="radio" name="sex" value ="9">9</option> <input type="radio" name="sex" value ="10">10</option> </td></tr><tr> <td>hyg</td> <td> <input type="radio" name="hyg" value ="1">1</option> <input type="radio" name="hyg" value ="2">2</option> <input type="radio" name="hyg" value ="3">3</option> <input type="radio" name="hyg" value ="4">4</option> <input type="radio" name="hyg" value ="5">5</option> <input type="radio" name="hyg" value ="6">6</option> <input type="radio" name="hyg" value ="7">7</option> <input type="radio" name="hyg" value ="8">8</option> <input type="radio" name="hyg" value ="9">9</option> <input type="radio" name="hyg" value ="10">10</option> </td></tr><tr> <td>Mes</td> <td> <input type="radio" src="img/full.gif" name="mes" value ="1">1</option> <input type="radio" name="mes" value ="2">2</option> <input type="radio" name="mes" value ="3">3</option> <input type="radio" name="mes" value ="4">4</option> <input type="radio" name="mes" value ="5">5</option> <input type="radio" name="mes" value ="6">6</option> <input type="radio" name="mes" value ="7">7</option> <input type="radio" name="mes" value ="8">8</option> <input type="radio" name="mes" value ="9">9</option> <input type="radio" name="mes" value ="10">10</option> </td></tr><tr> <td>aut</td> <td> <input type="radio" name="aut" value ="1">1</option> <input type="radio" name="aut" value ="2">2</option> <input type="radio" name="aut" value ="3">3</option> <input type="radio" name="aut" value ="4">4</option> <input type="radio" name="aut" value ="5">5</option> <input type="radio" name="aut" value ="6">6</option> <input type="radio" name="aut" value ="7">7</option> <input type="radio" name="aut" value ="8">8</option> <input type="radio" name="aut" value ="9">9</option> <input type="radio" name="aut" value ="10">10</option> </td> </tr><tr> <td>est</td> <td> <input type="radio" name="est" value ="1">1</option> <input type="radio" name="est" value ="2">2</option> <input type="radio" name="est" value ="3">3</option> <input type="radio" name="est" value ="4">4</option> <input type="radio" name="est" value ="5">5</option> <input type="radio" name="est" value ="6">6</option> <input type="radio" name="est" value ="7">7</option> <input type="radio" name="est" value ="8">8</option> <input type="radio" name="est" value ="9">9</option> <input type="radio" name="est" value ="10">10</option> </td> </tr><tr> <td></td> <td><input type="submit" name="submit" value="Post Your Date!"></td> </tr> </table> </form> <script language="JavaScript"> var cal9 = new calendar3(document.forms['addstory'].elements['when']); cal9.year_scroll = true; cal9.time_comp = false; </script> </div> <br><br> <?php } require("footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-574864 Share on other sites More sharing options...
mmarif4u Posted June 26, 2008 Share Posted June 26, 2008 try this: $cat_id=mysql_real_escape_string($_POST['cat']); $user_in_session=$_SESSION['SESS_USERNAME']; $now=date('Y-m-d H:i:s'); $location=mysql_real_escape_string($_POST['location']); $when=mysql_real_escape_string($_POST['when']); $datename=mysql_real_escape_string($_POST['datename']); $body=mysql_real_escape_string($_POST['body']); $fri=mysql_real_escape_string($_POST['fri']); $fun=mysql_real_escape_string($_POST['fun']); $soh=mysql_real_escape_string($_POST['soh']); $con=mysql_real_escape_string($_POST['con']); $sma=mysql_real_escape_string($_POST['sma']); $sex=mysql_real_escape_string($_POST['sex']); $hyg=mysql_real_escape_string($_POST['hyg']); $mes=mysql_real_escape_string($_POST['mes']); $aut=mysql_real_escape_string($_POST['aut']); $est=mysql_real_escape_string($_POST['est']); if(isset($_POST['submit'])) { $sql = "INSERT INTO stories(cat_id, username, dateposted, location, when, datename, body, fri, fun, soh, con, sma, sex, hyg, mes, aut, est) VALUES('$cat_id', '$user_in_session', $now, '$location','$when','$datename', '$body','$fri','$fun','$soh','$con','$sma','$sex','$hyg' ,'$mes','$aut','$est')"; mysql_query($sql) or die(mysql_error()); header("Location: " . $config_basedir . "/index.php"); } Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-574872 Share on other sites More sharing options...
GreenUser Posted June 26, 2008 Author Share Posted June 26, 2008 Darn! Same error message that looked good too. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'when, datename, body, fri, fun, soh, con, sma, sex, hyg, mes, aut, est) VALUE' at line 1 Thanks for your help, I need to go to bed now. I'll report back with any new finds. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-574876 Share on other sites More sharing options...
mmarif4u Posted June 26, 2008 Share Posted June 26, 2008 So now your code looks ok.Just check your db table columns names and there data types.specially for datename. That what you are storing there and what is the data type. Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-574878 Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 The date needs single quotes around it: $sql = "INSERT INTO stories(cat_id, username, dateposted, location, when, datename, body, fri, fun, soh, con, sma, sex, hyg, mes, aut, est) VALUES('".$_POST['cat']."', '".$_SESSION['SESS_USERNAME']."', NOW(), '".$_POST['location']."', '".$_POST['when']."', '".$_POST['datename']."', '".$_POST['body']."', ".$_POST['fri'].", ".$_POST['fun'].", ".$_POST['soh'].", ".$_POST['con'].", ".$_POST['sma'].", ".$_POST['sex'].", ".$_POST['hyg'].", ".$_POST['mes'].", ".$_POST['aut'].", ".$_POST['est'].")"; Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-574951 Share on other sites More sharing options...
GreenUser Posted June 26, 2008 Author Share Posted June 26, 2008 Well, the problem was ... the 'when'! Can't name it that. Just like it won't take a value for 'int', when am I going to learn, lol. Thanks for help cats. Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-575266 Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 oh yeah...that too....wow, that is the 3rd post TODAY i've seen where the problem was MySQL Reserved Words Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-575268 Share on other sites More sharing options...
GreenUser Posted June 26, 2008 Author Share Posted June 26, 2008 MYSQL Reserved Words, I'm writing that down. Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-575275 Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 Best method: Don't use reserved words (http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html) Second Best: Always put backticks around field names aka: INSERT INTO `tablename` (`when`,`desc`,`rand`) VALUES ('a','b','c') Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-575285 Share on other sites More sharing options...
GreenUser Posted June 26, 2008 Author Share Posted June 26, 2008 Thanks for ref. Reminds me of the board in Battleship, which I sunk a few ships so far. Quote Link to comment https://forums.phpfreaks.com/topic/111953-solved-inserting-user-selected-time-value/#findComment-575299 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.