PHP Help

SpaceshipSpaceship
Watch

jdickson

Established Member
Impact
1
I have a website that a friend did some PHP programming for last year and it is not working now. Here is my problem. It is a sports website, and users are submitting schedules. The database tables are: Schedule_Event & Schedule. There is 1 text box where the user enters their team with approx. 30 input boxes where the user enters: Date, Location, and Opponent. Here is the code he wrote me:

PHP:
<?

if ($New == 1 ) {
	mysql_connect("localhost", "***", "***");
	mysql_select_db("***");
	$rsSeason = mysql_query("SELECT Season_ID FROM Season WHERE Active = 1 LIMIT 1");
	$intSeason =  mysql_result($rsSeason,0);
	$schoolName = ereg_replace("'","//",$schoolName);
	mysql_query("INSERT INTO Schedule (Season_ID,School_Name,Status) VALUES ($intSeason,'$schoolName',0)");
					$rsSchedule_ID = mysql_query("SELECT Schedule_ID FROM Schedule WHERE Season_ID = $intSeason AND School_Name = '$schoolName' AND Status = 0 ORDER BY Schedule_ID DESC LIMIT 1");

$intSchedule_ID =  mysql_result($rsSchedule_ID,0);
	for ($i = 1; $i < 27; $i++) { 
		$strDate = ${"Date" .  $i};
		$strOpp = ${"Opponent" . $i};
		$strLoc = ${"Location" . $i};
		if ($strDate == "" && $strOpp == "" && $strLoc == "") {
		// they didnt input anything
		}else{
			mysql_query("INSERT INTO Schedule_Event (Schedule_ID,Event_Date,Opponent,Location) VALUES ($intSchedule_ID,'$strDate','$strOpp','$strLoc')");
			}
	}
	$strMessage = "Your schedule was successufully posted for review and duplicates.";
	
}
?>

The data is not inserting into the database. PLEASE HELP ME!
Schedule_Event:
Season_ID int(10)
Schedule_Event_ID int(10)
School_Name varchar(50)
Location varchar(60)
Opponent varchar(60)
Event_Date varchar(60)
Status int(1)

Schedule:
Season_ID int(10)
School_Name varchar(60)
Status int(1)
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
First of all, it helps if you put the code between [ PHP][ /PHP] "without spaces" ... I looked it over, and fixed a thing or two.. Didn't have much time so there may still be some things I over looked.. anyway:

PHP:
<?

if($New == 1 )
{
$db = mysql_connect("localhost", "***", "***");
mysql_select_db("***", $db);

$rsSeason = mysql_query("SELECT Season_ID FROM Season WHERE Active = '1' LIMIT 1");
$intSeason = mysql_result($rsSeason, 0);

$schoolName = str_replace("'", "//", $schoolName);

$query = mysql_query("INSERT INTO Schedule (Season_ID, School_Name, Status) VALUES($intSeason, '$schoolName', 0)") or die(mysql_error());

$rsSchedule_ID = mysql_query("SELECT Schedule_ID FROM Schedule WHERE Season_ID = $intSeason AND School_Name = '$schoolName' AND Status = '0' ORDER BY Schedule_ID DESC LIMIT 1");

$intSchedule_ID = mysql_result($rsSchedule_ID, 0);

for ($i = 1; $i < 27; $i++)
{
$strDate = "Date" . $i;
$strOpp = "Opponent" . $i;
$strLoc = "Location" . $i;
if($strDate == "" && $strOpp == "" && $strLoc == "")
{
// they didnt input anything
}
else
{
$q = mysql_query("INSERT INTO Schedule_Event (Schedule_ID, Event_Date, Opponent, Location) VALUES('$intSchedule_ID', '$strDate', '$strOpp', '$strLoc')") or die(mysql_error());
}
}

$strMessage = "Your schedule was successufully posted for review and duplicates.";

}
?>
 
0
•••
Thank you for your help. Sorry about the PHP code formatting, just a newbie here, and getting nervous as parents are trying to submit their kids schedules.

Many thanks
 
0
•••
No problem. :) Is it working for you now?


-Eric
 
0
•••
just for testing, replace "localhost" with localhost , and replace the = in queries with the word like.
 
0
•••
SecondVersion said:
No problem. :) Is it working for you now?


-Eric
No luck yet. When I press the 'Submit' button it just refreshes the page and does not insert into the database. For the form submit code it uses:

