允许用户将数据添加到他的sql表行并对其进行编辑

时间:2016-04-17 14:26:03

标签: javascript php

我有一个注册表单,其中包含用户名,电子邮件和密码。登录后,可以选择编辑/添加有关您自己的更多信息。这就是我遇到困难的地方,我似乎无法在没有SQL错误的情况下向同一个表“用户”添加额外的数据。我用来添加信息PHP和表单的代码......

<?php 
$error = $fname = $lname = $phone = $location = "";

  if (isset($_POST['fname']))
  {
    $fname = sanitizeString($_POST['fname']);
    $lname = sanitizeString($_POST['lname']);
    $phone = sanitizeString($_POST['phone']);
    $location = sanitizeString($_POST['location']);

    if ($fname == "" || $lname == "" || $phone == "" || $location == "")
      $error = "Enter all fields";
     //put if else statements here
    else if (preg_match("/[^a-zA-Z_-]/", $fname))
      $error='Remove spaces,numbers,special characters';
    else if (preg_match("/[^a-zA-Z_-]/", $lname))
      $error='Remove spaces,numbers,special characters';
    else if (preg_match("/[^+0-9]/", $phone))
      $error='Remove spaces,letters,special characters';
    else if (preg_match("/[^a-zA-Z_-]/", $location))
      $error='Remove spaces,numbers,special characters';
    }
    else
    {
      queryMysql("UPDATE users SET fname = '$fname', lname = '$lname', phone = '$phone', location = '$location' WHERE user = 'sheter'");
      
    }
?>

<form action="<?php echo htmlspecialchars($_SERVER[" PHP_SELF "]);?>" method="post" id="show_signup" class="login">
  <div class="headin">
    <h3>Add Your Details in the Form</h3>
  </div>
  <span id="info"><h3> </h3></span>
  <input type="text" maxlength='16' name='fname' onBlur='checkFname(this)' placeholder="First Name" pattern=".{3,}" required spellcheck="false" autocomplete="off" />
  <i class="fa fa-user"></i>

  <span id="info2"><h3> </h3></span>
  <input type="text" maxlength='16' name='lname' onBlur='checkLname(this)' placeholder="Last Name" pattern=".{3,}" required spellcheck="false" autocomplete="off" />
  <i class="fa fa-user"></i>

  <span id="info3"><h3> </h3></span>
  <input type="text" maxlength='16' name='phone' onBlur='checkPhone(this)' placeholder="Phone" pattern=".{3,}" required spellcheck="false" autocomplete="off" />
  <i class="fa fa-user"></i>

  <span id="info4"><h3> </h3></span>
  <input type="text" maxlength='16' name='location' onBlur='checkLocation(this)' placeholder="Location" pattern=".{3,}" required spellcheck="false" autocomplete="off" />
  <i class="fa fa-user"></i>

  <span class="errormsg"><h3><?php echo $error;?></h3></span>
  <div class="reset"><a href="javascript:clearFormS()">Reset</a>
  </div>
  <button type='submit' value='Submit'>
    <i class="spinner"></i>
    <span class="state">Submit</span>
  </button>
</form>

signup.php将查询作为下面的代码,空白''用于user_id设置为自动递增

queryMysql("INSERT INTO users VALUES('', '$user', '$email', '$pass')"); header("Location:../../index.html");

在所有页面上导入的标题是

<?php
session_start();

require_once 'functions.php';

$userstr = ' (Guest)';

if (isset($_SESSION['user']))
{
  $user     = $_SESSION['user'];
  $loggedin = TRUE;
  $userstr  = " ($user)";
}
else $loggedin = FALSE;

?>

谢谢!

0 个答案:

没有答案