473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problems Inputting Date into My database.

I am currently using a version of phpmyadmin via heartinternet.

I can connect to my database fine, but I cannot seem to input any database into the table I have created.

the database is called "web-32jerry" and the table is called "login" for reference sake.

The code i have at the moment has 2 text boxes which they input their username and password in and then a submit button attached.

I have taken bits from 2 different tutorials to help me so they are probably bits of code in there that i dont even need so it will look messy!!


the code i have is the following;

Expand|Select|Wrap|Line Numbers
  1. <form method="post">
  2. <p>Username - 
  3.   <input name="user" type="text" id="user" size="15">
  4.     <br>
  5.   Password -     
  6.   <input name="pass" type="text" id="pass" size="15">
  7. <br> <input name="add" type="submit" id="add" value="add">
  8. </form>
  9.  
  10. <?php
  11.  
  12. if(isset($_POST['add']))
  13. {
  14.  
  15. mysql_connect("localhost", "web32-jerry", "my password")
  16.     OR die ("Can't Access any database.");
  17.  
  18.  
  19.  
  20. mysql_selectdb("web32-jerry")
  21.     OR die ("Cant access the 'jerry' database.");
  22.  
  23. $user= $_POST['user'];
  24. $pass = $_POST['pass'];
  25.  
  26. $query = "INSERT INTO login (host, user, pass, select_priv, insert_priv, update_ priv) VALUES ('localhost', '$user', PASSWORD('$pass'), 'Y', 'Y', 'Y')";
  27.  
  28.  
  29. mysql_query($query) or die('Error , insert query failed');
  30.  
  31. $query = "FLUSH PRIVILEGES";
  32. mysql_query($query) or die('Error, insert query failed');
  33. }
  34.  
  35. ?>
  36.  
any help given i will be very greatful for...

thank you very much,

Jerry
Jul 18 '08 #1
9 1905
amitpatel66
2,367 Expert 2GB
So here you are facing a problem in conneting to the database or during inserting a record in to database table?
Jul 18 '08 #2
Crisis averted!

Sorry, I actually figured it out earlier!!

Cheers for the quick reply anyway dude!

Thanks!
Jul 18 '08 #3
amitpatel66
2,367 Expert 2GB
Crisis averted!

Sorry, I actually figured it out earlier!!

Cheers for the quick reply anyway dude!

Thanks!
Thats good to hear that your issue is resolved. It would be helpful if you can post your solution here so that in can be helpful for other members of the forum looking for a solution of a similar issue.
Jul 18 '08 #4
I had a number of pages

The form I used on my home page was the following;
Expand|Select|Wrap|Line Numbers
  1. <form name="form1" method="post" action="checklogin.php">
  2.  
  3. <div align="center">Username : 
  4.   <input name="myusername" type="text" id="myusername">
  5.  
  6.   Password : 
  7.   <input name="mypassword" type="password" id="mypassword">
  8. <p>
  9. <input type="submit" name="Submit" value="Login">
  10.  
  11. I then had a page with checked their login in details
  12.  
  13. <?php
  14. $host="localhost"; // Host name 
  15. $username=""; // Mysql username 
  16. $password=""; // Mysql password 
  17. $db_name=""; // Database name 
  18. $tbl_name=""; // Table name 
  19.  
  20. // Connect to server and select databse.
  21. mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
  22. mysql_select_db("$db_name")or die("cannot select DB");
  23.  
  24. // username and password sent from form 
  25. $myusername=$_POST['myusername']; 
  26. $mypassword=$_POST['mypassword']; 
  27.  
  28. // To protect MySQL injection (more detail about MySQL injection)
  29. $myusername = stripslashes($myusername);
  30. $mypassword = stripslashes($mypassword);
  31. $myusername = mysql_real_escape_string($myusername);
  32. $mypassword = mysql_real_escape_string($mypassword);
  33.  
  34. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  35. $result=mysql_query($sql);
  36.  
  37. // Mysql_num_row is counting table row
  38. $count=mysql_num_rows($result);
  39. // If result matched $myusername and $mypassword, table row must be 1 row
  40.  
  41. if($count==1){
  42. // Register $myusername, $mypassword and redirect to file "login_success.php"
  43. session_register("myusername");
  44. session_register("mypassword"); 
  45. header("location:login_success.php");
  46. }
  47. else {
  48. echo "Wrong Username or Password";
  49. }
  50. ?>
  51.  
And that directed me to a page called login_success.php which I created as a members area...

Im now having a new problem though...

At the bottom my direction is the following;

session_register("myusername");
session_register("mypassword");
header("location:login_success.php");


If I have 2 accounts created for example

John and Jerry

When those 2 accounts both log-in they both go to the same page (login_success.php)

Do you know of a way I can direct each different user to a different page...

I can't find anything about it on the Internet, surprising with the amount of phpmysql log-in form tutorials that come up....

