Create table werkt niet.
Ik ben nu al 3 dagen bezig met het volgende script:
--------------------------------------------------------------------
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
$con = mysql_connect("host","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("md212730db238717", $con);
$sql = "CREATE TABLE Persons
(
FirstName varchar(15),
LastName varchar(15),
)";
// Execute query
mysql_query($sql,$con);
mysql_close($con);
?>
$con = mysql_connect("host","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("md212730db238717", $con);
$sql = "CREATE TABLE Persons
(
FirstName varchar(15),
LastName varchar(15),
)";
// Execute query
mysql_query($sql,$con);
mysql_close($con);
?>
--------------------------------------------------------------------
Wat het ook doet, het maakt geen tabel aan, het geeft me ook geen error. Ik heb me suf gezocht op het internet maar zeer weinig gevonden. Wat ik vond werkte niet.
Kunnen jullie me misschien vertellen wat ik fout doe?
Ik zou het zeer op prijs stellen.
M.v.g.
Mr.Wiedeman
wat dacht je van foutafhandeling?
Je hebt nog een komma na de declaratie van LastName staan.
Het werkt, ik kan het niet geloven. 3 dagen werk naar z'n grootje alleen voor een comma... Dit voelt echt heel naar. Heel erg bedankt voor jullie hulp en mijn excuses voor het storen.
mysql_query levert net al mysql_connect een resultaat dat je kunt opvragen.
als je dus
had gedaan had je het probleem meteen gevonden. (die() is trouwen geen goede/mooie oplossing, maar voor problemen vinden werkt het prima)
Gewijzigd op 26/11/2012 22:55:39 door Frits Katoen
zou iemand me hier ook nog mee kunnen helpen:
DoneError: 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 '''')' at line 3
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
include 'create.php';
$con = mysql_connect($host,$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db, $con);
$sql="INSERT INTO Persons (Subject, News)
VALUES
('$_POST[Subject]','$_POST[News]'')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
include 'create.php';
$con = mysql_connect($host,$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db, $con);
$sql="INSERT INTO Persons (Subject, News)
VALUES
('$_POST[Subject]','$_POST[News]'')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
Gewijzigd op 26/11/2012 23:53:22 door Robert Wiedeman
Code (php)
1
2
3
4
5
2
3
4
5
<?php
$sql="INSERT INTO Persons (Subject, News)
VALUES
('$_POST[Subject]','$_POST[News]'')";
?>
$sql="INSERT INTO Persons (Subject, News)
VALUES
('$_POST[Subject]','$_POST[News]'')";
?>
Netter en veiliger:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
<?php
$sql = "INSERT INTO Persons
(
Subject,
News
)
VALUES
(
'" . mysql_real_escape_string($_POST['Subject']) . "',
'" . mysql_real_escape_string($_POST['News']) . "'
)
";
?>
$sql = "INSERT INTO Persons
(
Subject,
News
)
VALUES
(
'" . mysql_real_escape_string($_POST['Subject']) . "',
'" . mysql_real_escape_string($_POST['News']) . "'
)
";
?>
index.php:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
include 'Lo_db_usrpsho.php';
/* This is the beginning of the
* body of the website. Do not
* forget that there still has
* to be a submenu placed inside
* this location of the website.
*/
Echo "Here comes the context of the website.";
//---------------------------------------------
/* Here comes the first attempt to
* connect to the mysql database
* This goes to a different file
* once tested and working for
* security
*/
$con = mysql_connect($host,$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("md212730db238717", $con);
$result = mysql_query("SELECT * FROM HPNews");
echo "<table border='1'>
<tr>
<th>Subject</th>
<th>News</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Subject'] . "</td>";
echo "<td>" . $row['News'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
include 'Lo_db_usrpsho.php';
/* This is the beginning of the
* body of the website. Do not
* forget that there still has
* to be a submenu placed inside
* this location of the website.
*/
Echo "Here comes the context of the website.";
//---------------------------------------------
/* Here comes the first attempt to
* connect to the mysql database
* This goes to a different file
* once tested and working for
* security
*/
$con = mysql_connect($host,$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("md212730db238717", $con);
$result = mysql_query("SELECT * FROM HPNews");
echo "<table border='1'>
<tr>
<th>Subject</th>
<th>News</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Subject'] . "</td>";
echo "<td>" . $row['News'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
Insert.php:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
include 'Lo_db_usrpsho.php';
$con = mysql_connect($host,$username,$password) or die(mysql_error());
mysql_select_db($db, $con);
$sql = "INSERT INTO HPNews
(
Subject,
News
)
VALUES
(
'" . mysql_real_escape_string($_POST['Subject']) . "',
'" . mysql_real_escape_string($_POST['News']) . "'
)
";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
include 'Lo_db_usrpsho.php';
$con = mysql_connect($host,$username,$password) or die(mysql_error());
mysql_select_db($db, $con);
$sql = "INSERT INTO HPNews
(
Subject,
News
)
VALUES
(
'" . mysql_real_escape_string($_POST['Subject']) . "',
'" . mysql_real_escape_string($_POST['News']) . "'
)
";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
create.php:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
include 'Lo_db_usrpsho.php';
$con = mysql_connect($host,$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//het selecteren van de database.
mysql_select_db("md212730db238717", $con);
$sql = "CREATE TABLE HPNews
(
Subject varchar(15),
News text(65535)
)";
// Execute query
mysql_query($sql,$con);
mysql_close($con);
Echo "Done";
?>
include 'Lo_db_usrpsho.php';
$con = mysql_connect($host,$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//het selecteren van de database.
mysql_select_db("md212730db238717", $con);
$sql = "CREATE TABLE HPNews
(
Subject varchar(15),
News text(65535)
)";
// Execute query
mysql_query($sql,$con);
mysql_close($con);
Echo "Done";
?>
Lo_db_usrpsho.php:
Code (php)
1
2
3
4
5
6
2
3
4
5
6
<?php
$host = "db.secret.org";
$username = "md_secret";
$password = "sercetpass";
$db = "md212730db238717";
?>
$host = "db.secret.org";
$username = "md_secret";
$password = "sercetpass";
$db = "md212730db238717";
?>
Hoe kan ik ervoor zorgen dat hij ook daadwerkelijk waardes toevoegt?
Toevoeging op 27/11/2012 05:08:27:
Ik heb het al voor elkaar. Ik had de form nog niet in zijn geheel op de goede manier aangepast. Sorry voor het storen en bedankt voor de tips. Andere kritiek is natuurlijk ook welkom ik zal deze topic nog even in de gaten houden.
Gewijzigd op 27/11/2012 05:05:27 door Robert Wiedeman