Trouble with PHP script works in IE but not safari or firefox

buddaman

New Member
Messages
4
Reaction score
0
Points
0
Hello everyone, hope everybody is doing well and if anyone can help me with the script i would be very grateful. This is project i've been set for University and its a simple form for students to fill out and the information goes into a database and a tutor can access the database and retrieve any information passed to it. So reasonably simple but for some reason i when i hit submit on Safari and firefox the information inputed into the form is not reflected back to the user but it is in Internet Explorer. Is there anything wrong with my script or is it a browser setting. I'm just very confused as it seems to work fine for one browser but not for another. The script is below(included HTML as did'nt know if that has anything to do with it) any ideas or solutions are greatly received.


<head>
<title>feedbackconfirmation</title>
<meta name="generator" content="BBEdit 9.3" />
</head>
<body>
<h1>Feedback Confirmation</h1>

<p>Thank you for taking the time to fill in the form. The information below will be
passed to the tutors.</p>
<div class="articles">
<?php

$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$dob = $_POST["dob"];
$comments = $_POST["comments"];
$module = $_POST["module"];
$session = $_POST["session"];

// Print the content of the PHP variables back to the user

print "<br /><br />First name is>><strong><b> $firstname</b></strong>\n";
print "<br />Last name is>><strong><b> $lastname</b></strong>\n";
print "<br />Date of birth is>><strong><b> $dob</b></strong>\n";
print "<br />Your comments are>><strong><b> $comments</b></strong>\n";
print "<br />Your module is>><strong><b> $module</b></strong>\n";
print "<br />You selected>><strong><b> $session</b></strong>\n";
print "<br /><br />";


$dbserverIP="localhost";
$dbusername="buddaman_woody";
$dbuserpassword="PASSWORD";
$connection=mysql_connect($dbserverIP,$dbusername,$dbuserpassword)or die("Couldn't connect to the dbserver.");

$dbname="buddaman_classlist";
$dbselectok=mysql_select_db($dbname,$connection) or die("Couldn't select the remote database.");

$sqlstatement="INSERT INTO classlist VALUES ('$firstname','$lastname','$dob','$comments','$module','$session')";
$sql_result=mysql_query($sqlstatement,$connection)or die("Couldn't execute the SQL SELECT statement 1");

$sqlstatement = "SELECT * FROM classlist";
$sql_result = mysql_query($sqlstatement,$connection) or die("Couldn't execute the SQL SELECT statement 2");




?></div>

<p> Thank you </p>

<a href="FirstPage1.htm">Back to Homepage</a>


Thank you all for any suggestions in advance.
 

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
Are the values actually inserted into the database?
The browser really will not make a difference to the execution of PHP code, as PHP is a server side language. What is the URL of the page?
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Post the html for the input form.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
  • When posting code, use
    Code:
    , [html] or [php] (as appropriate) to separate the code from the rest of the post and format it.
    [*]Include a link to a live page. This is essential for this particular problem.
    [*]Never directly [URL="http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing"]interpolate[/URL] variables from user input into a query string; it leaves you open to [url=http://unixwiz.net/techtips/sql-injection.html]SQL injection[/url]. Instead, use a newer driver that supports [URL="http://www.php.net/pdo.prepared-statements"]prepared statements[/URL], such as [URL="http://www.kitebird.com/articles/php-pdo.html"]PDO[/URL]. Prepared statement parameters are invulnerable to SQL injection.
    [*]Don't use [URL="http://www.phpfreaks.com/blog/or-die-must-die"][FONT="Courier New"]or die[/FONT][/URL]
    [*]HTML defines the structure of a document. <br/> isn't structural, so should be avoided. Better would be to use a list in this case, such as <ul>. The best list to use here is <dl>, the definition list.
    [*]Read the sig and follow all instructions that apply.
    [/list]
 
Last edited:

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
These are probably your problem:
print "<br /><br />First name is>><strong><b> $firstname</b></strong>\n";
Replace every occurrence of >> with &gt;&gt; like so:
print "<br /><br />First name is&gt;&gt;<strong><b> $firstname</b></strong>\n";
You also do not appear to have fully compliant HTML, you need <html> tags and proper closing of all opened tags.
All that together makes this:
HTML:
<html>
<head>
<title>feedbackconfirmation</title>
<meta name="generator" content="BBEdit 9.3" />
</head>
<body>
<h1>Feedback Confirmation</h1>

<p>Thank you for taking the time to fill in the form. The information below will be
passed to the tutors.</p>
<div class="articles">
<?php

$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$dob = $_POST["dob"];
$comments = $_POST["comments"];
$module = $_POST["module"];
$session = $_POST["session"];

// Print the content of the PHP variables back to the user

print "<br /><br />First name is&gt;&gt;<strong><b> $firstname</b></strong>\n";
print "<br />Last name is&gt;&gt;<strong><b> $lastname</b></strong>\n";
print "<br />Date of birth is&gt;&gt;<strong><b> $dob</b></strong>\n";
print	 "<br />Your comments are&gt;&gt;<strong><b> $comments</b></strong>\n";
print "<br />Your module is&gt;&gt;<strong><b> $module</b></strong>\n";
print "<br />You selected&gt;&gt;<strong><b> $session</b></strong>\n";
print "<br /><br />";


$dbserverIP="localhost";
$dbusername="buddaman_woody";
$dbuserpassword="PASSWORD";
$connection=mysql_connect($dbserverIP,$dbusername, $dbuserpassword)or die("Couldn't connect to the dbserver.");

$dbname="buddaman_classlist";
$dbselectok=mysql_select_db($dbname,$connection) or die("Couldn't select the remote database.");

$sqlstatement="INSERT INTO classlist VALUES ('$firstname','$lastname','$dob','$comments','$mod ule','$session')";
$sql_result=mysql_query($sqlstatement,$connection) or die("Couldn't execute the SQL SELECT statement 1");

$sqlstatement = "SELECT * FROM classlist";
$sql_result = mysql_query($sqlstatement,$connection) or die("Couldn't execute the SQL SELECT statement 2");




?></div>

<p> Thank you </p>

<a href="FirstPage1.htm">Back to Homepage</a>
</body>
<html>
 
Last edited:

buddaman

New Member
Messages
4
Reaction score
0
Points
0
In answer to a few questions yes the values are inserted into the database and the url is
http://iainwood.x10hosting.com and you would need to click on Firstpage1.htm and then just click on Students click here. The site is not finished and is very messy but i am focusing on getting the php script to work and then i can add a CSS file and tidy it all up. I am still new to php and programming in general so i really thank you for all the help. Below is the html script for the form.

</head>
<h1>Feedback for Students.</h1>

<body>
<p>Please fill out the form below and click sumit when finished.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Please pick from the following<p>
<div class="articles">
<form name="info" action="script1.php" method="post" onsubmit="return validate_form();" >
Module:
<select name="module">
<option value>Choose module</option>
<option value>MWD1001</option>
<option value>MWD1002</option>
<option value>MWD1014</option>
<option value>MWD1003</option>
<option value>MWD1004</option>
<option value>MWD1000</option>
</select>
</br>
Session:
<select name="session">
<option value>Choose session</option>
<option vlaue>Session 1</option>
<option value>Session 2</option>
<option value>Session 3</option>
<option value>Session 4</option>
<option value>Session 5</option>
<option value>Session 6</option>
</select>
</br>
First Name:
<input type="text" name="firstname" size="12" mazlength="20"/>
</br>
Last Name:
<input type="text" name="lastname"size="12" mazlength="20"/>
</br>
Date of birth:
<input type="text" name="date of birth"size="12" mazlength="20"/>
</br>
Comments:
<textarea name="comments" Cols=40 rows=10/></textarea>
</br>

<input type="reset" type="button" value="clear form">
</br>
<a href="script1.php"><input type="submit" type="button" value"submit information"></a>
</form></div>

</br>
</br>
</br>
<a href="FirstPage1.htm">Back to Homepage</a>
</body>
 

bahawkid

New Member
Messages
3
Reaction score
0
Points
0
just remove the link on this line:
<a href="script1.php"><input type="submit" type="button" value"submit information"></a>

it should be:
<input type="submit" type="button" value"submit information">

then your all fine :D
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
  • Give the URL for a page (e.g. http://iainwood.x10hosting.com/SecondPage.htm) or link to the page rather than instructions on how to get there. It shouldn't be a treasure hunt.
  • Don't forget those
    Code:
    , [php] and [html] tags when posting:
    [PHP]<?php
    include_once('LocalDB.php');
    
    $fields = array(
      'firstname' => 'First Name', 'lastname' => 'Last Name', 
      'dob' => 'Date of Birth', 'comments' => 'Comments', 
      'module' => 'Module', 'session' => 'Session'
    );
    
    ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
      <head>
        <title>Feedback Confirmation</title>
      </head>
      <body>
        <dl>
          <?php foreach ($fields as $name => $label) {
            $args[":$name"] = $_POST[$name];
            ?>
            <dt><?php echo $name; ?></dt><dd><?php echo $_POST[$name]; ?></dd>
          <?php } ?>
        </dl>
        <div id="Results"><?php
          try {
              $db = LocalDB::connect('buddaman_classlist');
              $insertComment = $db->prepare("INSERT INTO 
                         classlist (`firstName`, `lastName`, `dob`, `comment`, `module`, `session`) 
                         VALUES (:first,:last,:dob,:comment,:module,:session)");
              if (! $insertComment->execute($args)) {
                  $err = $insertComment->errorInfo();
                  $exc = PDOException($err[2], $err[0]);
                  $exc->errorInfo = $err;
                  throw $exc;
              }
              echo "Your comment has been recorded. Thanks for your input.";
              ...
          } catch (PDOException $exc) {
            error_log($exc);
            echo "I couldn't record your comment now. The error has been logged, and we'll look into it. Please try again later.";
          }
        ?></div>
      </body>
    </html>
    [/PHP]
    For example (and incomplete) implementations of [FONT="Courier New"]LocalDB[/FONT], see "[URL="http://x10hosting.com/forums/programming-help/117523-display-all-would-secret-while-mysql-broken.html#post665590"]Display all that would be secret while Mysql is broken[/URL]" and "[URL="http://x10hosting.com/forums/tutorials/12014-php-mysql-php-4.html#post613750"]MySQL and PHP[/URL]"
    [/list]
 
Last edited:
Top