MySQL Insert with PHP
1
Name:
Anonymous
2010-12-17 11:05
I can't figure this out. Something is wrong with my SQL insert statement, and I have no idea what it is. (I also tried setting the variables for all of the values to be input, ie $city = "test" but that didn't work either...halp!)
<form method="POST" action="hw8b.php">
Name:<br />
<input type="text" name="name1" /><br /><br />
City:<br />
<input type="text" name="city" /><br /><br />
Email:<br />
<input type="text" name="email" /><br /><br />
<input type="submit" value="Insert">
</form>
<?php
$DBConnect = mysql_connect("localhost", "howard", "");
if (! $DBConnect)
{
echo "<P>Database not available";
}
$_POST["howard"];
$_POST["password"];
$name1 = $_POST["name1"];
$city = $_POST["city"];;
$email = $_POST["email"];
mysql_select_db("myDB");
$SQLstring = "SELECT MAX(ID) FROM FANS";
$QueryResult = mysql_query($SQLstring);
$Row = mysql_fetch_row($QueryResult);
$fanID = $Row[0] + 1;
$SQLstring = "INSERT INTO FANS VALUES(" . $fanID . ",'" . $name1 . "','" . $city . "','" . $email . "');";
$QueryResult = mysql_query($SQLstring);
2
Name:
Anonymous
2010-12-17 11:11
3
Name:
Anonymous
2010-12-17 11:11
4
Name:
Anonymous
2010-12-17 11:20
>>3
Yep, I see no way to delete an old post, and I find it counter-productive to reply to a thread so convoluted with bullshit replies.
5
Name:
Anonymous
2010-12-17 11:21
>>4
Well, you still have the same problems.
6
Name:
Anonymous
2010-12-17 11:27
I know, problem is I can't for the life of me figure them out.
I looked up the proper syntax for inserts with php into a mysql table, and I have:
$SQLstring = "INSERT INTO FANS (FANID, NAME, CITY, EMAIL) VALUES ('5','Richard','Place','R@P.com');";
This doesn't do shit either.
7
Name:
Anonymous
2010-12-17 11:43
Why did you make a new thread.
8
Name:
Anonymous
2010-12-17 11:45
Hello, Howard .
9
Name:
Anonymous
2010-12-17 16:08
<?php
$DBConnect = mysql_connect("localhost", "howard", "");
if (! $DBConnect)
{
echo "<P>Database not available";
}
$userID = $_POST["howard"];
$password = $_POST["password"];
$name1 = $_POST["name1"];
$city = $_POST["city"];;
$email = $_POST["email"];
mysql_select_db("myDB") or die(mysql_error());
$SQLstring = "SELECT MAX(FANID) FROM FANS" or die(mysql_error());
$QueryResult = mysql_query($SQLstring);
$Row = mysql_fetch_row($QueryResult);
$newID = $Row[0] + 1;
$SQLstring = "INSERT INTO FANS (FANID, NAME, CITY, EMAIL) VALUES ($newID,$name1,$city,$email);" or die(mysql_error());
$QueryResult = mysql_query($SQLstring);
mysql_close($DBConnect);
?>
The PHP page loads, doesn't output any errors...but it doesn't fucking INSERT THE GOD DAMN FORM DATA.
WHYYYYYYYYYYYYYYYYYYYYYYYYYYY
10
Name:
Anonymous
2010-12-17 16:10
>>9
add some fucking quotes or follow the links in your other thread goddamn stop being retarded
11
Name:
Anonymous
2010-12-17 16:14
>>10
Dude I've added over 9000 quotes, removed quotes, tried different quotes, done a bunch of random shit...
if I put shit to select * from fans; and output it for each row incremented... it PRINTS the table. I know 100% that it's loading the table. I can't get it to FUCKING INSERT NO MATTER WHAT I FUCKING TRY TO PUT.
I've followed the goddamned links and tried a bunch of shit, none of which WORKS. I don't get why the insert doesn't work. I've tried fucking everything.
12
Name:
Anonymous
2010-12-17 16:17
It's the motherfucking variables.
I added or die("name"); after the $name = $_POST["name1"];
and it printed "name"
HOW THE FUCK IS THE FORM DATA NOT BEING RECEIVED?
13
Name:
Anonymous
2010-12-17 16:19
>>11
Does the user have the right permissions?
14
Name:
Anonymous
2010-12-17 16:20
>>13
It should...I mean I can connect to the database in the PHP file, then print the contents of the table.
I assume I would also be able to insert data to the table...but it's not working.
15
Name:
Anonymous
2010-12-17 16:41
http://php.net/mysql_error
Also, do your own homework.
16
Name:
Anonymous
2010-12-17 16:43
Nigger nigger nigger nigger fuck fuck.
It was the single quotes I think. FINALLY figured this gay shit out.
Working final code:
<?php
$DBConnect = mysql_connect("localhost", "howard", "");
if (! $DBConnect)
{
echo "<P>Database not available";
}
$userID = $_POST["howard"];
$password = $_POST["password"];
$name1 = $_POST["name1"];
$city = $_POST["city"];
$email = $_POST["email"];
mysql_select_db("myDB") or die(mysql_error());
$SQLstring = "SELECT MAX(FANID) FROM FANS" or die(mysql_error());
$QueryResult = mysql_query($SQLstring);
$Row = mysql_fetch_row($QueryResult);
$newID = $Row[0] + 1;
$SQLstring = "INSERT INTO FANS (FANID, NAME, CITY, EMAIL) VALUES ('$newID','$name1','$city','$email');" or die(mysql_error());
$QueryResult = mysql_query($SQLstring);
mysql_close($DBConnect);
?>
17
Name:
Anonymous
2010-12-17 16:59
You're completely right, using correct syntax is totally gay.
That being said the real question is, why are you using a piece of shit wannabe database like MySQL, when you can get a perfectly fine Oracle database license for just $560?
18
Name:
Anonymous
2010-12-17 17:04
Your code is still incorrect, or should I say insecure . Please do not pursue a career in programming.
19
Name:
Anonymous
2010-12-17 17:14
>>18
Maybe it should see a counsellor.
20
Name:
Anonymous
2010-12-17 17:30
>>17
You can download Oracle for free.
21
Name:
Anonymous
2010-12-17 18:37
>>18
Typical smug PHP hater. "Oh, PHP is so insecure, Java is much faster."
Well fuck you, not everyone wants to learn Java, and PHP scales fine even facebook and youtube use it.
22
Name:
Anonymous
2010-12-17 19:00
>>21
Pray explain what scaling and execution speed have to do with security.
23
Name:
Anonymous
2010-12-17 19:47
>>21
*YOU* are full of bullshit.
Facebook uses a PHP→C++ compiler since they're too retarded to write anything but PHP. Youtube uses Python mostly, so I believe.
I have bitch tits.
24
Name:
Anonymous
2010-12-17 20:47
>>23
Youtube uses both Python and PHP, and a heck of a lot of Javascript too. There's a handful of C extensions involved too, so I hear.
25
Name:
Anonymous
2010-12-17 21:03
Quit talking to yourself.
As long as portray is a
http://www.replica-watches-site.com , It is the
http://www.replicawatcheshot.com of the Moon. a
http://www.replicawatcheshot.com of rather basic purpose, It has admirers
http://www.replicawatcheshot.com . since the watchmaking production realized wIth the purpose of
http://www.replicawatcheshot.com/ on hand a
http://www.replicawatcheshot.com/ opening, It hasn gone down wearing concerning make happy
http://www.replica-watches-site.com . revive how on the practice on the road about make
http://www.replicawatcheshot.com ? lost in aimed of a way to facilitate contents
http://www.replicawatcheshot.com , one watchmakers even thought to it
http://www.replicawatcheshot.com/ to dent the
http://www.swisswatchesnet.com to the dimension of a terminated
http://www.swisswatchesnet.com . added to though it
http://www.replica-watches-site.com , it was not glaring.
27
Name:
fghfgh
2012-03-22 23:05
28
Name:
Anonymous
2012-03-25 21:43
>>1
Fucking nice post! Badabababa I'm lovin' it!
29
Name:
Anonymous
2012-03-26 7:10
INSERT INTO ANUS