dtferguson Posted January 4, 2014 Share Posted January 4, 2014 Hi I am fairly new to using PHP and am struggling connecting the MYSQL database to PHP. It will work but when i enter dummy data into the form it won't update within the database. I have already got someone to look over the PHP and they have just given me hints and tips of which I have followed to improve the PHP. I just want to be able that when I type in a users data it displays within the MySQL database. If someone could help me ASAP that would be great. Thanks dtferguson Registration.zip Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted January 4, 2014 Share Posted January 4, 2014 sorry to be blunt, but the code you have posted looks like it was just copy/pasted together from three or more different sources, without any planned goal or purpose. some if it is not even valid php code, nor is the statement referencing the .mwb file how you access a database. there's even a link in the form that indicates you are running this directly from your desktop and not through a server (php is a server-side scripting language and requires a web server. you can install all-in-one wamp package on your computer to allow you develop php code locally.) so, you need to slow down and go back and learn the basics, both for what you are tying to do, develop a web page (i.e. how a web server and a browser work) and to learn enough php so that you can write valid php code. then you can read through tutorials (or even just the examples in the php.net documentation) showing how you make a database connection and form and run a sql query statement. then you need to read through some tutorials that show php form processing so that you can get the data from your form into your sql query statement. Quote Link to comment Share on other sites More sharing options...
dtferguson Posted January 4, 2014 Author Share Posted January 4, 2014 sorry to be blunt, but the code you have posted looks like it was just copy/pasted together from three or more different sources, without any planned goal or purpose. some if it is not even valid php code, nor is the statement referencing the .mwb file how you access a database. there's even a link in the form that indicates you are running this directly from your desktop and not through a server (php is a server-side scripting language and requires a web server. you can install all-in-one wamp package on your computer to allow you develop php code locally.) if you are going to be blunt at least be observant you will notice that there is a HTML file connected to a PHP file. This is connected by a action= I have ran the php file along with a HTML file of which i have a link for a desktip. Yes I am already and am already using the software Xampp for the setup and implementation of mysql database. This automatically saves the database as a mwb format. Anything else you need to state or be blunt about?? Quote Link to comment Share on other sites More sharing options...
jcbones Posted January 5, 2014 Share Posted January 5, 2014 I'll be blunt also. So, I commented your file. <?php $conn = mysqli_connect($host, $user, $password, $database); //Make connection, un-declared variables used $host,$user,$password,$database. $host; is; 'localhost'; //un-defined constant, assumed string, un-expected string, $user and $password; ""; //un-expected string. $database; 'USERS' //un-expected string. //This whole block is NOT PHP, but is consistant with the andriod API (Which is based on JAVA) Table USERS` . `USERS` // CREATE TABLE IF NOT EXISTS public void createTable(){ try { mydb = openOrCreateDatabase(DBNAME, Context . MODE_PRIVATE, null); mydb . execSQL("CREATE TABLE IF NOT EXISTS " + TABLE + " (ID INTEGER PRIMARY KEY, NAME TEXT, PLACE TEXT);"); mydb . close(); } catch (Exception e) { Toast . makeText(getApplicationContext(), "Errore durante la creazione della tabella", Toast . LENGTH_LONG); } //End of ANDRIOD API ?> <?php $con=mysqli_connect(USERS.mwb); //calling a connect function AGAIN, but this time without the required arguments. //Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="INSERT INTO USERS (FirstName, Address, EmailAddress,TelephoneNumber, Password) VALUES ('$_POST[firstname]','$_POST[Address]','$_POST[EmailAddress]' , '$_POST[TelephoneNumber , '$_POST[Password]']')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "1 record added"; mysqli_close($con); if (isset($_POST['submit'])); { //did not close the bracket, will result in an "un-expected end$" error. ?> PS. you cannot "save" a MySQL database in PHP, either it exists, or it doesn't. Quote Link to comment 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.