3

Unable to store value in database

 3 years ago
source link: https://www.codesd.com/item/unable-to-store-value-in-database.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Unable to store value in database

advertisements

when i submit the form.. the form display the 'error' msg that mean the query does'nt work.. i've compare the code with the other code and it seem similar... i dont know what to do with this.. please guys... help me...

(here's is the form code)

<?php
if(isset($_GET['bookno']))
        $bookingno = $_GET['bookno'];
    elseif(isset($_POST['bookno']))
        $bookingno = $_POST['bookno'];
    else
        $bookingno = "";

    $db = mysql_connect('localhost','root')
    or die ("unable to connect");
    mysql_select_db('fyp',$db) or die ("able to select");

$sql_select = "SELECT * FROM `booking` "
                    . " WHERE `bookingno`='".trim($bookingno)."'";

     $result = mysql_query($sql_select) or die ("Query failed!");
     $row = mysql_fetch_array($result);
     extract($row);

 ?>
    <form method ="post" action="appbooking.php">
<font face= "arial" size="2" font color="black">
<center>
<table width="800" height="150" border="0" cellspacing="0" cellpadding="2">
  <tr>
  <tr>
    <td height="28" colspan="8" valign="middle" bgcolor="#0A25E9"><center>
      <font color="white" size="3" face="Times New Roman" font="font"><b>BOOKING DETAIL</b></font>
    </center>
    </tr>
  <tr>
    <td width="129" align="left" ><font face="Arial" size="2" font color="#000000">Booking No</font></td>
    <td width="291"><input name="bookingno" type="text" value= "<?php echo $row['bookingno']; ?>" size="30" ></td>
    <td width="94" align="left" ><font face="Arial" size="2" font color="#000000">User ID</font></td>
    <td width="270"><input name="username" type="text" id="username" value= "<?php echo $row['username']; ?>" size="30" ></td>
  </tr>
  <tr>
    <td width="129" align="left"><font face="Arial" size="2" font color="#000000"> Name</font></td>
    <td width="291"><input name="name" type="text" id="name" value= "<?php echo $row['name']; ?>"size="45" ></td>
    <td width="94" align="left"><font face="Arial" size="2" font color="#000000">Department</font></td>
    <td><input name="department" type="text" id="department" value= "<?php echo $row['department']; ?>" size="45" >
    </tr>
  <tr>
    <td width="129" align="left" ><font face="Arial" size="2" font color="#000000">Required Date</font></td>
    <td width="291"><input name="u_g_date" type="text" id="g_date" value= "<?php echo $row['g_date']; ?>" size="30" ></td>
    <td width="94" align="left" ><font face="Arial" size="2" font color="#000000">Required Time</font></td>
    <td><input name="g_time" type="text" id="g_time" value= "<?php echo $row['g_time']; ?>" size="30" ></td>
  </tr>
  <tr>
    <td width="129" align="left" ><font face="Arial" size="2" font color="#000000">Return Date</font></td>
    <td width="291"><input name="u_r_date" type="text" id="r_date" value= "<?php echo $row['r_date']; ?>" size="30" ></td>
    <td width="94" align="left" ><font face="Arial" size="2" font color="#000000">Return Time</font></td>
    <td><input name="r_time" type="text" id="r_time" value= "<?php echo $row['r_time']; ?>" size="30" ></td>
  </tr>
  <tr>
    <td width="129" align="left"><font face="Arial" size="2" font color="#000000">Destination</font></td>
    <td width="291"><input name="u_destination" type="text" id="destination" value= "<?php echo $row['destination']; ?>" size="45" ></td>
    <td width="94" align="left"><font face="Arial" size="2" font color="#000000">Num Of Passengger</font></td>
    <td><input name="pass_num" type="text" id="pass_num" value= "<?php echo $row['pass_num']; ?>" ></td>
  </tr>
  <tr>
    <td width="129" align="left"><font face="Arial" size="2" font color="#000000">Purpose Of Trip</font></td>
    <td width="291"><textarea name="trip_purpose" rows="3" cols="40 " >
           <?php echo $row['trip_purpose']; ?>
           </textarea></td>
  </tr>
  <p> </p>
  <td><p> </p>
  <tr>
   <tr>
        <td height="28" colspan="8" valign="middle" bgcolor="#0A25E9">
                                                                                      

        <font color="white" size="3" face="Times New Roman"     font="font"><b>APPROVE</b></font>
                                                                                                                                

        <font color="white" size="3" face="Times New Roman"     font="font"><b>REJECT</b></font>
</td>

  </tr>
  <p> </p>
  <?php
     $db = mysql_connect('localhost','root')
     or die ("unable to connect");
    mysql_select_db('fyp',$db) or die ("able to select");

    $sql="SELECT * FROM vehicle WHERE v_status='READY'";

     $result = mysql_query($sql) or die ("Query failed!");
 ?>
  <tr>
  <tr>
    <td>Registration Number
    <td><select name="regno">
            <option value="" selected>--Registration No--</option>
            <?php while($row = mysql_fetch_array($result)){?>
            <option value="<?php echo $row['regno']; ?>"><?php echo $row['regno']; ?></option>
            <?php } ?>
        </select></td>
    <td>Reason</td>
  <td><textarea name="reason" rows="3" cols="50 "value = ""></textarea></td>
  </tr>
  <?php
     $db = mysql_connect('localhost','root')
     or die ("unable to connect");
    mysql_select_db('fyp',$db) or die ("able to select");

    $sql="SELECT * FROM driver WHERE d_status='READY'";

     $result = mysql_query($sql) or die ("Query failed!");
 ?>
  <tr>
    <td>Driver</td>
    <td><select id = "d_name" name="u_d_name">
      <option value="" selected>--Driver Name--</option>
      <?php while($row = mysql_fetch_array($result)){?>
      <option value="<?php echo $row['d_name']; ?>"><?php echo $row['d_name']; ?></option>
      <?php } ?>
    </select></td>
  </tr>
  <tr>
<?php
      mysql_close($db);
?>

</table>

(here's the code for the addprocessor)
<?php
   $db = mysql_connect('localhost','root')
     or die ("unable to connect");
     mysql_select_db('fyp',$db)
     or die ("able to select");

    $bookingno=$_POST['bookingno'];
    $username=$_POST['username'];
    $name=$_POST['name'];
    $department=$_POST['department'];
    $g_date=$_POST['g_date'];
    $r_date=$_POST['r_date'];
    $r_time=$_POST['r_time'];
    $destination=$_POST['destination'];
    $pass_num=$_POST['pass_num'];
    $trip_purpose=$_POST['trip_purpose'];
    $regno=$_POST['regno'];
    $d_name=$_POST['d_name'];
    $reason=$_POST['reason'];

$sql = "INSERT INTO usage VALUES('$bookingno','$username','$name','$department', '$g_date', '$g_time', '$r_date', '$r_time', '$destination', '$pass_num', '$trip_purpose', '$regno', '$d_name', '$reason')";

$result = mysql_query($sql) or die ("error!");
//$result = mysql_query($sql) or die ($query);

echo "<font face = arial size= 3><b>Booking No : </b>".$bookingno."</font>"."<br>";
echo "<font face = arial size= 3><b>Applicant's ID : </b>".$username."</font>"."<br>";
echo "<font face = arial size= 3><b>Applicant's Name : </b>".$name."</font>"."<br>";
echo "<font face = arial size= 3><b>Department : </b>".$department."</font>"."<br>";
echo "<font face = arial size= 3><b>Required Date : </b>".$g_date."</font>"."<br>";
echo "<font face = arial size= 3><b>Required Time: </b>".$g_time."</font>"."<br>";
echo "<font face = arial size= 3><b>Return Date : </b>".$r_date."</font>"."<br>";
echo "<font face = arial size= 3><b>Return Time : </b>".$r_time."</font>"."<br>";
echo "<font face = arial size= 3><b>Destinantion : </b>".$destination."</font>"."<br>";
echo "<font face = arial size= 3><b>Number Of Passenger : </b>".$pass_num."</font>"."<br>";
echo "<font face = arial size= 3><b>Trip Purpose : </b>".$trip_purpose."</font>"."<br>";
echo "<font face = arial size= 3><b>Registration Number : </b>".$regno."</font>"."<br>";
echo "<font face = arial size= 3><b>Driver Name : </b>".$d_name."</font>"."<br>";
echo "<font face = arial size= 3><b>Reject Reason : </b>".$reason."</font>"."<br>";

mysql_close($db);

echo "<font face = arial size= 4>You have sucessfully record booking details to the database.</font>";  

?>


$bookingno=mysql_real_escape_string($_POST['bookingno']);

and so on

Note that

$result = mysql_query($sql) or trigger_error (mysql_error().' in '.$sql);

call would be much more informative in case of error


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK