Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


  Search this Thread
Old 05-16-2003, 10:07 AM   #1
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.




if ($submit) {

// process form

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


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

$result = mysql_query($sql);

echo $sql;
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">



} // end if



Old 05-16-2003, 10:54 AM   #2
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, 11:17 AM   #3
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977
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, 11:34 AM   #4
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


in this way, it doesn't matter if they are posts or gets....
Old 05-19-2003, 02:00 PM   #5
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?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 01:27 AM
why do i get this error when inserting data to a mysql table verbatim Programming 2 06-15-2005 07:12 AM
I need help with inserting data into mysql w/ PHP lostboy Programming 3 08-25-2003 01:08 PM
Problem Inserting MySQL data from PHP! rhuser Linux - Software 9 03-03-2003 08:56 PM
MySQL - Inserting Data Not Happening! Rhapsodic Programming 4 10-26-2002 11:58 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:35 PM.

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