jamesnhughes Posted April 20, 2013 Share Posted April 20, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/277165-php-sending-data-incorrectly-to-mysql-database/ Share on other sites More sharing options...
cyberRobot Posted April 29, 2013 Share Posted April 29, 2013 I'm not entirely sure I follow. Does the form collect both the first and last name at the same time? If so, you should be able to modify the query to something like: mysqli_query($con,"INSERT INTO SmallBook (FirstName, LastName) VALUES ('$FirstName', '$LastName')"); Quote Link to comment https://forums.phpfreaks.com/topic/277165-php-sending-data-incorrectly-to-mysql-database/#findComment-1427116 Share on other sites More sharing options...
InoBB Posted May 1, 2013 Share Posted May 1, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/277165-php-sending-data-incorrectly-to-mysql-database/#findComment-1427407 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.