I was thinking of an If statement, but I can't seem to get what I've done to work! Just gives me unknown $ errors etc..

Any ideas?
Jul 22 '08 #5
Atli
5,058 Expert 4TB
Hi.

Why do you want to direct each of your users to separate pages?
Would it not be better to simply have that one page display different content based on which user is logged in?

Anyhow, a simple if statement should suffice:
Expand|Select|Wrap|Line Numbers
  1. if($userName = "Jerry") $url = "jerry.php";
  2. else if($userName = "John") $url = "john.php";
  3. header("Location: ". $url);
  4.  
One thing you should look out for tho.
The session_register function is very old and should not be used anymore, unless you are using PHP3, in which case you really really should upgrade!

It is better to simply assign or unset elements in the $_SESSION array, like:
Expand|Select|Wrap|Line Numbers
  1. // Instead of
  2. session_register("variable");
  3. session_unregister("variable");
  4. // Do
  5. $_SESSION['variable'] = $variable;
  6. unset($_SESSION['variable']);
  7.  
And please use [code] tags when posting code examples.
Jul 23 '08 #6
Okay that's fine.

Im not using PHP3, that's just something I saw so I used it. I will get onto changing that now! Thanks for that!

Basically, I want each person to be directed to their own User page. It's like for example how on play.com you get directed to your own page where you can view your previous orders and personal details and no one else can!

I need to have our clients see their own individual data but not any of the other clients we have!

If that makes sense!

Thanks for the help though!
Jul 23 '08 #7
I just read through your post again and yes your idea does seem more sensible!

I just need clients to view their own information and not other peoples and that method of using the same page but displaying different data sounds like it would be more organised!

How would I go about that then?

I'm currently reading through my book (i.e. my bible at the moment) to see if I can figure it out hehe

thanks
Jul 23 '08 #8
Two ideas I was thinking of on how to do it.

Include Files - I could validate the username, and each username brings up a different a include file on the user page.(but then that sounds familiar to my original idea...)

or

Storing the information in the Database - I could store the information I want to display in the database and then can display it by calling it up using variables etc...


Sorry for all the continual posts, I just wanted to show that I am actually thinking/trying to do something about it rather than just mooch off everyone else.

Would any of my above ideas work?
Jul 23 '08 #9
Atli
5,058 Expert 4TB
That second idea is pretty much how it is usually done.

Most pages like these are created with a standard "template" of sorts, that is filled in using personalized data from a database (or some other source of info).

Like, for example, if you had a page that should display the contact info for the logged in user, you could do something like this:
Expand|Select|Wrap|Line Numbers
  1. echo "<table>";
  2. echo "<tr><td>Email</td><td>Webpage</td><td>Phone</td></tr>";
  3.  
  4. $sql = "
  5.   SELECT email, web, phone FROM user
  6.   WHERE username = '{$_SESSION['UserName']}'";
  7. $result = mysql_query($sql) or die("Query failed: ". mysql_error());
  8.  
  9. while($row = mysql_fetch_assoc($result)) {
  10.   echo "<tr>";
  11.   echo " <td>{$row['email']}</td>";
  12.   echo " <td>{$row['web']}</td>";
  13.   echo " <td>{$row['phone']}</td>";
  14.   echo "</tr>";
  15. }
  16. echo "</table>";
  17.  
It's a little simplistic but you get the point.
Jul 23 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Raphael Gluck | last post by:
Hi everyone I am trying to create a form to update a database table. I have all the fields, set up, and a submit button happily processes my form. However, I am trying to create a field in my...
2
by: josepe | last post by:
Hi, I have an asp site web with connections to a SQL server database. All works ok in a Server of USA, I have changed to a new server in UK and I have configured the new server as the USA...
3
by: AndyBell | last post by:
Hi all! I have an Access 2000 database for the Habiat for Humanity where I work. This is the second database I have written and it gets a bit more complex each time... I have learned much and...
5
by: Eddie | last post by:
I have an Access database that tracks project information. The database is very simple, except for 1 small aspect. Some background: 4 Tables - Project information, Employees, activity and pay...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
5
by: Chris | last post by:
I have a meetings section I'm developing on our intranet. Using PHP/MySQL. Meeting info and Meeting docs reside on 2 related tables in the db. Users may want to upload anywhere from 1 to 10 or...
18
JamesDC
by: JamesDC | last post by:
Hi, So I'm working with an Access 2002 database for waste managemnt. The person in my role before my put together the program before he left and now I'm in charge of it. After updating a few...
2
by: rustyc | last post by:
Well, here's my first post in this forum (other than saying 'HI' over in the hi forum ;-) As I said over there: ... for a little side project at home, I'm writing a ham radio web site in...
4
by: atyndall | last post by:
OK, this is the relevant portion script: <?php $username = '__'; // MySQL Database Username. $password = '__'; // MySQL Database Password. $server = '__'; // MySQL Database server (most...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.