-
-
Save stanigator/5345a22b23c1ae98c1d1 to your computer and use it in GitHub Desktop.
MySQL database opening problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>FORM</title> | |
</head> | |
<body> | |
<form method="post" action="insert.php"> | |
Name: <input type="text" name="name" /><br /> | |
Email: <input type="text" name="email" /><br /> | |
Password: <input type="password" name="password" /><br /> | |
Confirm Password: <input type="password" name="cpassword" /><br /> | |
<input type="submit" name="submit" value="Register" /> | |
<a href="output.php">See data</a> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$name = $_POST["name"]; | |
$email = $_POST["email"]; | |
$pw = $_POST["password"]; | |
$cpw = $_POST["cpassword"]; | |
if ($name && $email && $pw) | |
{ | |
mysql_connect("localhost", "root", "") or die("We couldn't connect!"); | |
mysql_select_db("testsite"); | |
mysql_query("INSERT INTO users(name, email, password) VALUES('$name', '$email', '$pw'") or die(mysql_error()); | |
$registered = mysql_affected_rows(); | |
echo "$registered was inserted"; | |
} | |
else | |
{ | |
echo "At least one value is empty"; | |
} | |
mysql_close(); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
mysql_connect("localhost", "root", "") or die("Problem with connection"); | |
mysql_select_db("testsite"); | |
$result = mysql_query("SELECT * FROM users"); | |
while($row = mysql_fetch_array($result)) | |
{ | |
echo $row["name"]." ".$row["email"]." ".$row["password"]."<br />"; | |
} | |
mysql_close(); | |
?> |
You didn't check for errors in your mysql_query() lines. Try mysql_query( ... ) or die( mysql_error() );
How did you get a hold of my gist? Through the Freenode chat?
…On Thu, May 3, 2012 at 5:19 PM, Will Fong < ***@***.*** > wrote:
You didn't check for errors in your mysql_query() lines. Try mysql_query(
... ) or die( mysql_error() );
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/5345a22b23c1ae98c1d1
You pasted it!
I thought this is a private gist.
…-----Original Message-----
From: Will Fong [mailto:reply@reply.github.com]
Sent: Thursday, May 03, 2012 5:34 PM
To: stanigator
Subject: Re: gist gist: 5345a22b23c1ae98c1d1
You pasted it!
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/5345a22b23c1ae98c1d1
I have no idea. Why did you leave #mysql? :(
So you did find out from #mysql. I just got frustrated enough with the back and forth. I'm going to try my luck on Stackoverflow after trying your recommendation.
…-----Original Message-----
From: Will Fong [mailto:reply@reply.github.com]
Sent: Thursday, May 03, 2012 5:35 PM
To: stanigator
Subject: Re: gist gist: 5345a22b23c1ae98c1d1
I have no idea. Why did you leave #mysql? :(
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/5345a22b23c1ae98c1d1
Understood. But you can always try back in #mysql.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
All these files are in the testsite directory under xampp/htdocs/. I installed xampp and ran it before running the form.php in the browser. I made the "testsite" MySQL database, and the "users" table before running form.php (see http://i.imgur.com/pJXdm.png ). However, when I entered all the info properly, mysql_affected_rows() returned -1. This made me think that the database wasn't modified properly.