?
Solved

PHP / MySQL Insert

Posted on 2011-02-12
19
Medium Priority
?
418 Views
Last Modified: 2012-05-11
When I click submit on this form the data is not making it into the table. Any help would be appreciated. Please let me know if there is more information that would help.

Thank You

Form------------------------------------------>
<form action="insertevent.php" method="post">

<table border="1" cellspacing="0" cellpadding="0" align="center">

     <tr>
       <td>No Points Awarded:</td>
       <td>Date:</td>
       <td>Place:</td>
       <td>Start Time:</td>
       <td>Notes:</td>
       <td>Special Event:</td>
       </tr>
       <tr>
       <td><input type="checkbox" name="Points_Awarded" value="*"/></td>
     <td><input type="text" name="Date" /></td>
     <td><input type="text" name="Place" /></td>
     <td><input type="text" name="StartTime" /></td>
     <td><input type="text" name="Notes" /></td>
     <td><input type="text" name="Event" /></td>
       </tr>

<tr>
<td colspan="6" align="center"><input type="submit" name="submit" value="Add Event" /></td>
</tr>
</table>
</form>




insertevent.php---------------------------->
<?php
mysql_connect("mysql", "******", "******") or die ('Could not connect: ' . mysql_error());
mysql_select_db("RMDCRA");

$Points_Awarded = $_POST['Points_Awarded'];
$Date=$_POST['Date'];
$Place=$_POST['Place'];
$StartTime=$_POST['StartTime'];
$Notes=$_POST['Notes'];
$Event=$_POST['Event'];

