Idle Banter For non SV and non bike related chat (and the odd bit of humour - but if any post isn't suitable it'll get deleted real quick).![]() |
![]() |
|
Thread Tools |
![]() |
#1 |
Guest
Posts: n/a
|
![]()
This is some php code for a Uni project! It dont work! Can anyone see any errors! Cheers!
![]() <?php $connect = mysql_connect("localhost","root","live@49"); $db = mysql_select_db("flashphptask_zxq_customers", $connect); $sql = mysql_query("INSERT INTO comments (ID, Name, eMail, Comments) VALUE ('$ID', '$Name','$eMail','$Comments')")or die (mysql_error()); ?> |
![]() |
![]() |
#2 |
Member
Join Date: Jan 2009
Location: Northampton
Posts: 81
|
![]()
What error are you getting?
__________________
¡ƃuıop ɯ,ı ʇɐɥʍ ʍouʞ ı ˙˙˙ǝɯ ʇsnɹʇ |
![]() |
![]() |
![]() |
#3 |
Guest
Posts: n/a
|
![]()
There is no error - it just wont write anything to the database I have set up! been annoying me all night long!
|
![]() |
![]() |
#4 |
Member
Join Date: Apr 2009
Location: Chester, UK
Posts: 795
|
![]()
Assuming you have given a value to the variables you're using within the query then it will work... you have given the variables a value haven't you? I.e.
$ID = 'This goes in the ID column'; $Name = 'And this in the Name column'; |
![]() |
![]() |
![]() |
#5 |
Guest
Posts: n/a
|
![]()
I think something slightly worse is awry if you are not getting any error messages at all, but you could try these suggestions.
Why are you inserting an ID? is that the id for your item that will be incremented each time you add a new item? if so you should have it set as an auto_increment column in mysql, Then you wont need to insert it manually each time. What is the column type for name, email and comments? If they are set to text you need to be adding them in the SQL query as such: ("INSERT INTO comments (ID, Name, eMail, Comments) VALUE ('$ID', \''$Name'\',\''$eMail'\',\''$Comments'\')") Hope that helps. |
![]() |
![]() |
#6 | |
Member
Join Date: Jan 2009
Location: Northampton
Posts: 81
|
![]() Quote:
Pudsey, check your error logs!
__________________
¡ƃuıop ɯ,ı ʇɐɥʍ ʍouʞ ı ˙˙˙ǝɯ ʇsnɹʇ |
|
![]() |
![]() |
![]() |
#7 | |
Member
Mega Poster
Join Date: Jul 2006
Location: Sunny Croydonia
Posts: 6,124
|
![]() Quote:
Can you log into mySQL using those credentials and do an insert?
__________________
Sent from my PC NOT using any Tapatalk type rubbish!! █╬╬╬╬(•)i¯i▀▀▀▀▀█Ξ███████████████████████████████) |
|
![]() |
![]() |
![]() |
#8 |
Member
Join Date: Jan 2009
Location: Northampton
Posts: 81
|
![]()
Also, do you have phpMyAdmin installed? If so, is it working?
__________________
¡ƃuıop ɯ,ı ʇɐɥʍ ʍouʞ ı ˙˙˙ǝɯ ʇsnɹʇ |
![]() |
![]() |
![]() |
#9 | |
Guest
Posts: n/a
|
![]() Quote:
what is this...i dont even... ![]() |
|
![]() |
![]() |
#10 |
The Sick Man
Mega Poster
Join Date: Nov 2004
Location: Peckham.SE.LDN
Posts: 4,768
|
![]() Code:
$con = mysql_connect("localhost","root","live@49"); if(!$con){ die("Error conn - ".mysql_error()); }else{ $db = mysql_select_db("flashphptask_zxq_customers", $con); if(!$db){ die("Error changedb - ".mysql_error()); }else{ $sql = mysql_query("INSERT INTO comments (ID, Name, eMail, Comments) VALUE ('$ID', '$Name','$eMail','$Comments')",$db)or die (mysql_error()); } } make sure you use mysql_real_escape_string() on your insert values, dont forget the ; at the end as an additional saftey, mabey wrap your query up with a sprintf such as... Code:
$con = mysql_connect("localhost","root","live@49"); if(!$con){ die("Error conn - ".mysql_error()); }else{ $db = mysql_select_db("flashphptask_zxq_customers", $con); if(!$db){ die("Error changedb - ".mysql_error()); }else{ $sqlstring=sprintf("INSERT INTO comments (ID, Name, eMail, Comments) VALUE ('%u', '%s',%s','%s');", $ID, mysql_real_escape_string($Name), mysql_real_escape_string($eMail), mysql_real_escape_string($Comments)); $sql = mysql_query($sqlstring,$db)or die ("Error query - ".mysql_error()); } } You could just use PDO or get a DB Class to do most of it for you in OOP standard.
__________________
OTR: KTM 690 Duke R 2015 Full Akro SIDELINE: Kwak ZX636 A1P 2002, Red, R&G's, Yoshi, Double Bubble Screen GONE: Kwak ZX-7R P1, Full Akro, Undertray, Screen GONE: SV650S K2 Very Bruised & Without Fairing, Motovation Frame Sliders, R&G Ally Sprocket Toe Protector, HEL 2 Line Setup, GSXR K1 600 RWU Forks, Barnett Clutch & Springs, Penske 8981 Shock, Gilles Ti Rearsets, Steel Barends, Scottoiler, AFAM Chain & Sprockets, Twin FIAMM Horns, Skidmarx Bellypan, Full Micron Zeta Steel System, Cut down undertay. Forum Problems & Information / Site Suggestions |
![]() |
![]() |
![]() |
|
|