php/mysql newbie

  • funtasy
  • Novice
  • Novice
  • funtasy
  • Posts: 30
  • Loc: kl malaysia

Post 3+ Months Ago

hello all, i just start to learn about php,i have an acc at free host.
i create a table of simple memberid... and i make a form and php code but isnt work!i try to enter some turtorial site but still having problem....please help,im really tired to search a turtorial site again..
Code: [ Select ]
<form action="insert.php" method="post">
MemberID: <input type="text" name="MemberID"><br>
Password: <input type="text" name="Password"><br>
description: <input type="text" name="description"><br>
<input type="Submit">
</form>
  1. <form action="insert.php" method="post">
  2. MemberID: <input type="text" name="MemberID"><br>
  3. Password: <input type="text" name="Password"><br>
  4. description: <input type="text" name="description"><br>
  5. <input type="Submit">
  6. </form>

and this my insert.php file
PHP Code: [ Select ]
 
<?
 
$username="funtasyng";
 
$password="34891128";
 
$database="funtasyng";
 
 
 
$MemberID=$_POST['MemberID'];
 
$Password=$_POST['Password'];
 
$Description=$_POST['Description'];
 
mysql_connect(localhost,$username,$password);
 
@mysql_select_db($database) or die( "Unable to select database");
 
 
 
$query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')";
 
mysql_query($query);
 
 
 
mysql_close();
 
header("Location:./index.php");
 
?>
  1.  
  2. <?
  3.  
  4. $username="funtasyng";
  5.  
  6. $password="34891128";
  7.  
  8. $database="funtasyng";
  9.  
  10.  
  11.  
  12. $MemberID=$_POST['MemberID'];
  13.  
  14. $Password=$_POST['Password'];
  15.  
  16. $Description=$_POST['Description'];
  17.  
  18. mysql_connect(localhost,$username,$password);
  19.  
  20. @mysql_select_db($database) or die( "Unable to select database");
  21.  
  22.  
  23.  
  24. $query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')";
  25.  
  26. mysql_query($query);
  27.  
  28.  
  29.  
  30. mysql_close();
  31.  
  32. header("Location:./index.php");
  33.  
  34. ?>


thats all,am i need to create a file something like $db_connect......??
thanks for help.
  • funtasy
  • Novice
  • Novice
  • funtasy
  • Posts: 30
  • Loc: kl malaysia

Post 3+ Months Ago

PHP Code: [ Select ]
$query = "INSERT INTO contacts VALUES

are the 'contacts' database table name?
i change like this also not work:


PHP Code: [ Select ]
 
$query = "INSERT INTO member VALUES ('','$MemberID','$description','$Password')";
 
mysql_query($query);
  1.  
  2. $query = "INSERT INTO member VALUES ('','$MemberID','$description','$Password')";
  3.  
  4. mysql_query($query);
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

There are two obvious things wrong with your script. First, you have to specify which colums you are inserting data into for your SQL query. So

$query = "INSERT INTO member VALUES ('','$MemberID','$description','$Password')";

would become

$query = "INSERT INTO member (name1, name2, name3, name4) VALUES ('','$MemberID','$description','$Password')";

replaceing name1, name2, etc. with your colum names

Second, the HTTP specification says that you can not redirect to a relative URI.

Your last line shoud be
header("Location: http://yourdomain.com/index.php");

also it is a good idea (but not essential) that you have an exit(); immediately after your redirect.
  • funtasy
  • Novice
  • Novice
  • funtasy
  • Posts: 30
  • Loc: kl malaysia

Post 3+ Months Ago

the colum,how to create it?
at mysql? please help. thanks again. :wink:
mmm,,i try to check it out from phpmyadmin.this what i get,
i set the memberid for primary key, then i saw an indexes ,ask me to create an index on ? colum, i really dont know what is this, to make a colum?
is that keyname are colum u mean?
if that right,and if 1oo member going to sign up, i need to write how many name1...name2..........?!! :roll: for 100?

2.and what is 'unique' ,'fulltext' function on 'action'?
3.null or not null..... im turning my head about mysql...... :cry:
4this the last question,hate to ask.. :wink: can i have both of index page in html and php?

thanks for help!
  • veedee
  • Graduate
  • Graduate
  • User avatar
  • Posts: 110

Post 3+ Months Ago

hi.. i'm newbie too
if I'm not mistaken, in a folder you can make one or more index (with different ext, such as index.php,index.htm,index.html) , but only one that can be executed with "http://www.yoursite.com/"
others must be executed with "http://www.yoursite.com/index.htm" or "http://www.yoursite.com/index.html"

It's depend on your server setting, which one in the first order (can be index.php, index.htm, or index.html ->that's mean if no index.php then search for index.htm & if no index.htm search for index.html).
  • veedee
  • Graduate
  • Graduate
  • User avatar
  • Posts: 110

Post 3+ Months Ago

try to put double quotes in localhost:
mysql_connect("localhost",$username,$password);
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

Maybe you should take some basic lessons in database design... I'll try to explain it anyway.

Your mysql tables are a two dimensional set of data, kind of like a spreadsheet. You do not need one colum for each user, you need one row for each user, and using INSERT creates a new row.

You have one primary key (usually a numeric colum identifying the row) and you can have indicies but you don't have to have them.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

rjstephens wrote:
There are two obvious things wrong ...

$query = "INSERT INTO member VALUES ('','$MemberID','$description','$Password')";

Second, the HTTP specification says that you can not redirect to a relative URI.

Your last line shoud be
header("Location: http://yourdomain.com/index.php");


Umm I don't mean to start a brawl here but the SQL statement that you said is wrong does actually work (used it on numerous occasions) and the redirect can be a relative page (used it on a regular basis to)

Just wanted to point that out (maybe I'm wrong but it works for me :oops: )
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

The SQL statement I'm not 100% sure about. But I am 100% sure that the HTTP specifications say that when you do a 301 or a 302 redirect you MUST use an ABSOLUE URI. A relative URI may work on some browsers, but it is still wrong according to the HTTP specifications.

Just like how a page made with frontpage works find in internet explorer even though the HTML is crap. It works, but it is just plain wrong according to the HTML standard.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Thanks for that, I will go check out the specs :wink:

Um RJ do you have a link to those specs? The w3c specs are not very clear on the above topic - thanks (did find some interesting info on headers though)
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

Rabid,
ftp://ftp.isi.edu/in-notes/rfc2616.txt

Section 14.30


That is also pointed out here
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Thanks - useful info here.

Post Information

  • Total Posts in this topic: 12 posts
  • Users browsing this forum: No registered users and 44 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.