$sql = mysql_query("INSERT INTO Schedule (`Race_Number`, `Points_Awarded`, `Date`, `Place`, `StartTime`, `Notes`, `Event`)
    VALUES (NULL, '$Points_Awarded', '$Date', '$Place', '$StartTime', '$Notes', '$Event', '$Phone')") or die(mysql_error());
header('Location: http://rmdcra.org/admin/Admin.php');
?>

0
Comment
Question by:patrickm12981
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
  • 2
  • +1
19 Comments
 
LVL 10

Assisted Solution

by:cyberstalker
cyberstalker earned 200 total points
ID: 34879509
The number of columns does not match. Remove the '$Phone' part from the values list.
0
 

Author Comment

by:patrickm12981
ID: 34879615
Thanks for that - still not working...

<?php
mysql_connect("mysql", "******", "******") or die ('Could not connect: ' . mysql_error());
mysql_select_db("RMDCRA");

$Points_Awarded = $_POST['Points_Awarded'];
$Date=$_POST['Date'];
$Place=$_POST['Place'];
$StartTime=$_POST['StartTime'];
$Notes=$_POST['Notes'];
$Event=$_POST['Event'];

$sql = mysql_query("INSERT INTO Schedule (`Race_Number`, `Points_Awarded`, `Date`, `Place`, `StartTime`, `Notes`, `Event`)
    VALUES (NULL, '$Points_Awarded', '$Date', '$Place', '$StartTime', '$Notes', '$Event')") or die(mysql_error());
header('Location: http://rmdcra.org/admin/Admin.php');
?>
0
 
LVL 10

Expert Comment

by:cyberstalker
ID: 34879750
What error are you getting? I do not see any other errors, besides the obvious sql injection dangers.

Try running the query manually to see what happens.
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 8

Assisted Solution

by:rationalboss
rationalboss earned 200 total points
ID: 34879753

<?php
mysql_connect("mysql", "******", "******") or die ('Could not connect: ' . mysql_error());
mysql_select_db("RMDCRA");

$Points_Awarded = $_POST['Points_Awarded'];
$Date=$_POST['Date'];
$Place=$_POST['Place'];
$StartTime=$_POST['StartTime'];
$Notes=$_POST['Notes'];
$Event=$_POST['Event'];

$sql = ("INSERT INTO Schedule (`Race_Number`, `Points_Awarded`, `Date`, `Place`, `StartTime`, `Notes`, `Event`)
    VALUES (NULL, '$Points_Awarded', '$Date', '$Place', '$StartTime', '$Notes', '$Event')");
echo $sql;
// or die(mysql_error());
//header('Location: http://rmdcra.org/admin/Admin.php');
?>

Open in new window

What is the output?
0
 

Author Comment

by:patrickm12981
ID: 34879855
Nothing was returned from the "echo $sql" it went back to the form page, no errors.
0
 
LVL 8

Expert Comment

by:rationalboss
ID: 34879921
That's odd, did you comment the redirection?
echo $sql should contain: INSERT INTO Schedule ....
0
 

Author Comment

by:patrickm12981
ID: 34879937
I copied and pasted exactly what you wrote....-> Here is the entire insertevent.php


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>insertevent.php</title>
</head>
<body>

<?php
<?php
mysql_connect("mysql", "****", "*****") or die ('Could not connect: ' . mysql_error());
mysql_select_db("RMDCRA");

$Points_Awarded = $_POST['Points_Awarded'];
$Date=$_POST['Date'];
$Place=$_POST['Place'];
$StartTime=$_POST['StartTime'];
$Notes=$_POST['Notes'];
$Event=$_POST['Event'];

$sql = ("INSERT INTO Schedule (`Race_Number`, `Points_Awarded`, `Date`, `Place`, `StartTime`, `Notes`, `Event`)
    VALUES (NULL, '$Points_Awarded', '$Date', '$Place', '$StartTime', '$Notes', '$Event')");
echo $sql;
// or die(mysql_error());
//header('Location: http://rmdcra.org/admin/Admin.php');
?> 

</body>
</html>

<!--
For Reference:
INSERT INTO `RMDCRA`.`Schedule` (
`Race_Number` ,
`PointsAwarded` ,
`Date` ,
`Place` ,
`StartTime` ,
`Notes` ,
`Event` 
)
VALUES (
NULL , '*', '2011-04-03', 'I-76 Speedway', NULL , NULL , 'Hot Laps'
);

-->

Open in new window

0
 

Author Comment

by:patrickm12981
ID: 34880036
Here is the entire forms page - Admin.php


<?php

// Inialize session
session_start();

// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['username'])) {
header('Location: index.php');
}

?>

<?php

error_reporting(E_ALL);
include("../includes/Header.html");
include("../includes/conn.php"); 
?>
<center><p><a href="logout.php">Logout</a></p></center>
<table width="930" align="center">
<tr>
<td valign="top">

<center><h2><u>Submit Daily Points Totals</u></h2></center>

<form action="insert.php" method="post">

<table border="1" cellspacing="0" cellpadding="0" align="center">
	<tr>
		<th>
		Race Date:
		</th>
		<td colspan="2">
		<?php
		$query="SELECT Race_Number, Date FROM Schedule WHERE PointsAwarded NOT LIKE '*' ORDER BY Date";
		$result2 = mysql_query($query) or die("Error executing:<br>$query<br>" . mysql_error() );

		echo "<select name=\"Race_Number\">";
		echo "<option></option>";
		while ($row=mysql_fetch_assoc($result2)) {
		echo "<option value=\"{$row['Race_Number']}\">{$row['Date']}</option>";
		}
		echo "</select>";
		?>
		</td>
	<tr>
		<th>Car Number</th>
		<th>Points</th>
	</tr>
<?php	
$sql = "SELECT Roster_Number, Car_Number FROM Roster";
$result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);

while(list($Roster_Number, $Car_Number)=mysql_fetch_row($result)){

echo '<tr><td>'.$Car_Number.'</td><td><input style="border: 1px solid #FFFFFF" type="text" name ="pointsarray['.$Roster_Number.']"/></td></tr>'."\n";
}
?>
<tr>
<td colspan="3" align="center"><input type="submit" name="submit" value="Submit Points" /></td>
</tr>
</table>
</form>
</td>
<td valign="top">

<center><h2><u>Edit Points</u></h2></center>

<form action="updatepoints.php" method="post">


<table border="1" cellspacing="0" cellpadding="0" align="center">
	<tr>
		<th>
		Race Date:
		</th>
		<td colspan="2">
		<?php
		$query="SELECT Race_Number, Date FROM Schedule WHERE PointsAwarded NOT LIKE '*' ORDER BY Date";
		$result2 = mysql_query($query) or die("Error executing:<br>$query<br>" . mysql_error() );

		echo "<select name=\"Race_Number\">";
		echo "<option></option>";
		while ($row=mysql_fetch_assoc($result2)) {
		echo "<option value=\"{$row['Race_Number']}\">{$row['Date']}</option>";
		}
		echo "</select>";
		?>
		</td>
	<tr>
		<th>Car Number</th>
		<th>Points</th>
	</tr>
<?php
$sql = "SELECT Roster_Number, Car_Number FROM Roster";
$result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);

while(list($Roster_Number, $Car_Number)=mysql_fetch_row($result)){

echo '<tr><td>'.$Car_Number.'</td><td><input style="border: 1px solid #FFFFFF" type="text" name ="pointsarray['.$Roster_Number.']"/></td></tr>'."\n";
}
?>
<tr>
<td colspan="3" align="center"><input type="submit" name="submit" value="Edit Points" /></td>
</tr>
</table>
</form>
</td>
<tr>
    
<td valign="top">
<center><h2><u>Submit Race Results</u></h2></center>

<form action="insertresults.php" method="post">
<?php
if($updated===TRUE)
	{echo '<div>Results Updated</div>';
	}
?>
<table border="1" cellspacing="0" cellpadding="0" align="center">
	<tr>
		<th>
			Race Date:
		</th>
		
		<td colspan="2">
			<?php
			$query2="SELECT Race_Number, Date FROM Schedule ORDER BY Date";
			$result3 = mysql_query($query2) or die("Error executing:<br>$query2<br>" . mysql_error() );

			echo "<select name=\"Race_Number\">";
			echo "<option></option>";
			while ($row=mysql_fetch_assoc($result3)) {
			echo "<option value=\"{$row['Race_Number']}\">{$row['Date']}</option>";
			}
			echo "</select>";
			?>
		</td>	
	</tr>
	
	<tr>
		<th>
			Event:
		</th>
		
		<td colspan="2">
			<?php
			$query3="SELECT Event FROM Events";
			$result4 = mysql_query($query3) or die("Error executing:<br>$query3<br>" . mysql_error() );

			echo "<select name=\"Event\">";
			echo "<option></option>";
			while ($row=mysql_fetch_assoc($result4)) {
			echo "<option>".$row['Event']."</option>";
			}
			echo "</select>";
			?>
		</td>
	</tr>
        
            <tr><td>1</td><td><input type="text" name="1" /></td></tr>
            <tr><td>2</td><td><input type="text" name="2" /></td></tr>
            <tr><td>3</td><td><input type="text" name="3" /></td></tr>
            <tr><td>4</td><td><input type="text" name="4" /></td></tr>
            <tr><td>5</td><td><input type="text" name="5" /></td></tr>
            <tr><td>6</td><td><input type="text" name="6" /></td></tr>
            <tr><td>7</td><td><input type="text" name="7" /></td></tr>
            <tr><td>8</td><td><input type="text" name="8" /></td></tr>
            <tr><td>9</td><td><input type="text" name="9" /></td></tr>
            <tr><td>10</td><td><input type="text" name="10" /></td></tr>
            <tr><td>11</td><td><input type="text" name="11" /></td></tr>
            <tr><td>12</td><td><input type="text" name="12" /></td></tr>
            <tr><td>13</td><td><input type="text" name="13" /></td></tr>
            <tr><td>14</td><td><input type="text" name="14" /></td></tr>
            <tr><td>15</td><td><input type="text" name="15" /></td></tr>
            <tr><td>16</td><td><input type="text" name="16" /></td></tr>
            <tr><td>17</td><td><input type="text" name="17" /></td></tr>
            <tr><td>18</td><td><input type="text" name="18" /></td></tr>
            <tr><td>19</td><td><input type="text" name="19" /></td></tr>
            <tr><td>20</td><td><input type="text" name="20" /></td></tr>
            <tr><td>21</td><td><input type="text" name="21" /></td></tr>
            <tr><td>22</td><td><input type="text" name="22" /></td></tr>
            <tr><td>23</td><td><input type="text" name="23" /></td></tr>
            <tr><td>24</td><td><input type="text" name="24" /></td></tr>
            <tr><td>25</td><td><input type="text" name="25" /></td></tr>
            <tr><td>26</td><td><input type="text" name="26" /></td></tr>
            <tr><td>27</td><td><input type="text" name="27" /></td></tr>
            <tr><td>28</td><td><input type="text" name="28" /></td></tr>
            <tr><td>29</td><td><input type="text" name="29" /></td></tr>
            <tr> <td>30</td><td><input type="text" name="30" /></td></tr>
            <tr><td>DNF1</td><td><input type="text" name="DNF1" /></td></tr>
            <tr><td>DNF2</td><td><input type="text" name="DNF2" /></td></tr>
            <tr><td>DNF3</td><td><input type="text" name="DNF3" /></td></tr>
            <tr><td>DNF4</td><td><input type="text" name="DNF4" /></td></tr>
            <tr><td>DNF5</td><td><input type="text" name="DNF5" /></td></tr>
            <tr><td>DNF6</td><td><input type="text" name="DNF6" /></td></tr>
            <tr><td>DNF7</td><td><input type="text" name="DNF7" /></td></tr>
            <tr><td>DNF8</td><td><input type="text" name="DNF8" /></td></tr>
            <tr><td>DNF9</td><td><input type="text" name="DNF9" /></td></tr>
            <tr><td>DNF10</td><td><input type="text" name="DNF10" /></td></tr>
            <tr><td>DNS1</td><td><input type="text" name="DNS1" /></td></tr>
            <tr><td>DNS2</td><td><input type="text" name="DNS2" /></td></tr>
            <tr><td>DNS3</td><td><input type="text" name="DNS3" /></td></tr>
            <tr><td>DNS4</td><td><input type="text" name="DNS4" /></td></tr>
            <tr><td>DNS5</td><td><input type="text" name="DNS5" /></td></tr>
            <tr><td>NT1</td><td><input type="text" name="NT1" /></td></tr>
            <tr><td>NT2</td><td><input type="text" name="NT2" /></td></tr>
            <tr><td>NT3</td><td><input type="text" name="NT3" /></td></tr>
            <tr><td>NT4</td><td><input type="text" name="NT4" /></td></tr>
            <tr><td>NT5</td><td><input type="text" name="NT5" /></td></tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="submit" value="Submit Results" /></td>
</tr>
</table>
</form>
</td>
<td valign="top">
<center><h2><u>Edit Race Results</u></h2></center>

<form action="updateresults.php" method="post">

<table border="1" cellspacing="0" cellpadding="0" align="center">
	<tr>
		<th>
			Race Date:
		</th>

		<td colspan="2">
			<?php
			$query2="SELECT Race_Number, Date FROM Schedule ORDER BY Date";
			$result3 = mysql_query($query2) or die("Error executing:<br>$query2<br>" . mysql_error() );

			echo "<select name=\"Race_Number\">";
			echo "<option></option>";
			while ($row=mysql_fetch_assoc($result3)) {
			echo "<option value=\"{$row['Race_Number']}\">{$row['Date']}</option>";
			}
			echo "</select>";
			?>
		</td>
	</tr>

	<tr>
		<th>
			Event:
		</th>

		<td colspan="2">
			<?php
			$query3="SELECT Event FROM Events";
			$result4 = mysql_query($query3) or die("Error executing:<br>$query3<br>" . mysql_error() );

			echo "<select name=\"Event\">";
			echo "<option></option>";
			while ($row=mysql_fetch_assoc($result4)) {
			echo "<option>".$row['Event']."</option>";
			}
			echo "</select>";
			?>
		</td>
	</tr>

            <tr><td>1</td><td><input type="text" name="1" /></td></tr>
            <tr><td>2</td><td><input type="text" name="2" /></td></tr>
            <tr><td>3</td><td><input type="text" name="3" /></td></tr>
            <tr><td>4</td><td><input type="text" name="4" /></td></tr>
            <tr><td>5</td><td><input type="text" name="5" /></td></tr>
            <tr><td>6</td><td><input type="text" name="6" /></td></tr>
            <tr><td>7</td><td><input type="text" name="7" /></td></tr>
            <tr><td>8</td><td><input type="text" name="8" /></td></tr>
            <tr><td>9</td><td><input type="text" name="9" /></td></tr>
            <tr><td>10</td><td><input type="text" name="10" /></td></tr>
            <tr><td>11</td><td><input type="text" name="11" /></td></tr>
            <tr><td>12</td><td><input type="text" name="12" /></td></tr>
            <tr><td>13</td><td><input type="text" name="13" /></td></tr>
            <tr><td>14</td><td><input type="text" name="14" /></td></tr>
            <tr><td>15</td><td><input type="text" name="15" /></td></tr>
            <tr><td>16</td><td><input type="text" name="16" /></td></tr>
            <tr><td>17</td><td><input type="text" name="17" /></td></tr>
            <tr><td>18</td><td><input type="text" name="18" /></td></tr>
            <tr><td>19</td><td><input type="text" name="19" /></td></tr>
            <tr><td>20</td><td><input type="text" name="20" /></td></tr>
            <tr><td>21</td><td><input type="text" name="21" /></td></tr>
            <tr><td>22</td><td><input type="text" name="22" /></td></tr>
            <tr><td>23</td><td><input type="text" name="23" /></td></tr>
            <tr><td>24</td><td><input type="text" name="24" /></td></tr>
            <tr><td>25</td><td><input type="text" name="25" /></td></tr>
            <tr><td>26</td><td><input type="text" name="26" /></td></tr>
            <tr><td>27</td><td><input type="text" name="27" /></td></tr>
            <tr><td>28</td><td><input type="text" name="28" /></td></tr>
            <tr><td>29</td><td><input type="text" name="29" /></td></tr>
            <tr> <td>30</td><td><input type="text" name="30" /></td></tr>
            <tr><td>DNF1</td><td><input type="text" name="DNF1" /></td></tr>
            <tr><td>DNF2</td><td><input type="text" name="DNF2" /></td></tr>
            <tr><td>DNF3</td><td><input type="text" name="DNF3" /></td></tr>
            <tr><td>DNF4</td><td><input type="text" name="DNF4" /></td></tr>
            <tr><td>DNF5</td><td><input type="text" name="DNF5" /></td></tr>
            <tr><td>DNF6</td><td><input type="text" name="DNF6" /></td></tr>
            <tr><td>DNF7</td><td><input type="text" name="DNF7" /></td></tr>
            <tr><td>DNF8</td><td><input type="text" name="DNF8" /></td></tr>
            <tr><td>DNF9</td><td><input type="text" name="DNF9" /></td></tr>
            <tr><td>DNF10</td><td><input type="text" name="DNF10" /></td></tr>
            <tr><td>DNS1</td><td><input type="text" name="DNS1" /></td></tr>
            <tr><td>DNS2</td><td><input type="text" name="DNS2" /></td></tr>
            <tr><td>DNS3</td><td><input type="text" name="DNS3" /></td></tr>
            <tr><td>DNS4</td><td><input type="text" name="DNS4" /></td></tr>
            <tr><td>DNS5</td><td><input type="text" name="DNS5" /></td></tr>
            <tr><td>NT1</td><td><input type="text" name="NT1" /></td></tr>
            <tr><td>NT2</td><td><input type="text" name="NT2" /></td></tr>
            <tr><td>NT3</td><td><input type="text" name="NT3" /></td></tr>
            <tr><td>NT4</td><td><input type="text" name="NT4" /></td></tr>
            <tr><td>NT5</td><td><input type="text" name="NT5" /></td></tr>

<tr>
<td colspan="3" align="center"><input type="submit" name="submit" value="Edit Results" /></td>
</tr>
</table>
</form>
</td>
</tr>

<tr>
<td>
<center><h2><u>Add Member to Roster</u></h2></center>
<form action="insertroster.php" method="post" enctype="multipart/form-data">

<table border="1" cellspacing="0" cellpadding="0" align="center">

     <tr><td>Car Number</td><td><input type="text" name="Car_Number" /></td></tr>
     <tr><td>Full Name</td><td><input type="text" name="Driver_Name" /></td></tr>
     <tr><td>Home Town</td><td><input type="text" name="Home_Town" /></td></tr>
     <tr><td>Cartoon Character</td><td><input type="text" name="Cartoon_Character" /></td></tr>
     <tr><td>Highlights</td><td><input type="text" name="Highlights" /></td></tr>
     <tr><td>Email</td><td><input type="text" name="Email" /></td></tr>
     <tr><td>Phone</td><td><input type="text" name="Phone" /></td></tr>
     <tr><td>Image</td><td><input type="file" name="mailfile" /></td></tr>

<tr>
<td colspan="3" align="center"><input type="submit" name="submit" value="Add Member" /></td>
</tr>
</table>
</form>
</td>
<td>
<center><h2><u>Edit Roster Member</u></h2></center>
<form action="updateroster.php" method="post" enctype="multipart/form-data">

<table border="1" cellspacing="0" cellpadding="0" align="center">

     <tr>
         <td>
            Car Number:
	</td>

	<td>
            <?php
            $query3="SELECT Car_Number FROM Roster";
            $result5 = mysql_query($query3) or die("Error executing:<br>$query4<br>" . mysql_error() );
            echo "<select name=\"Car_Number\">";
            echo "<option></option>";
            while ($row=mysql_fetch_assoc($result5)) {
            echo "<option>".$row['Car_Number']."</option>";
            }
            echo "</select>";
            ?>
	</td>
     </tr>
     <tr><td>Full Name</td><td><input type="text" name="Driver_Name" /></td></tr>
     <tr><td>Home Town</td><td><input type="text" name="Home_Town" /></td></tr>
     <tr><td>Cartoon Character</td><td><input type="text" name="Cartoon_Character" /></td></tr>
     <tr><td>Highlights</td><td><input type="text" name="Highlights" /></td></tr>
     <tr><td>Email</td><td><input type="text" name="Email" /></td></tr>
     <tr><td>Phone</td><td><input type="text" name="Phone" /></td></tr>
     <tr><td>Image</td><td><input type="file" name="mailfile" /></td></tr>

<tr>
<td colspan="3" align="center"><input type="submit" name="submit" value="Update Member" /></td>
</tr>
</table>
<tr>
<center>
<table>
<td>
<center><h2><u>Delete Roster Member</u></h2></center>
<form action="deleteroster.php" method="post"/>

<table border="1" cellspacing="0" cellpadding="0" align="center">

     <tr>
         <td>
            Car Number:
	</td>

	<td>
            <?php
            $query4="SELECT Car_Number FROM Roster";
            $result6 = mysql_query($query3) or die("Error executing:<br>$query4<br>" . mysql_error() );
            echo "<select name=\"Car_Number\">";
            echo "<option></option>";
            while ($row=mysql_fetch_assoc($result6)) {
            echo "<option>".$row['Car_Number']."</option>";
            }
            echo "</select>";
            ?>
	</td>
     </tr>

<tr>
<td colspan="3" align="center"><input type="submit" name="submit" value="Delete Member" /></td>
</tr>
</table>
</table>

<center><h2><u>Add Event</u></h2></center>
<form action="insertevent.php" method="post">

<table border="1" cellspacing="0" cellpadding="0" align="center">
     <tr>
	 <td>No Points Awarded:</td>
	 <td>Date:</td>
	 <td>Place:</td>
	 <td>Start Time:</td>
	 <td>Notes:</td>
	 <td>Special Event:</td>
	 </tr>
	 <tr>
	 <td><input type="checkbox" name="Points_Awarded" value="*"/></td>
     <td><input type="text" name="Date" /></td>
     <td><input type="text" name="Place" /></td>
     <td><input type="text" name="StartTime" /></td>
     <td><input type="text" name="Notes" /></td>
     <td><input type="text" name="Event" /></td>
	 </tr>

<tr>
<td colspan="6" align="center"><input type="submit" name="submit" value="Add Event" /></td>
</tr>
</table>
</form>
</center>
</form>
</td>
</tr>
</table>
</body>
</html>

Open in new window

0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 34880243
Try removing the quotes from around the values as they look like the columns should/would be int values NOT vchar.

Please change your php script to include mysql_real_escape_string() on ALL posted values.

$Points_Awarded = mysql_real_escape_string($_POST['Points_Awarded']);
$Date = mysql_real_escape_string($_POST['Date']);
$Place = mysql_real_escape_string($_POST['Place']);

etc....etc.... that makes if safer !
0
 

Author Comment

by:patrickm12981
ID: 34880291
i sepreated out the form from the rest to its own page called admintest.php, also here my current insertevent.php. I not sure which quotes you sre talking about.

Also the table structure.


<?php

// Inialize session
session_start();

// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['username'])) {
header('Location: index.php');
}

