Govind Rai
Govind Rai

Reputation: 15820

Entries not appearing in phpMyAdmin

I have been trying different variations of this code for hours. I am a newbie. I cannot seem to figure out why nothing is getting inserted into the phpMyAdmin database. I have verified that I am connected to the database (using echo and error function below). I know mysql_ is in the process of being deprecated but please help a brotha out. My question again: Why is nothing getting inserted? I'm using PHP 4.0.10.7 (Godaddy).

<?php

$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$password = $_POST['password'];
$phone_number = $_POST['phone_number'];


define('dbusername', 'someusername');
define('dbpassword', 'somepassword');
define('dbhost', 'localhost');
define('dbname', 'somedb');

if (($first_name=="")||($last_name=="")||($email=="")||($password=="")||($phone_number=="")) 
        { 
        echo "All fields are required, please fill <a href='home.html'>the form</a> again."; 
        die();
        } 

$connect = mysql_connect(dbhost,dbusername,dbpassword) or die("Could not connect. " . mysql_error());

$db = mysql_select_db(dbname, $connect);

$queryemail = "SELECT * FROM User WHERE email = '$email'";

$insertemail = "INSERT INTO User (email,password,first_name,last_name,phone_number) VALUES ('$email','$password','$first_name','$last_name','$phone_number')"; 

echo $insertemail;
mysql_close($connect);

header("Location: account_summary.html");

?>

Echoing $insertemail returns

INSERT INTO User (email,password,first_name,last_name,phone_number) VALUES ('asdfsda@sdfa','','sadf','asdf',''). The password doesn't show up, but neither does the phone number. Actual Form I'm testing on is located at Desotocab.com. Thank you!

As requested:

<form action="login.php" method="post">
		
		<label>First Name: *</label><input type="text" name="first_name"/><br/>
		<label>Last Name: *</label><input type="text" name="last_name"/><br/>
		<label>Email: *</label><input type="email" name="email"/><br/>
		<label>Password: *</label><input type="password" name="password"/><br/>
		<sub>Password must be 8 characters minimum</sub><br/>
		<label>Phone Number: *</label><input type="text" name="phone_number"/><br/>

		<input type="submit" value="Sign Up"/>

</form>

User Table Schema:

Column | Type
user_id | int(11)
email | varchar(22)
password | varchar(64)
created_on | timestamp
first_name | varchar(50)
last_name | varchar(50)
phone_number | varchar(20)

Upvotes: 0

Views: 2066

Answers (1)

Bhanu Satapati
Bhanu Satapati

Reputation: 28

Change above code from MySQL compatible to MySQLi compatible

then Use

$result = mysqli_query($connect, $insertemail);

before

echo $insertemail; 

Upvotes: 1

Related Questions