webdevRefinery Forum: Can somebody check my PHP-SQL code? - webdevRefinery Forum

Jump to content

  • 3 Pages +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • This topic is locked

User is offline renewaltopics 

  • Group: Members
  • Posts: 53
  • Joined: 25-March 12
  • Expertise:HTML,PHP,Javascript,SQL

Posted 29 July 2012 - 02:19 PM (#1)

Can somebody check my PHP-SQL code?


There is aparentaly an error in my code, can you check for me?
I get a blank PHP page in my browser, so that means a code error because it only prints "Hi" when i take away the $ query = UPDATE part. so is that where
theres an error?



<?php

$con = mysql_connect("localhost","register","mysql");

if (!$con)

{
die("Could not connect: " . mysql_error());
}

mysql_select_db("users");


$query = "UPDATE users SET Email= $_POST["email"]
WHERE Password = 'farts';";

$result= mysql_query($query);

mysql_close($con);

echo "Hi";

?>
0


User is offline Hyde 

  • Group: Members
  • Posts: 1562
  • Joined: 08-March 10

Posted 29 July 2012 - 02:27 PM (#2)

I believe the error is in your SQL query. On the line
WHERE Password = 'farts';";
you have two semi-colons, that could be it.
Hyde | HTML & CSS | PHP & SQL | Objective-C | Java | Basic JavaScript
0


User is offline renewaltopics 

  • Group: Members
  • Posts: 53
  • Joined: 25-March 12
  • Expertise:HTML,PHP,Javascript,SQL

Posted 29 July 2012 - 02:29 PM (#3)

View PostHyde, on 29 July 2012 - 02:27 PM, said:

I believe the error is in your SQL query. On the line
WHERE Password = 'farts';";
you have two semi-colons, that could be it.


I changed it...

<?php

$con = mysql_connect("localhost","register","mysql");

if (!$con)

{
die("Could not connect: " . mysql_error());
}

mysql_select_db("users");


$query = "UPDATE users SET Email= '$_POST["email"]'
WHERE Password = 'farts'";

$result= mysql_query($query);

mysql_close($con);

echo "Hi";

?>

It still gives a blank error page
0


User is offline Hyde 

  • Group: Members
  • Posts: 1562
  • Joined: 08-March 10

Posted 29 July 2012 - 02:34 PM (#4)

By the way :

  • Use [code] tags when pasting code
  • Don't use die(), implement error reporting in a nice way
  • Don't use mysql_ and learn PDO instead
  • Don't put a capital letter as the beginning of row names

Hyde | HTML & CSS | PHP & SQL | Objective-C | Java | Basic JavaScript
0


User is offline renewaltopics 

  • Group: Members
  • Posts: 53
  • Joined: 25-March 12
  • Expertise:HTML,PHP,Javascript,SQL

Posted 29 July 2012 - 02:36 PM (#5)

I plan to use PDO library in the future, but for now, i need to update this data.

<?php

$con = mysql_connect("localhost","register","mysql");

if (!$con)

{
die("Could not connect: " . mysql_error());
}

mysql_select_db("users");


$query = "UPDATE users SET Email= '$_POST["email"]'
WHERE Password = 'farts'";

$result= mysql_query($query);

mysql_close($con);

echo "Hi";

?>


Still accepting all answers
0


User is offline Ruku 

  • I do Linux and that Internet thing.
  • Group: Members
  • Posts: 1349
  • Joined: 17-April 10
  • Location/root
  • Expertise:HTML,CSS,PHP,Javascript,Python,SQL

Posted 29 July 2012 - 02:45 PM (#6)

Find out for yourself; run this in a terminal/command prompt:

php -l file.PHP

0


User is offline renewaltopics 

  • Group: Members
  • Posts: 53
  • Joined: 25-March 12
  • Expertise:HTML,PHP,Javascript,SQL

Posted 29 July 2012 - 02:49 PM (#7)

View PostRuku, on 29 July 2012 - 02:45 PM, said:

Find out for yourself; run this in a terminal/command prompt:

php -l file.PHP



How do I find code bugs in a command prompt?
0


User is offline TheEmpty 

  • I say words in sequences.
  • Group: Members
  • Posts: 5154
  • Joined: 02-October 10
  • Expertise:HTML,CSS,PHP,Java,Javascript,Python,Ruby on Rails,SQL

Posted 29 July 2012 - 03:18 PM (#8)

View Postrenewaltopics, on 29 July 2012 - 02:49 PM, said:

How do I find code bugs in a command prompt?

By running that command.
Reserved.
0


User is offline renewaltopics 

  • Group: Members
  • Posts: 53
  • Joined: 25-March 12
  • Expertise:HTML,PHP,Javascript,SQL

Posted 29 July 2012 - 03:21 PM (#9)

can somebody just tell me my error? im sorry for being impatient i just need to have this page completed in 3 hours.
0


User is offline TheEmpty 

  • I say words in sequences.
  • Group: Members
  • Posts: 5154
  • Joined: 02-October 10
  • Expertise:HTML,CSS,PHP,Java,Javascript,Python,Ruby on Rails,SQL

Posted 29 July 2012 - 03:24 PM (#10)

View Postrenewaltopics, on 29 July 2012 - 03:21 PM, said:

can somebody just tell me my error? im sorry for being impatient i just need to have this page completed in 3 hours.

Then study and read your assigned reading?
Reserved.
0


User is offline renewaltopics 

  • Group: Members
  • Posts: 53
  • Joined: 25-March 12
  • Expertise:HTML,PHP,Javascript,SQL

Posted 29 July 2012 - 03:27 PM (#11)

I keep trying to change certain things in the code, but i cant seem to crack this bug. Can someone please help me, id really appreciate it
0


User is online callumacrae 

  • {{ post.author }}
  • Group: Members
  • Posts: 2862
  • Joined: 20-January 11
  • LocationWarwickshire, England
  • Expertise:HTML,CSS,PHP,Javascript,Node.js,SQL

Posted 29 July 2012 - 03:33 PM (#12)

I don't he's capable of more one point at a time

Try this line:

$query = "UPDATE users SET Email= '$_POST["email"]'
WHERE Password = 'farts'";

Front-end developer and writer
Twitter | GitHub | phpBB Contributor and Website Team Member | lynxphp
0


User is offline renewaltopics 

  • Group: Members
  • Posts: 53
  • Joined: 25-March 12
  • Expertise:HTML,PHP,Javascript,SQL

Posted 29 July 2012 - 03:34 PM (#13)

am i getting an answer please?

View Postcallumacrae, on 29 July 2012 - 03:33 PM, said:

I don't he's capable of more one point at a time

Try this line:

$query = "UPDATE users SET Email= '$_POST["email"]'
WHERE Password = 'farts'";



thats the same exact thing as my error code
0


User is online callumacrae 

  • {{ post.author }}
  • Group: Members
  • Posts: 2862
  • Joined: 20-January 11
  • LocationWarwickshire, England
  • Expertise:HTML,CSS,PHP,Javascript,Node.js,SQL

Posted 29 July 2012 - 03:36 PM (#14)

In PHP, how do you put an array element in a string?
Front-end developer and writer
Twitter | GitHub | phpBB Contributor and Website Team Member | lynxphp
0


User is offline renewaltopics 

  • Group: Members
  • Posts: 53
  • Joined: 25-March 12
  • Expertise:HTML,PHP,Javascript,SQL

Posted 29 July 2012 - 03:40 PM (#15)

View Postcallumacrae, on 29 July 2012 - 03:36 PM, said:

In PHP, how do you put an array element in a string?



string implode ( array $pieces )
0


User is online callumacrae 

  • {{ post.author }}
  • Group: Members
  • Posts: 2862
  • Joined: 20-January 11
  • LocationWarwickshire, England
  • Expertise:HTML,CSS,PHP,Javascript,Node.js,SQL

Posted 29 July 2012 - 03:43 PM (#16)

Nope. I meant like this:

$a = "abc $abc abc";


But with
$abc['abc']
instead of
$abc

Front-end developer and writer
Twitter | GitHub | phpBB Contributor and Website Team Member | lynxphp
0


User is offline renewaltopics 

  • Group: Members
  • Posts: 53
  • Joined: 25-March 12
  • Expertise:HTML,PHP,Javascript,SQL

Posted 29 July 2012 - 03:45 PM (#17)

yeah its a different method of writing an array. so whats the point?
0


User is online callumacrae 

  • {{ post.author }}
  • Group: Members
  • Posts: 2862
  • Joined: 20-January 11
  • LocationWarwickshire, England
  • Expertise:HTML,CSS,PHP,Javascript,Node.js,SQL

Posted 29 July 2012 - 03:47 PM (#18)

If you know how to do it, you know how to solve your problem.
Front-end developer and writer
Twitter | GitHub | phpBB Contributor and Website Team Member | lynxphp
0


User is offline renewaltopics 

  • Group: Members
  • Posts: 53
  • Joined: 25-March 12
  • Expertise:HTML,PHP,Javascript,SQL

Posted 29 July 2012 - 03:48 PM (#19)

ok, but i dont know where the porblem is... ive done the same thing before and it worked. so thats why im very confused where my error is
0


User is online callumacrae 

  • {{ post.author }}
  • Group: Members
  • Posts: 2862
  • Joined: 20-January 11
  • LocationWarwickshire, England
  • Expertise:HTML,CSS,PHP,Javascript,Node.js,SQL

Posted 29 July 2012 - 03:54 PM (#20)

$a = "b $c["d"] e";


That code isn't valid, do you see why?
Front-end developer and writer
Twitter | GitHub | phpBB Contributor and Website Team Member | lynxphp
0


Share this topic:


  • 3 Pages +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • This topic is locked

4 User(s) are reading this topic
0 members, 4 guests, 0 anonymous users


Enter your sign in name and password


Sign in options
  Or sign in with these services