SitePoint Sponsor |
|
User Tag List
Results 1 to 12 of 12
Thread: Need Help with PHP + MySQL
-
May 12, 2009, 20:03 #1
- Join Date
- May 2008
- Posts
- 8
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Need Help with PHP + MySQL
Hey guys,
I have been running into problems with this code for a bit now. Since I am just learning PHP, I decided that the best way to learn is to start building. So I got part of the script done, but ran into a problem adding data to a database.
I have a file called ADD dot php which looks like this:
<?php include "base dot php"; ?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Beta Test</title>
<link rel="stylesheet" href="style dot css" type="text/css" />
</head>
<body>
<h1>Add Domain</h1>
<form method="post" action="addomain dot php" name="loginform" id="loginform">
<fieldset>
<label for="domain">Domain/label><input type="text" name="domain" id="domain" /><br /><br />
<input type="submit" name="submit" id="submit" value="Add Domain!" />
</fieldset>
</form>
<a href="logout dot php">Logout</a>
<?php
$first = $_POST['domain'];
$sql = "INSERT INTO (domains) VALUES ('$first')";
mysql_query($sql);
{
?>
Parse error: syntax error, unexpected $end in addomain dot php on line 6
Thanks,
-
May 12, 2009, 20:23 #2
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
What is the last "{" in the file for? It doesn't match anything, which is probably why it's complaining.
You need to connect to the database before you can issue queries to itTry Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
-
May 12, 2009, 20:31 #3
- Join Date
- May 2008
- Posts
- 8
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok, That works. No more syntax erroe but now for some reason, its not adding anything to the database. :/
-
May 12, 2009, 20:37 #4
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Did you connect to the database before calling mysql_query?
Also, your query is not correct. It's missing either the table name or the name of the column, I'm not sure which...
PHP Code:$sql = "INSERT INTO table_name (column_name) VALUES ('$first')";
Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
-
May 12, 2009, 20:40 #5
- Join Date
- May 2008
- Posts
- 8
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Wow thanks man. That works!
-
May 13, 2009, 12:16 #6
- Join Date
- May 2008
- Posts
- 8
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
When I try to add another domain, it doesnt add a new row. Why is there?
-
May 13, 2009, 12:24 #7
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Two things:
1) Share the schema of the table. Show the CREATE TABLE query that created it.
2) Share the error message.
PHP Code:$ret = mysql_query($sql);
if (!$ret) {
echo "Error: " . mysql_error();
}
Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
-
May 13, 2009, 12:27 #8
- Join Date
- May 2008
- Posts
- 8
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Not sure what you mean for #1 but if I got to phpMyAdmin, and click the table, it says this for the MySQL query
SELECT *
FROM `domains`
LIMIT 0 , 30
Error: Duplicate entry '' for key 1
-
May 13, 2009, 12:29 #9
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
You need to set the primary key of the table to an auto_incrementing integer.
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
May 13, 2009, 12:30 #10
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
-
May 13, 2009, 12:36 #11
- Join Date
- May 2008
- Posts
- 8
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I have 3 rows in the database. uid, username, and domain. I'm not worried about the username and uid now, just need to add the domains.
-
May 13, 2009, 12:38 #12
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
Bookmarks