PHP:
<form action="<? print $PHP_SELF; ?>" method="POST" >

Would that be correct? Again, thank you guys for your help. The guy who did this only did it halfway and left it with me
 
0
•••
What value are you trying to insert ? Are there any quotes in the text that are not escaped ?
 
0
•••
jdickson said:
No luck yet. When I press the 'Submit' button it just refreshes the page and does not insert into the database. For the form submit code it uses:

PHP:
<form action="<? print $PHP_SELF; ?>" method="POST" >

Would that be correct? Again, thank you guys for your help. The guy who did this only did it halfway and left it with me
PHP:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >

Hmm, I'll have to look it over again. But just woke up so, not atm :p
 
0
•••
Here is the entire page:

PHP:
<? 

if($New == 1 ) 
{ 
$db = mysql_connect("***", "***", "***"); 
mysql_select_db("***", $db); 

$rsSeason = mysql_query("SELECT Season_ID FROM Season WHERE Active = '1' LIMIT 1"); 
$intSeason = mysql_result($rsSeason, 0); 

$schoolName = str_replace("'", "//", $schoolName); 

$query = mysql_query("INSERT INTO Schedule (Season_ID, School_Name, Status) VALUES($intSeason, '$schoolName', 0)") or die(mysql_error()); 

$rsSchedule_ID = mysql_query("SELECT Schedule_ID FROM Schedule WHERE Season_ID = $intSeason AND School_Name = '$schoolName' AND Status = '0' ORDER BY Schedule_ID DESC LIMIT 1"); 

$intSchedule_ID = mysql_result($rsSchedule_ID, 0); 

for ($i = 1; $i < 27; $i++) 
{ 
$strDate = "Date" . $i; 
$strOpp = "Opponent" . $i; 
$strLoc = "Location" . $i; 
if($strDate == "" && $strOpp == "" && $strLoc == "") 
{ 
// they didnt input anything 
} 
else 
{ 
$q = mysql_query("INSERT INTO Schedule_Event (Schedule_ID, Event_Date, Opponent, Location) VALUES('$intSchedule_ID', '$strDate', '$strOpp', '$strLoc')") or die(mysql_error()); 
} 
} 

$strMessage = "Your schedule was successufully posted for review and duplicates."; 

} 
?> 

<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
function MakeArray(n) {
	this.length = n
	return this
}
monthNames = new MakeArray(12)
monthNames[1] = "January"
monthNames[2] = "February"
monthNames[3] = "March"
monthNames[4] = "April"
monthNames[5] = "May"
monthNames[6] = "June"
monthNames[7] = "July"
monthNames[8] = "August"
monthNames[9] = "September"
monthNames[10] = "October"
monthNames[11] = "November"
monthNames[12] = "December"
dayNames = new MakeArray(7)
dayNames[1] = "Sunday"
dayNames[2] = "Monday"
dayNames[3] = "Tuesday"
dayNames[4] = "Wednesday"
dayNames[5] = "Thursday"
dayNames[6] = "Friday"
dayNames[7] = "Saturday"

function customDateString() {
	currentDate = new Date()
	var theDay = dayNames[currentDate.getDay() + 1]
	var theMonth = monthNames[currentDate.getMonth() + 1]
	msie4 = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 ));
	if (msie4) {
	    var theYear = currentDate.getYear()
	}
	else {
	     var theYear = currentDate.getYear() +1900
	}
	return theDay + ", " + theMonth + " " + currentDate.getDate() + ", " + theYear
}
//-->
</SCRIPT>
<STYLE>
FORM { margin-bottom : 0 px; margin-top : 0 px; }
BODY
{
scrollbar-face-color: #3300FF; scrollbar-shadow-color: #CCCCCC; 
scrollbar-highlight-color: #FFFFFF; scrollbar-3dlight-color: #FFFFFF; 
scrollbar-darkshadow-color: #FFFFFF; scrollbar-track-color: #CCCCCC; 
scrollbar-arrow-color: #FFEB00
}
</STYLE>

