Skip to main content
robertp95498449
Participant
June 1, 2016
Question

Incorrect table name "

  • June 1, 2016
  • 1 reply
  • 681 views

Hello

I made a form, a register form, but that form does not work properly. You see, when i try to submit the data, i get a Incorrect table name " error and i cant seem to find what´s causing it. Here´s the insert record part :

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;   

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}

// *** Redirect if username exists

$MM_flag="MM_insert";

if (isset($_POST[$MM_flag])) {

  $MM_dupKeyRedirect="register.php";

  $loginUsername = $_POST['username'];

  $LoginRS__query = sprintf("SELECT username FROM `user` WHERE username=%s", GetSQLValueString($loginUsername, "text"));

  mysql_select_db($database_localhost, $localhost);

  $LoginRS=mysql_query($LoginRS__query, $localhost) or die(mysql_error());

  $loginFoundUser = mysql_num_rows($LoginRS);

  //if there is a row in the database, the username was found - can not add the requested username

  if($loginFoundUser){

    $MM_qsChar = "?";

    //append the username to the redirect page

    if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";

    $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;

    header ("Location: $MM_dupKeyRedirect");

    exit;

  }

}

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "register")) {

  $insertSQL = sprintf("INSERT INTO ``user`` (fname, lname, email, username, password) VALUES (%s, %s, %s, %s, %s)",

                       GetSQLValueString($_POST['fname'], "text"),

                       GetSQLValueString($_POST['lname'], "text"),

                       GetSQLValueString($_POST['email'], "text"),

                       GetSQLValueString($_POST['username'], "text"),

                       GetSQLValueString($_POST['password'], "text"));

  mysql_select_db($database_localhost, $localhost);

  $Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error());

  $insertGoTo = "login.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

    $insertGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $insertGoTo));

}

mysql_select_db($database_localhost, $localhost);

$query_register = "SELECT * FROM `user`";

$register = mysql_query($query_register, $localhost) or die(mysql_error());

$row_register = mysql_fetch_assoc($register);

$totalRows_register = mysql_num_rows($register);

?>

And here are my db fields : `user`(`userid`, `fname`, `lname`, `email`, `username`, `password`, `timestamp`, `userlevel`)

Thank you

This topic has been closed for replies.

1 reply

David_Powers
Inspiring
July 12, 2016

I don't know how this has happened, but the problem lies with an extra pair of backticks around the table name in the following line:

$insertSQL = sprintf("INSERT INTO ``user`` (fname, lname, email, username, password) VALUES (%s, %s, %s, %s, %s)",

I haven't used Dreamweaver's server behaviors for a very long time, but I'm fairly sure that the server behavior should insert backticks around each column name. So the line would look like this (notice only a single pair of backticks around user):

$insertSQL = sprintf("INSERT INTO `user` (`fname`, `lname`, `email`, `username`, `password`) VALUES (%s, %s, %s, %s, %s)",

You should be aware that Dreamweaver CC removed the server behaviors a couple of years ago because they use code that's no longer supported by PHP 7.