1 Replies - 313 Views - Last Post: 19 November 2012 - 10:06 PM Rate Topic: -----

#1 jeromerpg11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 13-January 11

PHP and Database Interactions

Posted 19 November 2012 - 09:53 PM

im currently trying to learn php but i cant figure out how to make this program work..
this is what i want.. i would like to create a simple PHP application that will enable the user to add, delete, search and update records in my sql database..im currently having troubles with adding records to my database... so i cant proceed to deleting, searching and updating... Im also trying to make it all work in one file only (if it is possible to do) can anyone help me with this?

this is my code
<html>
<body>

<form action="j.php" method="post">
Username: <input type="text" name="username" />
Password: <input type="text" name="password" />
First: <input type="text" name="first" />
Last: <input type="text" name="last" />
about: <input type="text" name="about" />
<input type="submit" />
</form>

</body>
</html>

<?php

$accounts = mysql_connect("localhost" , "root" , "myownpassword") or die(mysql_error());

mysql_select_db("accounts", $accounts);

$sql = "INSERT INTO users (Username, Password, First, Last, About) VALUES('$_POST[username]', '$_POST[password]', '$_POST[first]', '$_POST[last]', '$_POST[about]')";

if (!mysql_query($sql, $accounts))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($accounts);

?>



Edited by macosxnerd101: Please make sure to use code tags: :code:, and a descriptive title.

Is This A Good Question/Topic? 0
  • +

Replies To: PHP and Database Interactions

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10823
  • View blog
  • Posts: 40,354
  • Joined: 27-December 08

Re: PHP and Database Interactions

Posted 19 November 2012 - 10:06 PM

I'm going to move this to PHP. Please remember to post your questions in the appropriate forum.

It's not clear exactly what the problem is from your description. I will suggest using Prepared Statements like PDO over the near deprecated mysql_*() family of functions. Prepared Statements guard against SQL Injections so you don't have to sanitize inputs, which you should do if you aren't using prepared statements.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1