0

I have an issue with a form been generated with values from the DB and on submit nothing happens.

I had this working, but then it stopped... Not sure what I've done... just learning php so please help :) thanks

Here is code of entire page:

    <?php ob_start(); 

$x_station = $_REQUEST['station'];


?>
<?php include('incl/session.php3'); ?>
<?php if($session->logged_in){ } else { header("Location: index.php"); }?>
<?php include('incl/vars.php3'); ?>

<?php include('incl/header.php3'); ?>

<?php include('incl/menu.php3'); ?>

<?php
// Connect to server and select databse.

    $x_db_host1="xxxxx"; // Host name
    $x_db_username1="xxxxx"; // Mysql username
    $x_db_password1="xxxxxx"; // Mysql password
    $x_db_name1="xxxxx"; // Database name
// Connect to server and select databse.
    mysql_connect("$x_db_host1", "$x_db_username1", "$x_db_password1")or die("cannot connect to database");
    mysql_select_db("$x_db_name1") or die("cannot select DB");

$sql="SELECT * FROM delegates WHERE CheckedIn = 0 AND DStation = $x_station";
$result=mysql_query($sql) or die ('Error: '.mysql_error ());

// Count table rows
$count=mysql_num_rows($result);
?>


    <div class="content">


                <div class="in author">
                    <h2>Conference Check-in</h2>
                    <p>Please see Brad for assistance.<em></em></p>
</div>

                <div class="line"></div>


            <div class="check_main"></div>

                <div class="in forms">
                <form name="form1" method="post" action="">
<table width="600" border="0" cellspacing="1" cellpadding="0">
<tr style="background-color:#d9d8d8; font-size:14px;">
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Saturday</strong></td>
<td align="center"><strong>Dinner</strong></td>
<td align="center"><strong>Sunday</strong></td>
<td align="center"><strong>Special Req</strong></td>
<td align="center"><strong>Check In?</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? 
$DID[]=$rows['DID']; 
echo $rows['DID']; ?>
  </td> 
<td align="center"><? echo $rows['DFName']; ?> <? echo $rows['DLName']; ?></td>
<td align="center">   
<?php 

if($rows['DConfSat']==0){echo "<select name=\"Sat[]\" id=\"Sat\"><option selected=\"selected\" value=\"0\">YES</option><option value=\"1\">NO</option></select>";}
else{echo "<select name=\"Sat[]\" id=\"Sat[]\"><option selected=\"selected\" value=\"1\">NO</option><option value=\"0\">YES</option></select>";}
?>
</td>
<td align="center"> <?php 
$DiSat[]=$rows['DConfdinner'];
if($rows['DConfdinner']==0){echo "<select name=\"DiSat[]\" id=\"DiSat\"><option selected=\"selected\" value=\"0\">YES</option><option value=\"1\">NO</option></select>";}
else{echo "<select name=\"DiSat[]\" id=\"DiSat\"><option selected=\"selected\" value=\"1\">NO</option><option value=\"0\">YES</option></select>";}
?></td>
<td align="center">  <?php 
$Sun[]=$rows['DConfSun'];
if($rows['DConfSun']==0){echo "<select name=\"Sun[]\" id=\"Sun\"><option selected=\"selected\" value=\"0\">YES</option><option value=\"1\">NO</option></select>";}
else{
    echo "<select name=\"Sun[]\" id=\"Sun\"><option selected=\"selected\" value=\"1\">NO</option><option value=\"0\">YES</option></select>";}
?></td>
<td align="center"> 
<?php 
if($rows['DSpecRe']==0){echo "NO"; }
    else { echo "YES"; }
 ?> 
    </td>
<td align="center"> 
     <input name="checkin[]" type="checkbox" id="checkin" value="1" /></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>

</form>
      </div>





    <div class="in"></div>

        </div>
<?php
// BEGIN FORM PROCESSING!


// Check if button name "Submit" is active, do this


