Problem inserting data into a mysql table using PHP
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Problem inserting data into a mysql table using PHP
Hey there. So I'm trying to write code for a website that will use mysql and php to allow users to create a membership, edit their info, etc. However everytime I test run the code on my computer and try to view the updated table, it tells me that the table hasn't been changed. I have even tried making two different versions of this page, one with a seperate .html and .php and one with all the code in a single .php file. BOth of them use a .css file. I've included all those files below. I can't figure out for the life of me why it won't work.
When I try to use the one file that has both the php and html code in it called profile2.php I can't even preview it in quanta editor.
I've read books and artciles and can't figure out what I'm doing wrong. If whoever figures out what my problem is lives in the Chicago area I'll buy them free drinks.
Matt
Map.css
#rowone {
background : url(mapredglow.jpg);
position : absolute;
width : 773px;
height : 60px;
left : 10px;
top : 10px;
}
#rowtwo {
top : 70px;
height : 18px;
width : 773px;
valign : middle;
position : absolute;
color : #cc0000;
background : #DBDBDB;
text-align : right;
font-size : 1px;
font : Verdana;
#rowfive {
top : 520px;
width : 773px;
text-align : center;
font-size : 2;
position : absolute;
}
h3 {
background : #cc0000;
text-align : center;
font-weight : bold;
color : #ffffff;
font-family : Times New Roman;
font-size : 10;
padding : 3;
}
profile.html
<html>
<head>
<TITLE>Create a Listing</TITLE>
<META content=description name="add your site description">
<META content=keywords name="add your site keywords">
<?php
//function emailChecker($user_name_pass){
// global $conn, $check_result;
// $check = "select id from subscribers where email = '$user_name_pass'";
// $check_result = mysql_query($check,$conn) or die(mysql_error());
//}
mysql_query($user_name_pass) or die(mysqlerror());
mysql_query($user_name_pass, $conn) {
$display_block = "<a href="listing.html">Tell us more about yourself</a>";
};
}
?>
profile2.php
<?php
//function emailChecker($user_name_pass){
// global $conn, $check_result;
// $check = "select id from subscribers where email = '$user_name_pass'";
// $check_result = mysql_query($check,$conn) or die(mysql_error());
//}
$conn = mysql_connect("localhost", "root")
or die(mysql_error());
mysql_select_db("map",$conn) or die(mysql_error());
$user_name_pass = "INSERT INTO auth (id, username, password) values (' ', '$_POST[name]', '$_POST[password]')"; mysql_query($user_name_pass) or die(mysqlerror());
mysql_query($user_name_pass, $conn) {
$display_block = "<a href=\"listing.html\">Tell us more about yourself</a>";
};
?>
<html>
<head>
<TITLE>Create a Listing</TITLE>
<META content=description name="add your site description">
<META content=keywords name="add your site keywords">
In the future, please wrap code in [ code ][ /code ] tags. Much easier to read. (Remove spaces, obviously).
The CSS code probably is irrelevant to a PHP issue. Do you get any MySQL errors back? Have you tried replacing mysql_query with a print/echo to see what the assembled query looks like?
Part of the infuriating thing about this is that there are no error messages. I will view profile.html through firefox, fill out the boxes and hit continue, then get a blank screen. Then when I go to the mysql prompt and type
SELECT * FROM auth;
it tells me that the table has had no data inserted into it.
What do you mean use echo instead of query where would I use that and echo what exactly?
Actually, Matir was just showing you an example... try printing your constructed INSERT statement ie $user_name_pass variable.
Incidentally, are you sure you want id to be ' '?
If it's an auto-increment col, don't specify it's name+val at all in the INSERT; the DB will handle that for you automatically.
On another question.... are you sure your server is actually parsing the PHP document? Have you tried running the PHP document at the command line? Have you tried using "view source" in your browser to see if there's anything "hidden" there?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.