<style type="text/css">
A:link {text-decoration:none} A:visited {text-decoration:none} 
</style>
<link rel="stylesheet" href="ie.css">
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#0000ff" alink="#0000FF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="772" border="0" cellspacing="0" cellpadding="0">
  <tr valign="TOP"> 
    <td height="18" colspan="4"> 
      <?php include("../top.php"); ?>
    </td>
  </tr>
  <tr valign="top"> 
    <td height="20" colspan="4"> 
      <?php include("../banner.php"); ?>
    </td>
  </tr>
  <tr> 
    <td width="140" valign="top"> 
      <?php include("../menu.php"); ?>
    </td>
    <td width="632" colspan="3" valign="top"><div align="center"></div>
      <div align="left"> 
        <div align="center"> 
          <? 
					  if ($strMessage) {
					    print ("<font color=\"#990000\"><b>");
					  	print $strMessage;
						print ("</b></font>");
					  }
					  ?>
					    <form action="<? print $PHP_SELF; ?>" method="POST" >

         
            <table width="448" border="0" cellspacing="2" cellpadding="0">
              <tr> 
                <td colspan="3"> <div align="center"><b><font size="4" face="Arial, Helvetica, sans-serif">School's
                         Named</font></b></div></td>
                <td width="263"> <div align="left"> <b><font face="Arial, Helvetica, sans-serif"> 
                    <input name="schoolName" type="text" id="schoolName">
                    </font></b></div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"><b><font face="Arial, Helvetica, sans-serif"></font></b></td>
                <td width="105"> </td>
                <td width="263"><b><font face="Arial, Helvetica, sans-serif"></font></b></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"><font size="4"><b><font face="Arial, Helvetica, sans-serif">Date</font></b></font></div></td>
                <td width="105"> <div align="center"><font size="4" face="Arial, Helvetica, sans-serif"><b>Opponent</b></font></div></td>
                <td width="263"> <div align="center"><font size="4"><b><font face="Arial, Helvetica, sans-serif">Location</font></b></font></div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date1" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent1" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location1" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date2" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent2" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location2" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date3" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent3" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location3" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date4" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent4" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location4" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td height="22" width="80"> </td>
                <td height="22" width="80"> <div align="center"> 
                    <input type="text" name="Date5" size="10">
                  </div></td>
                <td height="22" width="105"> <input type="text" name="Opponent5" size="30"> 
                </td>
                <td height="22" width="263"> <div align="center"> 
                    <input type="text" name="Location5" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date6" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent6" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location6" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date7" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent7" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location7" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date8" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent8" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location8" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date9" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent9" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location9" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date10" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent10" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location10" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date11" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent11" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location11" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date12" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent12" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location12" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date13" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent13" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location13" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td height="22" width="80"> </td>
                <td height="22" width="80"> <div align="center"> 
                    <input type="text" name="Date14" size="10">
                  </div></td>
                <td height="22" width="105"> <input type="text" name="Opponent14" size="30"> 
                </td>
                <td height="22" width="263"> <div align="center"> 
                    <input type="text" name="Location14" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date15" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent15" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location15" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date16" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent16" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location16" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date17" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent17" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location17" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date18" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent18" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location18" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date19" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent19" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location19" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date20" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent20" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location20" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date21" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent21" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location21" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date22" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent22" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location22" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date23" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent23" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location23" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date24" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent24" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location24" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date25" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent25" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location25" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td width="80"> </td>
                <td width="80"> <div align="center"> 
                    <input type="text" name="Date26" size="10">
                  </div></td>
                <td width="105"> <input type="text" name="Opponent26" size="30"> 
                </td>
                <td width="263"> <div align="center"> 
                    <input type="text" name="Location26" size="30">
                  </div></td>
              </tr>
              <tr> 
                <td colspan="4" align="center"> </td>
              </tr>
              <tr> 
                <td colspan="4"> <div align="center"> 
                    <input type=hidden name="return_link_url" value="http://google.com.com/">
                    <input name="New" type=hidden id="New" value="1">
                    <input type="submit" name="Submit" value="Submit Schedule">
                  </div></td>
              </tr>
              <tr>
                <td colspan="4"> </td>
              </tr>
              <tr>
                <td colspan="4"><div align="center"><font face="Arial, Helvetica, sans-serif"></font></div></td>
              </tr>
            </table>
            <p> </p>
          </form>
        </div>
      </div></tr>
  <tr> 
    <td colspan="4" valign="top">  </td>
  </tr>
</table>
</body>
</html>
 
0
•••
anyone?
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
Appraise.net

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back