Xtremer360 Posted October 27, 2008 Share Posted October 27, 2008 Form Insert "INSERT INTO shows (showname, showlabel, location, arena, date) VALUES ('".$_POST['names']."','".$_POST['showlabel']."','".$_POST['location']."','".$_POST['arena']."','".$_POST['date']."')"; Form print '<SCRIPT LANGUAGE="JavaScript" SRC="CalendarPopup.js"></SCRIPT>'; print '<SCRIPT LANGUAGE="JavaScript"> var cal = new CalendarPopup(); </SCRIPT>'; print '<form action="setupshow.php" method="post"name="form1" >'; print '<tr><td>Weekly Show or Pay-Per View:</td><td><select name="type" id="ajax1" onChange="ajaxGet();"><option value="">Select a Show Type</option>'; $query = 'SELECT type FROM showtypes ORDER BY type'; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)){ print "<option value=\"{$row['type']}\">{$row['type']}</option>\r"; } print '</select></td></tr>'; print "<tr><td>Show Name:</td><td><div id=\"shownam\"><select id=\"names\" onChange=\"ajaxGetL();\"></select></div></td></tr>"; print '<tr><td>Show Label:</td><td><input name="showlabel" id="label" type="text" readonly="true" size="5"></td></tr>'; print '<tr><td>Location:</td> '; print '<td><input name="location" type="text"></td></tr>'; print '<tr><td>Arena:</td> '; print '<td><input name="arena" type="text"></td></tr>'; print '<tr><td>Date:</td><td><input type="text" name="date" readonly="readonly" /> <a href="#" onClick="cal.select(document.forms[\'form1\'].date,\'anchor1\',\'MM/dd/yyyy\'); return false;"NAME="anchor1" ID="anchor1">Date Selector</a></td></tr>'; print '<tr><th colspan=2><input name="submit" type="submit" value="Submit"><input name="sumbitted" type="hidden" value="TRUE"></th></tr></table></form><br><br><br>'; Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted October 27, 2008 Share Posted October 27, 2008 You may have to put 'date' in backquotes because 'DATE' is a MySQL keyword. "INSERT INTO shows (showname, showlabel, location, arena, `date`) VALUES ('".$_POST['names']."','".$_POST['showlabel']."','".$_POST['location']."','".$_POST['arena']."','".$_POST['date']."')"; Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted October 27, 2008 Author Share Posted October 27, 2008 But what about my problem of it now posting the show name Quote Link to comment Share on other sites More sharing options...
Alt_F4 Posted October 27, 2008 Share Posted October 27, 2008 your problem is in this line: print "<tr><td>Show Name:</td><td><div id=\"shownam\"><select id=\"names\" onChange=\"ajaxGetL();\"></select></div></td></tr>"; you have omitted the 'name' attribute of the select tag it is always a good idea to echo your query to the browser to make sure that it is receiving the variable correctly. Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted October 27, 2008 Author Share Posted October 27, 2008 Still not. I put: print "<tr><td>Show Name:</td><td><div id=\"shownam\"><select name=\"showname\" id=\"names\" onChange=\"ajaxGetL();\"></select></div></td></tr>"; Quote Link to comment Share on other sites More sharing options...
Alt_F4 Posted October 27, 2008 Share Posted October 27, 2008 your POST variable is named 'names' so you should use that, not 'shownames' to echo your query to the browser do this: echo "INSERT INTO shows (showname, showlabel, location, arena, `date`) VALUES ('".$_POST['names']."','".$_POST['showlabel']."','".$_POST['location']."','".$_POST['arena']."','".$_POST['date']."')"; after this line: "INSERT INTO shows (showname, showlabel, location, arena, `date`) VALUES ('".$_POST['names']."','".$_POST['showlabel']."','".$_POST['location']."','".$_POST['arena']."','".$_POST['date']."')"; Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted October 27, 2008 Author Share Posted October 27, 2008 This is what shows up INSERT INTO shows (showname, showlabel, location, arena, `date`) VALUES ('','1','locationtest;','arenatest','10/08/2008') Quote Link to comment Share on other sites More sharing options...
Alt_F4 Posted October 27, 2008 Share Posted October 27, 2008 yep thats what i thought would show up see how the value you are trying to insert into the showname field of the database is an empty string ('')? this should have the value that has been selected from the select tag in your form, so that mean that the data is not getting from your form to the PHP query. like i said your issue is still with this line: print "<tr><td>Show Name:</td><td><div id=\"shownam\"><select name=\"showname\" id=\"names\" onChange=\"ajaxGetL();\"></select></div></td></tr>"; only this time the name you have given the select tag (\"showname\") does not match the POST variable you are trying to retreive it with ($_POST['names']). Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted October 27, 2008 Author Share Posted October 27, 2008 I am starting to understand my problem but still confused. What should that it be? Quote Link to comment Share on other sites More sharing options...
Alt_F4 Posted October 27, 2008 Share Posted October 27, 2008 Fine I'll do it for you. The solution is: print "<tr><td>Show Name:</td><td><div id=\"shownam\"><select name=\"names\" id=\"names\" onChange=\"ajaxGetL();\"></select></div></td></tr>"; instead of this: print "<tr><td>Show Name:</td><td><div id=\"shownam\"><select name=\"showname\" id=\"names\" onChange=\"ajaxGetL();\"></select></div></td></tr>"; that should make the form submit the value of the names select tag to the POST variable Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted October 27, 2008 Author Share Posted October 27, 2008 Nope. Here's my updated code for you. <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"> function ajaxGet() { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.getElementById('shownam').innerHTML = xmlHttp.responseText; ajaxGetL(); } } //alert("Selected: " + document.getElementById("ajax1").value); xmlHttp.open("GET","showAjax.php?type=" + document.getElementById("ajax1").value + "&rand=" + Math.random(),true); xmlHttp.send(null); } function ajaxGetL() { //alert("CALLED"); var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.getElementById('label').value = xmlHttp.responseText; } } //alert("Selected: " + document.getElementById("ajax1").value); xmlHttp.open("GET","showAjax.php?label=" + document.getElementById("names").value + "&rand=" + Math.random(),true); xmlHttp.send(null); } </script> </head> <body> <?php /* setupshow.php */ /* This form after submission takes the results of the form and makes a new show ready for adding matches. */ require ('database.php'); //This code runs if the form has been submitted if (isset($_POST['submit'])) { // now we insert it into the database $insert = "INSERT INTO shows (showname, showlabel, location, arena, `date`) VALUES ('".$_POST['showname']."','".$_POST['showlabel']."','".$_POST['location']."','".$_POST['arena']."','".$_POST['date']."')"; echo "INSERT INTO shows (showname, showlabel, location, arena, `date`) VALUES ('".$_POST['names']."','".$_POST['showlabel']."','".$_POST['location']."','".$_POST['arena']."','".$_POST['date']."')"; $add_show = mysql_query($insert) or die(mysql_error()); } print '<center><caption><strong>Create A Show</strong></caption></center>'; print '<table border="1" align="center" style="margin: auto; width: 60%;">'; print '<SCRIPT LANGUAGE="JavaScript" SRC="CalendarPopup.js"></SCRIPT>'; print '<SCRIPT LANGUAGE="JavaScript"> var cal = new CalendarPopup(); </SCRIPT>'; print '<form action="setupshow.php" method="post"name="form1" >'; print '<tr><td>Weekly Show or Pay-Per View:</td><td><select name="type" id="ajax1" onChange="ajaxGet();"><option value="">Select a Show Type</option>'; $query = 'SELECT type FROM showtypes ORDER BY type'; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)){ print "<option value=\"{$row['type']}\">{$row['type']}</option>\r"; } print '</select></td></tr>'; print "<tr><td>Show Name:</td><td><div id=\"shownam\"><select name=\"names\" id=\"names\" onChange=\"ajaxGetL();\"></select></div></td></tr>"; print '<tr><td>Show Label:</td><td><input name="showlabel" id="label" type="text" readonly="true" size="5"></td></tr>'; print '<tr><td>Location:</td> '; print '<td><input name="location" type="text"></td></tr>'; print '<tr><td>Arena:</td> '; print '<td><input name="arena" type="text"></td></tr>'; print '<tr><td>Date:</td><td><input type="text" name="date" readonly="readonly" /> <a href="#" onClick="cal.select(document.forms[\'form1\'].date,\'anchor1\',\'MM/dd/yyyy\'); return false;"NAME="anchor1" ID="anchor1">Date Selector</a></td></tr>'; print '<tr><th colspan=2><input name="submit" type="submit" value="Submit"><input name="sumbitted" type="hidden" value="TRUE"></th></tr></table></form><br><br><br>'; print '<center><caption><strong>List of shows</strong></caption></center>'; print '<table width="60%" border="1" align="center">'; print '<tr><th align="center">Show Name</th><th align="center">Show Label</th><th align="center">Location</th><th align="center">Arena</th><th align="center">Date</th><th align="center">Edit</th><th align="center">Delete</th></tr>'; if(!isset($_GET['action']) && !isset($_POST['name'])) { //Define the query $query = "SELECT * FROM shows"; if ($r = mysql_query ($query)) // Run the query. { if (mysql_num_rows($r) > 0) { // Retrieve and print every record while ($row = mysql_fetch_array ($r)) { print '<tr><td align="center">'.$row['showname'].'</td><td align="center">'.$row['showlabel'].'</td><td align="center">'.$row['location'].'</td><td align="center">'.$row['arena'].'</td><td align="center">'.$row['date'].'</td><td align="center"><a href="addshowname.php?action=edit&id='.$row['id'].'"><center>Edit</center></a></td><td align="center"><a href="addshowname.php?action=delete&id='.$row['id'].'">Delete</a></td></tr>'; } }else{ print "<center>No shows</center>\n"; } }else{ die ('<p>Could not retrieve the data because <b>' . mysql_error() . '</b>. The query was '."$query.".'</p>'); } //End of query IF print '</table>'; } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
Alt_F4 Posted October 27, 2008 Share Posted October 27, 2008 Nope. Here's my updated code for you. // now we insert it into the database $insert = "INSERT INTO shows (showname, showlabel, location, arena, `date`) VALUES ('".$_POST['showname']."','".$_POST['showlabel']."','".$_POST['location']."','".$_POST['arena']."','".$_POST['date']."')"; echo "INSERT INTO shows (showname, showlabel, location, arena, `date`) VALUES ('".$_POST['names']."','".$_POST['showlabel']."','".$_POST['location']."','".$_POST['arena']."','".$_POST['date']."')"; print "<tr><td>Show Name:</td><td><div id=\"shownam\"><select name=\"names\" id=\"names\" onChange=\"ajaxGetL();\"></select></div></td></tr>"; Of course it doesn't! The point i am trying to make is that you need to have the name of the select tag and the POST variable the same. You have now changed both of them rather than just the one! change this line only: $insert = "INSERT INTO shows (showname, showlabel, location, arena, `date`) VALUES ('".$_POST['showname']."','".$_POST['showlabel']."','".$_POST['location']."','".$_POST['arena']."','".$_POST['date']."')"; to this $insert = "INSERT INTO shows (showname, showlabel, location, arena, `date`) VALUES ('".$_POST['names']."','".$_POST['showlabel']."','".$_POST['location']."','".$_POST['arena']."','".$_POST['date']."')"; Quote Link to comment 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.