Jump to content

Broken Code?


jvo

Recommended Posts

I am trying to implement a website using PHP and so far it's going rather well. Today I ran upon a bit of a hiccup. I've written some code folloing a tutorial that allows people to enter information to a database and it worked fine for a little while. But now it's broken. On the user end, it looks like it works, but when I actually browse the contents of the database, the information has not been added. I'm relatively new to the PHP/MySQL platform but as I'm not so familiar with the syntax yet, I could very well be over looking something quite simple. Below is the code from the two pages I have.

SIGNUP.HTML
<html>
<head> <title>.:: New User ::. </title></head>

<body>

<font face="arial" pt size=1>

<form action="insert.php" method="post">

Username: <input type="text" name="user"><br>
Password: <input type="password" name="password"><br>
Confirm Password: <input type="password" name="password"><br>
Email: <input type="text" name="email"><br>

First Name: <input type="text" name="first"><br>
Last Name: <input type="text" name="last"><br>
Primary Contact: <input type="text" name="phone"><br>
Age: <input type="text" name="age"><br>
Gender: <input type="radio" name="gender" value="M">Male
<input type="radio" name="gender" value="F">Female<br>

<input type="Submit">
</form>

</body>
</html>



INSERT.PHP

<?php
include("library/dblogin.php");

$user=$_POST['user'];
$password=$_POST['password'];
$email=$_POST['email'];

$first=$_POST['first'];
$last=$_POST['last'];
$phone=$_POST['phone'];
$age=$_POST['age'];
$gender=$_POST['gender'];

$query = "INSERT INTO users VALUES
('','$user','$password','$email','$first','$last','$phone','$age','$gender','0')";
mysql_query($query);


mysql_close();

?>

<html>
<head>
<title> .:: New User ::. </title>
</head>

<body>
<font face="arial" pt size="1">
<p align="center">
Your account has been successfully created.<br>
Thank you for registering. <br>
</p>
</body>
</html>

So there it is. Is there any reason why this code shouldn't work? Any insight would be helpful.
Link to comment
Share on other sites

If nothing is being added to your Database then there is a likely chance you have an error with your Query. To find out change this:
[code]mysql_query($query);[/code]
to:
[code]mysql_query($query) or die("Error: " . mysql_error());[/code]
Run you code again this time if there is a problem with your query it'll stop the script and show an error message. if it does return an error, post the full error message here and we'll try to help.
Link to comment
Share on other sites

[!--quoteo(post=364165:date=Apr 12 2006, 03:26 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 12 2006, 03:26 PM) [snapback]364165[/snapback][/div][div class=\'quotemain\'][!--quotec--]
If nothing is being added to your Database then there is a likely chance you have an error with your Query. To find out change this:
[code]mysql_query($query);[/code]
to:
[code]mysql_query($query) or die("Error: " . mysql_error());[/code]
Run you code again this time if there is a problem with your query it'll stop the script and show an error message. if it does return an error, post the full error message here and we'll try to help.
[/quote]


Hey, thanks so much for the fast reply. I did exactly what you said and here's what I get

[i]Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''users' VALUES ('','johndoe','0000','john@doe.com','John','D[/i]

I'm rechecking my code now, but it still looks fine. Any advise?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.