if($Submit){

for($i=0;$i<$count;$i++){
// SQl Query
$sql1="UPDATE delegates SET Dconfdinner='$DiSat[$i]', DConfSat='$Sat[$i]' DConfSun='$Sun[$i]' CheckedIn='checkin[$i]' WHERE DID='$DID[$i]'";


$result1=mysql_query($sql1)or die ('Error: '.mysql_error ());
}
}
if($result1){
header("location: checkin.php&msg=1");
}
mysql_close();
?>          
<?php include('incl/footer.php3'); ?>


<?php ob_flush(); ?>

No idea why when submitted it does not make changes.

It also does not redirect to the correct page it simply returns to the current page.

Help appreciated :)

Kyle
  • 21,978
  • 2
  • 60
  • 61
Braddles
  • 41
  • 6
  • use GET or POST instead of REQUEST... and, there isen't no $_POST['station'] or $_GET['station'] parameter, and when you do this `SELECT * FROM delegates WHERE CheckedIn = 0 AND DStation = $x_station` it stops because `$x_station` doesn't have a value... {i think} – Joseadrian Mar 10 '11 at 01:36
  • It all displays perfectly. It's the form handling that is having issues? somewhere the processing part has the issue. – Braddles Mar 10 '11 at 01:45
  • [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://stackoverflow.com/a/14110189/1723893). – NullPoiиteя Jan 08 '13 at 11:48

4 Answers4

0

change

if($Submit)

to

if(isset($_POST['submit']))

isset checks if $_POST['submit'] has a value. when you click on a button a value is creating automatically im guessing a 1. you just have it as if($submit) and that variable is not linked to anything. its best to write it as i did.

Exploit
  • 6,278
  • 19
  • 70
  • 103
0

Your form has no action attribute set. Are you using javascript to submit the form? If not, your form needs an action!

<form name="form1" method="post" action="">

Should be something like this

<form name="form1" method="post" action="your_script.php">

Kyle
  • 21,978
  • 2
  • 60
  • 61
  • the form posts to itself and form handling is set down the bottom – Braddles Mar 10 '11 at 01:41
  • I set the action to the script name and I now get the following error: Error: 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 '' at line 1 – Braddles Mar 10 '11 at 01:43
  • I would change the following line. This is just a guess. `$sql="SELECT * FROM delegates WHERE CheckedIn = 0 AND DStation = $x_station"` to `$sql="SELECT * FROM delegates WHERE CheckedIn = 0 AND DStation = '$x_station'"` - You need the single quotes around the variable. – Kyle Mar 10 '11 at 01:46
  • The issue is not at all with the displaying of data it's only with form handling updating data – Braddles Mar 10 '11 at 01:54
  • That was because when I set action to the page name it did this because the pagename.php?station=123 bit was not there. – Braddles Mar 10 '11 at 01:59
  • I thank you for your Kyle it just did not work. It's a strange issue I can't work it out. :S – Braddles Mar 10 '11 at 02:00
0
$sql = 'UPDATE delegates SET Dconfdinner = "%s", DConfSat = "%s", DConfSun = "%s", CheckedIn = "%s" WHERE  DID = "%s"'; // ,
$sql = sprintf($sq, $DiSat[$i], $Sat[$i], $Sun[$i], $checkin[$i], $DID[$i]);

Also... $Sat variable isn't exist.

Joseadrian
  • 4,234
  • 2
  • 16
  • 7
0

what you can do is edit your httpd.conf and look for ErrorLog and right next to it put the path to a tet file. every sql query that is run on any website that you are hosting will be displayed on this page. so that you can track down what mysql queries are being seen by the computer itself.

Exploit
  • 6,278
  • 19
  • 70
  • 103
  • I have no solutions so far. Does anyone know another way this can be done. – Braddles Mar 10 '11 at 02:16
  • i do see a problem in your query though. $sql1="UPDATE delegates SET Dconfdinner='$DiSat[$i]', DConfSat='$Sat[$i]' DConfSun='$Sun[$i]' CheckedIn='checkin[$i]' WHERE DID='$DID[$i]'"; (you dont have an input field for $DiSat[$i] and manny of those variables. if your trying to add the values through javascript its not gonna work. – Exploit Mar 10 '11 at 06:10