SV650.org - SV650 & Gladius 650 Forum

SV650.org - SV650 & Gladius 650 Forum (http://forums.sv650.org/index.php)
-   Idle Banter (http://forums.sv650.org/forumdisplay.php?f=116)
-   -   Php help! (http://forums.sv650.org/showthread.php?t=150154)

pudsey 18-04-10 07:25 AM

Php help!
 
This is some php code for a Uni project! It dont work! Can anyone see any errors! Cheers! :confused:




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

?>

Kalessin 18-04-10 10:17 AM

Re: Php help!
 
What error are you getting?

pudsey 18-04-10 10:18 AM

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!

christopher 18-04-10 10:34 AM

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';

Wester 18-04-10 11:11 AM

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.

Kalessin 18-04-10 11:24 AM

Re: Php help!
 
Quote:

Originally Posted by Wester (Post 2245254)
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!

SoulKiss 18-04-10 11:41 AM

Re: Php help!
 
Quote:

Originally Posted by Kalessin (Post 2245259)
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?

Kalessin 18-04-10 11:47 AM

Re: Php help!
 
Also, do you have phpMyAdmin installed? If so, is it working?

GeneticBubble 18-04-10 12:14 PM

Re: Php help!
 
Quote:

Originally Posted by pudsey (Post 2245162)
This is some php code for a Uni project! It dont work! Can anyone see any errors! Cheers! :confused:




<?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...:confused:

TSM 18-04-10 12:24 PM

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.


All times are GMT. The time now is 06:41 PM.

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