?>

<?php
error_reporting(E_ALL);
include("../includes/Header.html");
include("../includes/conn.php"); 
?>
<center><p><a href="logout.php">Logout</a></p></center>

<table width="930" align="center">
<tr>
<td valign="top">

<center><h2><u>Add Event</u></h2></center>
<form action="insertevent.php" method="post">

<table border="1" cellspacing="0" cellpadding="0" align="center">
     <tr>
	 <td>No Points Awarded:</td>
	 <td>Date:</td>
	 <td>Place:</td>
	 <td>Start Time:</td>
	 <td>Notes:</td>
	 <td>Special Event:</td>
	 </tr>
	 <tr>
	 <td><input type="checkbox" name="Points_Awarded" value="*"/></td>
     <td><input type="text" name="Date" /></td>
     <td><input type="text" name="Place" /></td>
     <td><input type="text" name="StartTime" /></td>
     <td><input type="text" name="Notes" /></td>
     <td><input type="text" name="Event" /></td>
	 </tr>

<tr>
<td colspan="6" align="center"><input type="submit" name="submit" value="Add Event" /></td>
</tr>
</table>
</form>
</td>
</tr>
</table>

Open in new window

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>insertevent.php</title>
</head>
<body>

<?php
<?php
mysql_connect("mysql", "xxx", "xxxx") or die ('Could not connect: ' . mysql_error());
mysql_select_db("RMDCRA");

