LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-24-2005, 09:30 PM   #1
Rockgod2099
Member
 
Registered: Oct 2004
Location: Chicago
Distribution: Fedora Core 2
Posts: 32

Rep: Reputation: 15
Angry 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;

}

#rowthree {
width : 773px;
top : 88px;
position:absolute;
text-align : center;
background : #cc0000;
color : #FFFFFF;
font-weight :bold;
font-family : Arial;
font-size : 1px;
href : underline;
a-color : #FFFFFF;
}
#citycol {
font-size : -1;
color : #000000
valign : top;
position:absolute;
top:110;
left:10;
width:120;
padding:5;
text-align:left;
}

#coltwo {
width : 400px;
left : 150px;
top : 110px;
text-align : center;
valign : top;
font-family : Times New Roman;
color : #000000;
font-size : 1;
position : absolute;
}

#colthree {
width : 200px;
left : 570px;
top : 110px;
background : #ffffff;
href : underline;
text-align : right;
font-family : Times New Roman;
font-size : 2;
position : absolute;
}

#rowfour {
width : 773px;
top : 500px;
position: absolute;
text-align : center;
background : #cc0000;
color : #FFFFFF;
font-family : Arial;
font-size : 1px;
href : underline;
}

#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">

<link rel="StyleSheet" type="text/css" href="map.css">
</head>

<div id="rowone"> </div>

<div id="rowtwo"> Put something here, dude. </div>

<div id="rowthree">

<A HREF="about.php">About MAP</A> ||

<A HREF="index.php">Browse MAP</A> ||

<A HREF="news.php">News & Announcements</A> ||

<A HREF="link.php"> Link To Us</A> ||

<A HREF="contact.php">Contact Us</a>

</div>

<div id="citycol">

<h3>Illinois</h3>

<ul>
<LI><a href="illinois/chicago/">Chicago</a></LI>
<li><a href="illinois/willcounty/">Will County</a></li>
</ul>

<h3><a href="other.html"><font color="#000000">Other Areas</font></a></h3>

</div>

<div id="coltwo">
<body>
<h3>Create a Listing on The Mutual Aid Phonebook</h3>

<FORM ACTION="profile.php" METHOD="POST">

<p>Name:
<input type="text" name="name"><br /> <br />

<p>Password:
<input type="text" name="password"><br /> <br />

<p>Type Password again please:
<input type="text" name="repassword"><br /> <br />

<p><input type="submit" name="submit" value="Continue"></p>

</FORM>

</body>

</div>

<div id="colthree">

<h3> Featured Sites </h3>

<ul>

<LI><a href="http://www.unboundbooks.org"><font face="Times New Roman" size="2">Unbound Books</font></a>

</ul>

More to come...

<h3>Important News</h3>

The MAP is looking for submissions. Check the <A HREF="news.html">News Page</A>
for more info...

<h3>Random Link of the Week</h3>

<a href="http://www.autonome.org">
<img border="0" src="http://www.autonome.org/en/img/a_worker.gif" width="160" height="60"></a>
<font face="Arial">Autonome</font>

</div>

<div id="rowfour">

<A HREF="about.php">About MAP</A> ||

<A HREF="index.php">Browse MAP</A> ||

<A HREF="news.php">News & Announcements</A> ||

<A HREF="link.php"> Link To Us</A> ||

<A HREF="contact.php">Contact Us</a>

</div>



</html>

profile.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());
//}

//if ((!$_POST[name]) || (!$_POST[password]) || ($_POST[password] != //$_POST[repassword])){

if ($_POST[op] != "add") {
header("Location: profile.html");
exit;
} else if ($_POST[op] == "add" {
if (($_POST[name] == " ") || ($_POST[password] == " ")){
header("Location: profile.html");
exit;
}


$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>";
};

}
?>


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());
//}

//if ((!$_POST[name]) || (!$_POST[password]) || ($_POST[password] != //$_POST[repassword])){

