how to look at strings sent from php to mysql

troubleshooting a php-mysql problem

Page 1 of 1

7 Replies - 981 Views - Last Post: 10 June 2008 - 01:36 AM Rate Topic: -----

#1 tannenba  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-June 08

how to look at strings sent from php to mysql

Posted 09 June 2008 - 04:25 PM

Hello, I am trying to teach myself php-sql from "PHP & Mysql for dummies". I am trying to login a new user (from example code in book and getting the error that it couldn't execute the insert query.


 $today = date("Y-m-d");
		$fields_str = implode(",",$fields);
		$values_str = implode('","',$values);
		$fields_str .=",createDate";
		$values_str .='"'.",".'"'.$today;
		$fields_str .=",password";
		$values_str .= '"'.","."md5"."('".$password."')";
		$sql = "INSERT INTO member ";
		$sql .= "(".$fields_str.")";
		$sql .= " VALUES ";
		$sql .= "(".'"'.$values_str.")";
		$result = mysqli_query($cxn,$sql) 
				or die("Couldn't execute final insert query");




The account info is correct, because I get other errors when I try this with the account info wrong.

I believe I might have a problem with the table I made, but it does look ok to me according to the book.

I got to wondering if there is a way to see the code going from php to the mysql server? They are on the same machine (a laptop) that has php (5.2.5), mysql (5) and apache (2.0) on Winxp with sp3. I have error logging turned on, but there is no log file.

Thx,
Joe

Is This A Good Question/Topic? 0
  • +

Replies To: how to look at strings sent from php to mysql

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: how to look at strings sent from php to mysql

Posted 09 June 2008 - 04:36 PM

You can do echo $sql; to see what your query is that is being executed.
Was This Post Helpful? 0
  • +
  • -

#3 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 90
  • View blog
  • Posts: 797
  • Joined: 25-February 08

Re: how to look at strings sent from php to mysql

Posted 09 June 2008 - 04:40 PM

View PostPsychoCoder, on 9 Jun, 2008 - 07:36 PM, said:

You can do echo $sql; to see what your query is that is being executed.


Make sure you post the result of your echo here.
Was This Post Helpful? 0
  • +
  • -

#4 joeyadms  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 41
  • View blog
  • Posts: 178
  • Joined: 04-May 08

Re: how to look at strings sent from php to mysql

Posted 09 June 2008 - 04:56 PM

That can get nasty and hard to debug by adding onto a string that way, it is best just to use multiple lines per variable definition.

I am a little confused with you imploding the fields and values, taking out the commas, if there is more than one field or value, this would cause them to mash together without seperation right?

It is really good practice to not make insert's dynamic.

Doing what Psycho said will help you find the problem fast, but I would suggest rewriting your statements, make them simpler. Assuming your implode works as it should, here is what I would do
<?php
$fields_str = implode(",",$fields);
$values_str = implode('","',$values);
$password = md5($password);
$sql = "INSERT INTO member($fields_str,`createDate`,`password`)
		VALUES('$values_str',CURDATE(),'$password')";
$result = mysqli_query($cxn,$sql)or die("Couldn't execute final insert query");



But it is unsure without the value of $fields, and $values.
Was This Post Helpful? 0
  • +
  • -

#5 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 90
  • View blog
  • Posts: 797
  • Joined: 25-February 08

Re: how to look at strings sent from php to mysql

Posted 09 June 2008 - 05:01 PM

It's looking like PHP and MySql for Dummies was written by a dummy. Ha ha. You can find a lot of great php tutorials here on DIC. Browse through them and you'll pick up a lot of helpful information.
Was This Post Helpful? 0
  • +
  • -

#6 joeyadms  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 41
  • View blog
  • Posts: 178
  • Joined: 04-May 08

Re: how to look at strings sent from php to mysql

Posted 09 June 2008 - 05:04 PM

akozlik, I was thinking the same thing. I can't understand why anyone trying to teach someone something, would present data in such an unreadable and obfuscated way.
Was This Post Helpful? 0
  • +
  • -

#7 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 90
  • View blog
  • Posts: 797
  • Joined: 25-February 08

Re: how to look at strings sent from php to mysql

Posted 09 June 2008 - 05:11 PM

View Postjoeyadms, on 9 Jun, 2008 - 08:04 PM, said:

akozlik, I was thinking the same thing. I can't understand why anyone trying to teach someone something, would present data in such an unreadable and obfuscated way.


I feel like it's that way with a lot of books and tutorials. They try to throw so much information at you at once, that people who are just starting have a hard time following along. That's why when I write my tutorials for DIC I write them to be as simple as possible. Throwing too much at once results in people just not understanding anything.

We should take all the great tutorials in DIC and make our own book. DIC for Dummies.
Was This Post Helpful? 0
  • +
  • -

#8 silverblaze  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 69
  • Joined: 18-January 08

Re: how to look at strings sent from php to mysql

Posted 10 June 2008 - 01:36 AM

Quote

We should take all the great tutorials in DIC and make our own book. DIC for Dummies.


hehe.. i will order 1 rite nw.. :) ... its always gud to have a ref materials. :) ...

you ppl are rite abt most of the tutorials, if we start reading we wont understant evn a bit what they are trying to convey n its real hard to sort out good tutorial whn searching for somethin in web. its nt only the case of php. bt almost all the tutorials are like this. If we read some tuts we will feel tht the author had wrote them to show what all he knes rather than to teach others what they dont knw. Once i went thru a tutorail in CSS. ohh my god its still a nighmare to me..

But even worse is learning videos. they try to teach the entire php in just 6hrs. we wont even understant a bit, if we miss a min of the video thn we will lose the entrie flow. Also it wont stay in memory. After we saw the entire movie we will think what actually we learn. I had seen only one real gud learning video iin php. im nt mentioning its name, bt it was really gud n covers only the basics in a neat n clean way.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1