SV650.org - SV650 & Gladius 650 Forum



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).
There's also a "U" rating so please respect this. Newbies can also say "hello" here too.

Reply
 
Thread Tools
Old 18-04-10, 07:25 AM   #1
pudsey
Guest
 
Posts: n/a
Default Php help!

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());

?>
  Reply With Quote
Old 18-04-10, 10:17 AM   #2
Kalessin
Member
 
Kalessin's Avatar
 
Join Date: Jan 2009
Location: Northampton
Posts: 81
Default Re: Php help!

What error are you getting?
__________________
¡ƃuıop ɯ,ı ʇɐɥʍ ʍouʞ ı ˙˙˙ǝɯ ʇsnɹʇ
Kalessin is offline   Reply With Quote
Old 18-04-10, 10:18 AM   #3
pudsey
Guest
 
Posts: n/a
Default Re: Php help!

There is no error - it just wont write anything to the database I have set up! been annoying me all night long!
  Reply With Quote
Old 18-04-10, 10:34 AM   #4
christopher
Member
 
christopher's Avatar
 
Join Date: Apr 2009
Location: Chester, UK
Posts: 795
Default Re: Php help!

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';
christopher is offline   Reply With Quote
Old 18-04-10, 11:11 AM   #5
Wester
Guest
 
Posts: n/a
Default Re: Php help!

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.
  Reply With Quote
Old 18-04-10, 11:24 AM   #6
Kalessin
Member
 
Kalessin's Avatar
 
Join Date: Jan 2009
Location: Northampton
Posts: 81
Default Re: Php help!

Quote:
Originally Posted by Wester View Post
I think something slightly worse is awry if you are not getting any error messages at all
Not necessarily. If using an integrated LAMP stack such as XAMPP or MAMP, PHP errors may be written to an error log rather than displayed on screen.

Pudsey, check your error logs!
__________________
¡ƃuıop ɯ,ı ʇɐɥʍ ʍouʞ ı ˙˙˙ǝɯ ʇsnɹʇ
Kalessin is offline   Reply With Quote
Old 18-04-10, 11:41 AM   #7
SoulKiss
Member
Mega Poster
 
SoulKiss's Avatar
 
Join Date: Jul 2006
Location: Sunny Croydonia
Posts: 6,124
Default Re: Php help!

Quote:
Originally Posted by Kalessin View Post
Not necessarily. If using an integrated LAMP stack such as XAMPP or MAMP, PHP errors may be written to an error log rather than displayed on screen.

Pudsey, check your error logs!
Check your mySQL logs too, could be a permissions thing on the database.

Can you log into mySQL using those credentials and do an insert?
__________________
Sent from my PC NOT using any Tapatalk type rubbish!!

█╬╬╬╬()i¯i▀▀▀▀▀█Ξ███████████████████████████████)
SoulKiss is offline   Reply With Quote
Old 18-04-10, 11:47 AM   #8
Kalessin
Member
 
Kalessin's Avatar
 
Join Date: Jan 2009
Location: Northampton
Posts: 81
Default Re: Php help!

Also, do you have phpMyAdmin installed? If so, is it working?
__________________
¡ƃuıop ɯ,ı ʇɐɥʍ ʍouʞ ı ˙˙˙ǝɯ ʇsnɹʇ
Kalessin is offline   Reply With Quote
Old 18-04-10, 12:14 PM   #9
GeneticBubble
Guest
 
Posts: n/a
Default Re: Php help!

Quote:
Originally Posted by pudsey View Post
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());

?>


what is this...i dont even...
  Reply With Quote
Old 18-04-10, 12:24 PM   #10
TSM
The Sick Man
Mega Poster
 
TSM's Avatar
 
Join Date: Nov 2004
Location: Peckham.SE.LDN
Posts: 4,768
Default Re: Php help!

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());
  }
}
Saftey points...
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());
  }
}
Its not OOP but should work fine if you just want a simple connection and query.
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
TSM is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:15 AM.


Powered by vBulletin® - Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.