LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-16-2003, 09:07 AM   #1
zuessh
Member
 
Registered: Jun 2002
Location: USA
Distribution: Suse 8.0
Posts: 247

Rep: Reputation: 30
inserting data in mysql


I posted this on phpbuilder but didn't get much help so I knew this was the best place. I am trying to insert data into mysql database. Below is the code, any suggestions, it does not return any errors and takes me straight back to the form page, but does not insert data.


<html>

<body>

<?php



if ($submit) {

// process form

$db = mysql_connect("localhost", "testphp", "test") or die("couldnt connect");

mysql_select_db("php",$db);

$sql = "INSERT INTO phptest (id,name,address,phone) VALUES ($id,'$name','$address','$phone')"
;

$result = mysql_query($sql);

echo $sql;
if(mysql_error()){
echo mysql_error();
}


echo "Thank you! Information entered.\n";

} else{



// display form



?>


<form method="post" action="<?php echo $PHP_SELF?>">

id:<input type="Text" name="id"><br>

name:<input type="Text" name="name"><br>

address:<input type="Text" name="address"><br>

phone:<input type="Text" name="phone"><br>

<input type="Submit" name="submit" value="Enter information">

</form>


<?php



} // end if



?>

</body>

</html>
 
Old 05-16-2003, 09:54 AM   #2
cyber
Member
 
Registered: Feb 2003
Location: Sweden
Distribution: RedHat Linux 8.0
Posts: 43

Rep: Reputation: 15
if it takes you right back to the form page then "if ($submit)" can't work like you want it to,.,. try to put <input type="hidden" name="check" value="1"> and do a "if ($check == 1)".
 
Old 05-16-2003, 10:17 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
you can't access those values as global variables, i'm not too hot on PHP, but i think you either need $data["address"] or $_POST["address"]
 
Old 05-16-2003, 10:34 AM   #4
vous
Member
 
Registered: Mar 2003
Location: Macondo
Distribution: Mandrake 9.1, 10.1, SuSE 8.1 pro, 10.1, Red Hat 8.0/9.0
Posts: 380

Rep: Reputation: 30
....or

$_REQUEST["address"]

in this way, it doesn't matter if they are posts or gets....
 
Old 05-19-2003, 01:00 PM   #5
zuessh
Member
 
Registered: Jun 2002
Location: USA
Distribution: Suse 8.0
Posts: 247

Original Poster
Rep: Reputation: 30
I still do not understand, is the problem with the php script or with the form? Would it be best to change the php script or the form?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem inserting data into a mysql table using PHP Rockgod2099 Programming 13 08-03-2005 12:27 AM
why do i get this error when inserting data to a mysql table verbatim Programming 2 06-15-2005 06:12 AM
I need help with inserting data into mysql w/ PHP lostboy Programming 3 08-25-2003 12:08 PM
Problem Inserting MySQL data from PHP! rhuser Linux - Software 9 03-03-2003 07:56 PM
MySQL - Inserting Data Not Happening! Rhapsodic Programming 4 10-26-2002 10:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration