Jump to content

PHP Sending data incorrectly to MYSQL database.


jamesnhughes

Recommended Posts

Hi all,
I am new here and was looking for some help.I am new to programming java and php using app inventor and have no experience with MYSQL although i have been educated on theory and concepts.
 
Problem: User fills out for on appinventor app form and clicks submit button. This app talks with my php script below (Dont know how i did it but coudnt get anyones elses to work so i wrote my own from PHP scratch) and input the userdata one PHPscript or "form field" at a time causing the database to look like this.
 
Firstname Lastname
___________________RID___
John        NULL             1
NULL        Smith            2
 
What i need it to do is dump all the form data at once or keep the session with the same unique ID or RID?(Not sure if i know what im talking about here).
 
This is the script that takes the info from my appinventor userinput and plants it in mySQL data base under the appropriate field. problem is when second script is ran(idont know php very well) it puts the lastname in the database but it doesnt put it at the same key or unique id as the first name?
---------------------------------------------------------------------------------------------------------------------------------------------------------
<?php
$FirstName = $_GET['FirstName'];
$con=mysqli_connect("XXXXXXXXXX","XXXXXXXX","XXXXXXXX","XXXXXXX");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
 
mysqli_query($con,"INSERT INTO SmallBook (FirstName)
VALUES ('$FirstName')");
mysqli_close($con);
?>

 

___________________________________________________________

second script

-----------------------------------------------------------------------------------------------

 

<?php
$LastName = $_GET['LastName'];
$con=mysqli_connect("XXXXXXXXXX","XXXXXXXX","XXXXXXXX","XXXXXXX");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
 
mysqli_query($con,"INSERT INTO SmallBook (LastName)
VALUES ('$LastName')");
mysqli_close($con);
?>
 

Thanks in advance,

~James

 

 

PS: not sure if it helps but my scripts are save as .php5 

post-147708-0-10241000-1366430902_thumb.png

post-147708-0-36021300-1366431413_thumb.jpg

Link to comment
Share on other sites

  • 2 weeks later...

A little unclear but if your wanting the names to go into the database as a single entry "John Smith" and be listed in database as:

 

______________RID_

John       Smith       1

 

Then a single query should do the job:

$dbhost = "host_name";
$dbuser = "sql_username";
$dbpass = "sql_password";
$DB = "table_name";

$con = new MySQLi($dbhost, $dbuser, $dbpass, $db);

if (!con) {
    echo "Database connection failed.";
}

$sql = "INSERT INTO SmallBook (FirstName, LastName) VALUES (?, ?)";
$query = $con->prepare($sql);
$query->bind_param('ss', $FirstName, $LastName);
$query->execute();
$query->close();

The fact that your scripts are saved as .php5 dosn't hurt anything unless your server is not configured to handle .php5 as a file extension.

Link to comment
Share on other sites

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.