$Points_Awarded = mysql_real_escape_string($_POST['Points_Awarded']);
$Date = mysql_real_escape_string($_POST['Date']);
$Place = mysql_real_escape_string($_POST['Place']);
$StartTime=mysql_real_escape_string($_POST['StartTime']);
$Notes=mysql_real_escape_string($_POST['Notes']);
$Event=mysql_real_escape_string($_POST['Event']);

$sql = ("INSERT INTO `RMDCRA`.`Schedule` (`Race_Number`, `Points_Awarded`, `Date`, `Place`, `StartTime`, `Notes`, `Event`)
    VALUES (NULL, '$Points_Awarded', '$Date', '$Place', '$StartTime', '$Notes', '$Event')") or die(mysql_error());
echo $sql;
echo mysql_error();

//header('Location: http://rmdcra.org/admin/Admin.php');
?> 

</body>
</html>

<!--
INSERT INTO `RMDCRA`.`Schedule` (
`Race_Number` ,
`PointsAwarded` ,
`Date` ,
`Place` ,
`StartTime` ,
`Notes` ,
`Event` 
)
VALUES (
NULL , '*', '2011-04-03', 'I-76 Speedway', NULL , NULL , 'Hot Laps'
);

-->

Open in new window

Capture.PNG
0
 

Author Comment

by:patrickm12981
ID: 34880372
When executed I get a blank page.
0
 
LVL 20

Accepted Solution

by:
Mark Brady earned 1600 total points
ID: 34880460
A blank page means the script is halting and the page will not excecute any more code so it stays blank. The first problem I see here is you are trying to insert a value into a field set as "auto increment". Even if that value is empty you need to remove it from your code. The value is `Race_Number` and NULL. Because that column is set to AI you can leave it out of your query altogether. Also, you don't need the backtics unless your column name has a space in between two words. Remove the brackets from your $sql variable so change the query from :

$sql = ("INSERT INTO `RMDCRA`.`Schedule` (`Race_Number`, `Points_Awarded`, `Date`, `Place`, `StartTime`, `Notes`, `Event`)
    VALUES (NULL, '$Points_Awarded', '$Date', '$Place', '$StartTime', '$Notes', '$Event')") or die(mysql_error());

To this:

$sql = "INSERT INTO `RMDCRA`.`Schedule` (Points_Awarded, Date, Place, StartTime, Notes, Event)
 VALUES ('$Points_Awarded', '$Date', '$Place', '$StartTime', '$Notes', '$Event')";

// Now run the query
$result = mysql_query($sql)or die(mysql_error());
if($result){
echo "The query worked!";
}else{
echo "The query failed!!!";
}
0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 34880461
Fix up those few problems then we'll take another look at it.
0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 34880463
You also have two openeing tags on the page. Remove line 11 <?php
0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 34880469
You might want to ask a moderator to remove or mask line 12 on your last post (the 2nd page you posted) as it has your login details. Best to change these credentials now cause google may already have grabbed this page :)
0
 

Author Comment

by:patrickm12981
ID: 34880510
I noticed just after I posted it. I already asked the moderator.


Her is the result that I received after making the changes......

Unknown column 'Points_Awarded' in 'field list'
0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 34880515
Sorry, I didn't picj=k that up. Change (Points_Awarded, to PointsAwarded

There is no _ underscore between the two words. The first line of your insert query (PointsAwarded, etc... must match EXACTLY to the column names in your table.
0
 

Author Comment

by:patrickm12981
ID: 34880517
NM -  fixed it.

Query worked!
0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 34880520
No problems!
0

Featured Post

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question