Jump to content

Having Problems posting non-numeric data


Recommended Posts

New to PHP/My SQL and trying to make an evaluation form that writes to a database.

 

Everything seems to be working fine, except for one major thing. I am only able to post numbers. Anytime that I enter text, nothing happens. I don't even get an error.

 

All of the fields in the MySQL database are set to text or varchar, and the HTML form is set to accept text. Here is the PHP if anyone sees something that stands out.

 

<?php require_once('databaseconn.php'); ?>

<?php

$_1a = $_POST['1a'];

$_1b = $_POST['1b'];

$_1c = $_POST['1c'];

$_2a = $_POST['2a'];

$_2b = $_POST['2b'];

$_2c = $_POST['2c'];

$_3a = $_POST['3a'];

$_4a = $_POST['4a'];

$_5a = $_POST['5a'];

$_6a = $_POST['6a'];

$_7a = $_POST['7a'];

$_8a = $_POST['8a'];

 

mysql_select_db('training', $databaseconn);

 

$insertSQL = sprintf"(INSERT INTO evaluation (1a, 1b, 1c, 2a, 2b, 2c, 3a, 4a, 5a, 6a, 7a, 8a) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", $_1a, $_1b, $_1c, $_2a, $_2b, $_2c, $_3a, $_4a, $_5a, $_6a, $_7a, $_8a);

 

mysql_query($insertSQL, $databaseconn) or die(mysql_error());

 

/* redirect back to registration page */

header("Location: index.php");

?>

 

 

 

 

couple things...if you aren't seeing any errors, then you need to turn on error reporting...

 

next, you need to put quotes around your values when inserting

also, you should send all your values through mysql_real_escape_string() to prevent SQL Injection:

<?php require_once('databaseconn.php'); ?>
<?php
mysql_select_db('training', $databaseconn);

$_1a = mysql_real_escape_string($_POST['1a']);
$_1b = mysql_real_escape_string($_POST['1b']);
$_1c = mysql_real_escape_string($_POST['1c']);
$_2a = mysql_real_escape_string($_POST['2a']);
$_2b = mysql_real_escape_string($_POST['2b']);
$_2c = mysql_real_escape_string($_POST['2c']);
$_3a = mysql_real_escape_string($_POST['3a']);
$_4a = mysql_real_escape_string($_POST['4a']);
$_5a = mysql_real_escape_string($_POST['5a']);
$_6a = mysql_real_escape_string($_POST['6a']);
$_7a = mysql_real_escape_string($_POST['7a']);
$_8a = mysql_real_escape_string($_POST['8a']);

$insertSQL = sprintf"(INSERT INTO evaluation (1a, 1b, 1c, 2a, 2b, 2c, 3a, 4a, 5a, 6a, 7a, 8a) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $_1a, $_1b, $_1c, $_2a, $_2b, $_2c, $_3a, $_4a, $_5a, $_6a, $_7a, $_8a);

mysql_query($insertSQL, $databaseconn) or die(mysql_error());

/* redirect back to registration page */
header("Location: index.php");
?>

probably because whitespace has already been sent...try this:

<?php
//Turn on error reporting...you should remove this once the script is working
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors',1);

//Connect to the DB
require_once('databaseconn.php');
mysql_select_db('training', $databaseconn);

$_1a = mysql_real_escape_string($_POST['1a']);
$_1b = mysql_real_escape_string($_POST['1b']);
$_1c = mysql_real_escape_string($_POST['1c']);
$_2a = mysql_real_escape_string($_POST['2a']);
$_2b = mysql_real_escape_string($_POST['2b']);
$_2c = mysql_real_escape_string($_POST['2c']);
$_3a = mysql_real_escape_string($_POST['3a']);
$_4a = mysql_real_escape_string($_POST['4a']);
$_5a = mysql_real_escape_string($_POST['5a']);
$_6a = mysql_real_escape_string($_POST['6a']);
$_7a = mysql_real_escape_string($_POST['7a']);
$_8a = mysql_real_escape_string($_POST['8a']);

$insertSQL = sprintf"(INSERT INTO evaluation (1a, 1b, 1c, 2a, 2b, 2c, 3a, 4a, 5a, 6a, 7a, 8a) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $_1a, $_1b, $_1c, $_2a, $_2b, $_2c, $_3a, $_4a, $_5a, $_6a, $_7a, $_8a);

mysql_query($insertSQL, $databaseconn) or die(mysql_error());

/* redirect back to registration page */
header("Location: index.php");
exit;
?>

I can't get your suggested code to work at all.

 

here's my updated code that works right, sans the redirect.

 

<?php require_once('databaseconn.php'); ?>
<html>
<head>
<title>Class Register</title>
<style type="text/css">
<?php
$_1a = $_POST['1a'];
$_1b = $_POST['1b'];
$_1c = $_POST['1c'];
$_2a = $_POST['2a'];
$_2b = $_POST['2b'];
$_2c = $_POST['2c'];
$_3a = $_POST['3a'];
$_4a = $_POST['4a'];
$_5a = $_POST['5a'];
$_6a = $_POST['6a'];
$_7a = $_POST['7a'];
$_8a = $_POST['8a'];

mysql_select_db('training', $databaseconn);

$insertSQL = sprintf("INSERT INTO evaluation (1a, 1b, 1c, 2a, 2b, 2c, 3a, 4a, 5a, 6a, 7a, 8a) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $_1a, $_1b, $_1c, $_2a, $_2b, $_2c, $_3a, $_4a, $_5a, $_6a, $_7a, $_8a);

mysql_query($insertSQL, $databaseconn) or die(mysql_error());

/* redirect back to registration page */
$conf = "redirect.php";
header("Location: $conf");

?>
</body>
</html>

You can't do a Location redirect have you have sent stuff to the screen. And, if you are redirecting, there shouldn't be any HTML on the page anyways.

 

and you didn't add the error reporting, which will tell you EXACTLY what the problem is:

 

<?php
//Turn on error reporting...you should remove this once the script is working
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors',1);

require_once('databaseconn.php');

$_1a = $_POST['1a'];
$_1b = $_POST['1b'];
$_1c = $_POST['1c'];
$_2a = $_POST['2a'];
$_2b = $_POST['2b'];
$_2c = $_POST['2c'];
$_3a = $_POST['3a'];
$_4a = $_POST['4a'];
$_5a = $_POST['5a'];
$_6a = $_POST['6a'];
$_7a = $_POST['7a'];
$_8a = $_POST['8a'];

mysql_select_db('training', $databaseconn);

$insertSQL = sprintf("INSERT INTO evaluation (1a, 1b, 1c, 2a, 2b, 2c, 3a, 4a, 5a, 6a, 7a, 8a) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $_1a, $_1b, $_1c, $_2a, $_2b, $_2c, $_3a, $_4a, $_5a, $_6a, $_7a, $_8a);

mysql_query($insertSQL, $databaseconn) or die(mysql_error());

/* redirect back to registration page */
$conf = "redirect.php";
header("Location: $conf");

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.