if ($_POST[op] != "add") {
$display_block = "
<h3>Create a Listing on The Mutual Aid Phonebook</h3>

<FORM ACTION=\"$_SERVER[PHP_SELF]\" METHOD=\"POST\">

Name:
<input type=\"text\" name=\"name\"><br /> <br />

Password:
<input type=\"text\" name=\"password\"><br /> <br />

Type Password again please:
<input type=\"text\" name=\"repassword\"><br /> <br />

<input type=\"hidden\" name=\"op\" values=\"add\"
<input type=\"submit\" name=\"submit\" value=\"Continue\">

</FORM>";
} else if ($_POST[op] == "add") {
if (($_POST[name] == " ") || ($_POST[password] == " ")){
header("Location: profile.php");
exit;
}


$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">

<link rel="StyleSheet" type="text/css" href="map.css">
</head>


<div id="rowone"> </div>

<div id="rowtwo"> Put something here, dude. </div>

<div id="rowthree">

<A HREF="about.php">About MAP</A> ||

<A HREF="index.php">Browse MAP</A> ||

<A HREF="news.php">News & Announcements</A> ||

<A HREF="link.php"> Link To Us</A> ||

<A HREF="contact.php">Contact Us</a>

</div>

<div id="citycol">

<h3>Illinois</h3>

<ul>
<LI><a href="illinois/chicago/">Chicago</a></LI>
<li><a href="illinois/willcounty/">Will County</a></li>
</ul>

<h3><a href="other.html"><font color="#000000">Other Areas</font></a></h3>

</div>

<div id="coltwo">

<?php echo $display_block; ?>


</div>

<div id="colthree">

<h3> Featured Sites </h3>

<ul>

<LI><a href="http://www.unboundbooks.org"><font face="Times New Roman" size="2">Unbound Books</font></a>

</ul>

More to come...

<h3>Important News</h3>

The MAP is looking for submissions. Check the <A HREF="news.html">News Page</A>
for more info...

<h3>Random Link of the Week</h3>

<a href="http://www.autonome.org">
<img border="0" src="http://www.autonome.org/en/img/a_worker.gif" width="160" height="60"></a>
<font face="Arial">Autonome</font>

</div>

<div id="rowfour">

<A HREF="about.php">About MAP</A> ||

<A HREF="index.php">Browse MAP</A> ||

<A HREF="news.php">News & Announcements</A> ||

<A HREF="link.php"> Link To Us</A> ||

<A HREF="contact.php">Contact Us</a>

</div>

</html>
 
Old 07-25-2005, 12:03 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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?
 
Old 07-25-2005, 03:08 PM   #3
Rockgod2099
Member
 
Registered: Oct 2004
Location: Chicago
Distribution: Fedora Core 2
Posts: 32

Original Poster
Rep: Reputation: 15
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?

Matt
 
Old 07-25-2005, 03:29 PM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Very often, when I am having similar bugs, I will do like this:
Code:
print("select $COL1,$COL2 from table where ID=$ID");
To see how PHP is evaluating the expression.
 
Old 07-25-2005, 04:26 PM   #5
Rockgod2099
Member
 
Registered: Oct 2004
Location: Chicago
Distribution: Fedora Core 2
Posts: 32

Original Poster
Rep: Reputation: 15
So I typed

print("SELECT * FROM auth WHERE ID=$ID");

as the last statement in the profile.php file, ran the .html file again, and still nothing.
 
Old 07-25-2005, 04:58 PM   #6
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Try to comment temporarly all your header() calls in profile.php in a first step
 
Old 07-25-2005, 08:25 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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.
 
Old 07-25-2005, 08:33 PM   #8
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Wow. I dunno how I missed that header... that really could be causing huge bugs.

Also note that in PHP it is preferred to quote associate array keys, i.e.
Code:
$_POST["username"]
This is not a bug, just a stylistic thing encouraged by the PHP developers.
 
Old 07-26-2005, 06:13 PM   #9
Rockgod2099
Member
 
Registered: Oct 2004
Location: Chicago
Distribution: Fedora Core 2
Posts: 32

Original Poster
Rep: Reputation: 15
I wrote print

("SELECT $user_name_pass FROM auth");

and it still won't print any errors

I commented out the header() files, ran profile.html and got nothing, so I commented out that entire if else statement, still nothing.

Could it be something with my php or mysql configuration?
 
Old 07-26-2005, 06:20 PM   #10
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Could you post just your profile.php between [ php] and [ /php] ?
 
Old 07-26-2005, 08:19 PM   #11
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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?
 
Old 07-27-2005, 12:20 AM   #12
Rockgod2099
Member
 
Registered: Oct 2004
Location: Chicago
Distribution: Fedora Core 2
Posts: 32

Original Poster
Rep: Reputation: 15
I opened up profile.php with firefox and viewed the source, it said the source was only

<html><body></body></html>

How would I make sure firefox or quanta were parsing php right? What exactly IS parsing?
 
Old 07-27-2005, 12:28 AM   #13
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Before each of the exit statements, try adding something like:
Code:
print "Error... SOMEVALUE was X, expected N";
My guess is it's "exit;"ing and not printing anything.
 
Old 08-03-2005, 12:27 AM   #14
Rockgod2099
Member
 
Registered: Oct 2004
Location: Chicago
Distribution: Fedora Core 2
Posts: 32

Original Poster
Rep: Reputation: 15
I tried inserting some error statements before "exit"ing but it still didn't do anything. Maybe I used the wrong syntax? I think I did something like

print "error, I messed up"

Matt
 
  


Reply


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
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
inserting data in mysql zuessh Linux - Software 4 05-19-2003 01:00 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 > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:56 AM.

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