RON_ron
-
Posts
370 -
Joined
-
Last visited
Posts posted by RON_ron
-
-
I want to change the Default value of my db to None. Currently it's Null. Could someone show me the syntax to change the NULL in to None (Default value)?
I thought this would work... but no luck.?
$sql = "ALTER TABLE my_db MODIFY (name VARCHAR(100) None, mail VARCHAR(100) None, phone TIMESTAMP(30) None)"; mysql_query($sql,$conn);
-
Thanks btherl.
Is it possible to use the array created ($Array1) instead of repeating the field names?
-
OK. I've used the "COUNT" command before but not with the "IN" command.
$sql = "SELECT rowBa, rowBb, rowBc, rowBd, rowBe COUNT(*) AS cnt FROM my_db2 WHERE rowBa, rowBb, rowBc, rowBd, rowBe = 'YES'"; if ($result = mysql_query($sql)) { $output = mysql_result($result, 0); }
-
I've included the FROM... that did not fix the issue.
$sql = "SELECT COUNT(*) AS cnt FROM my_db2 WHERE 'YES' IN(rowBa, rowBb, rowBc, rowBd, rowBe)"; if ($result = mysql_query($sql)) { $output = mysql_result($result, 0); }
-
simple as that!
Thanks Thorpe.
-
I'm trying to incorporate mysql_real_escape_string to my existing script. But doesn't seem to work. Could someone point out what's the reason.
$abc =sprintf("INSERT INTO my_db1 (username, password, firstname, company, email) VALUES ('%s', '%s', '%s', '%s', '%s'", mysql_real_escape_string($username), mysql_real_escape_string($password), mysql_real_escape_string($surname), mysql_real_escape_string($firstname), mysql_real_escape_string($company), mysql_real_escape_string($email))); $resultg = mysql_query($abc);
-
strtotime($date->format('H:i:s'));
time();
-
Thanks. But the adding the missing brackets did not solve the issue.
$abc =sprintf("INSERT INTO my_db1 (username, password, firstname, company, email) VALUES ('%s', '%s', '%s', '%s', '%s'", mysql_real_escape_string($username), mysql_real_escape_string($password), mysql_real_escape_string($surname), mysql_real_escape_string($firstname), mysql_real_escape_string($company), mysql_real_escape_string($email))); $resultg = mysql_query($abc);
-
Sorry for being babyish! But I'm not knowing what to do here.
When I insert that piece of code it gives this;
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax
$S1 = array(); $Array1 = array(); $Variable1 = 'somename'; $query1 = "SELECT * FROM my_db1 WHERE username = '".$Variable1."'"; $result1 = mysql_query($query1); $score1 = mysql_fetch_assoc($result1); foreach (range('a','e') as $ltr) { $S1[] = array($score1['mopA' . $ltr]); } $Variable2 = 'nextX'; $query1 = "SELECT * FROM my_db2 WHERE rdx = '".$Variable2."'"; $result = mysql_query($query1); $scoreM = mysql_fetch_assoc($result); foreach (range('a','e') as $ltr) { $Array1[] = array($scoreM['rowB' . $ltr]); } $count = array(); for($i=0;$i<count($S1);++$i) { $count[$i] = count(array_intersect($S1[$i],$Array1[$i])); } $points = array_sum($count); echo $points; $sql = "SELECT COUNT(*) AS cnt WHERE 'YES' IN(rowBa, rowBb, rowBc, rowBd, rowBe)"; if ($result = mysql_query($sql)) { $output = mysql_result($result, 0); } echo $output;
Thanks for helping me out.
-
Hey thorpe.... I'm curious... isn't the table name required after the SELECT?
$sql = "SELECT COUNT(*) AS cnt WHERE 'YES' IN(rowBa, rowBb, rowBc, rowBd, rowBe)"; if ($result = mysql_query($sql)) { echo mysql_result($result, 0); }
-
Why would you have 5 fields all containing the same or similar data?
I really appreciate your input thorpe.
Those columns actually represents Months and rowBa, rowBb, rowBc... row stands for the project we're doing and B stands for the team name. Then 1, 2, 3... to differentiate the fields. Is it still poorly designed?
Thank you so much for the additional input.
-
Could someone tell what's wrong here?
$abc =sprintf("INSERT INTO my_db1 (username, password, firstname, company, email) VALUES ('%s', '%s', '%s', '%s', '%s'", mysql_real_escape_string($username), mysql_real_escape_string($password, mysql_real_escape_string($surname, mysql_real_escape_string($firstname, mysql_real_escape_string($company, mysql_real_escape_string($email))); $resultg = mysql_query($abc);
Thanks!
-
Hi sweeb.... Thanks (and welcome)
Actually I want to get the COUNT of 'YES' from the entire databse.
E.g.
rowBa | rowBb | rowBc | rowBd | rowBe
NO | YES | NO | NO | NO
NO | NO | YES | YES | YES
NO | YES | NO | YES | NO
count = 6
-
There is an error.
Parse error: syntax error, unexpected ')'
and I removed a bracket from (marked in red) mysql_fetch_assoc($result)) then it gives another error.
Parse error: syntax error, unexpected '{'
-
The structure is like this and the word 'YES' might be in the following fields in my_db2.
Thank you.
-
This is my existing code and I need to get the COUNT of the fields which contain the word "YES" out of my_db2.
$S1 = array(); $Array1 = array(); $Variable1 = 'somename'; $query1 = "SELECT * FROM my_db1 WHERE username = '".$Variable1."'"; $result1 = mysql_query($query1); $score1 = mysql_fetch_assoc($result1); foreach (range('a','e') as $ltr) { $S1[] = array($score1['mopA' . $ltr]); } $Variable2 = 'nextX'; $query1 = "SELECT * FROM my_db2 WHERE rdx = '".$Variable2."'"; $result = mysql_query($query1); $scoreM = mysql_fetch_assoc($result); foreach (range('a','e') as $ltr) { $Array1[] = array($scoreM['rowB' . $ltr]); } $count = array(); for($i=0;$i<count($S1);++$i) { $count[$i] = count(array_intersect($S1[$i],$Array1[$i])); } $points = array_sum($count); echo $points;
The below code worked before I brought in the arrays. But now I'm dealing with arrays and I'm not knowing how to get the count of the fields which contain the word "YES" in my_db2.
$result = array_count_values($Array1); if (isset($result['YES'])) { $points = $result['YES']; }
Thanks and appreciate for helping!
-
Below was my code. that works. I'm trying to convert this using the arrays.
$Array1 = array($winRa1, $winRa2, $winRa3, $winRa4, $winRa5, $winRa6, $winRa7, $winRa8); $result = array_count_values($Array1); if (isset($result['YES'])) { $points = $result['YES']; }
This is what I'm trying to do now. Basically I need to get the COUNT of the fields which contain the word "YES".
$ArrayM1 = array(); $Var = 'name'; $query = "SELECT * FROM db WHERE username = '".$Var."'"; $result = mysql_query($query); $score = mysql_fetch_assoc($result); foreach (range('1','2') as $ltr) { $ArrayM1[] = array($score['ro' . $ltr]); } $Array1 = array(); for($j=0;$j<count($ArrayM1);++$j) { $result = array_count_values($ArrayM1[$j]); if (isset($result['YES'])) { $points1 = $result['YES']; } }
-
I want to get the COUNT of the fields (ArrayM11 - ArrayM19), which has the word "YES". The code isn't working. Appreciate any help.
$Array1 = array(); for($j=0;$j<count($ArrayM1);++$j) { $result = array_count_values($ArrayM1[$j]); if (isset($result['YES'])) { $points1 = $result['YES']; } }
-
Something like this?
<?php $conn = mysql_connect("localhost","my_un","my_pw"); mysql_select_db("my_db"); foreach ($_POST as $key => $value) { $$key = $value; $$key = mysql_real_escape_string($$key); } $result = mysql_query("SELECT * FROM my_db2 WHERE username = '$username'"); $mypost = array_map('mysql_real_escape_string',$_POST); if (mysql_num_rows ($result) > 0){ $register = "Retry."; echo($register); } else { mysql_query("INSERT INTO my_db3 (username, password, surname, firstname, company) VALUES ('$username', '$password', '$surname', '$firstname', '$company')"); $register = "Successful."; echo($register); } ?>
-
I need to send some of the data to my php file via flash. Below in my php file I'm trying to use a for-loop to convert all the variables to php variables to prevent sql injection. How effective is this method? Please help me with your valuable ideas.
Thank you.
<?php $conn = mysql_connect("localhost","my_un","my_pw"); mysql_select_db("my_db"); foreach ($_POST as $key => $value) { $$key = $value; $$key = mysql_real_escape_string($$key); } $result = mysql_query("SELECT * FROM my_db2 WHERE username = '$username'"); if (mysql_num_rows ($result) > 0){ $register = "Retry."; echo($register); } else { mysql_query("INSERT INTO my_db3 (username, password, surname, firstname, company) VALUES ('$username', '$password', '$surname', '$firstname', '$company')"); $register = "Successful."; echo($register); } ?>
-
You seriously need to learn some debugging and manual reading skills
Accepted.
and learning nothing from the answers.What are you referring to?
You have not provided anywhere near enough informationMy question was "I'm unable to update the table. Could someone tell me why?"
Basically when i use this code it doesn't update the mysql db.
in addition.
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_VARIABLE or '$' in /home/.../test.php on line 5
-
I'm unable to update the table. Could someone tell me why?
$dfield1 = mysql_real_escape_string($field1); $dfield2 = mysql_real_escape_string($field2); $dfield3 = mysql_real_escape_string($field3); $dfield4 = mysql_real_escape_string($field4); $result =sprintf("SELECT * FROM db1 WHERE username ='%s'", $dfield1); $resultf = mysql_query($result); if (mysql_num_rows ($resultf) > 0){ $register = "&err=Not Available. Retry."; echo($register); } else { mysql_query("INSERT INTO db1 (name, birthday, street, phone) VALUES ('$dfield1', '$dfield2', '$dfield3', '$dfield4')"); $register = "Successful."; echo($register); }
-
Works a charm! Thanks thorpe!!
-
Thanks sniperscope.
Is that effective? This is my first attempt in using "mysql_real_escape_string". So I'm not sure what's perfect.
Automatically Update Marks...
in MySQL Help
Posted
I'm creating a system to calculate the marks of a students examination.
db1
The students is asked to select the correct answer out of 3 given answers (A, B or C). All those answers will be stored in a MYSQL db (below is the db design example).
| Question 1 | Question 2 | Question 3 | Question 4 | Question 5 | Your Marks |
Mickey | A | C | C | A | B | 0 |
Nathan | C | B | C | B | A | 0 |
Jeff | A | C | C | A | B | 0 |
db2
The correct answers will be stored in a separate db. The correct answers will be updated after the exam is over. (below is the db design example).
| Question 1 | Question 2 | Question 3 | Question 4 | Question 5 |
Section A | A | C | C | A | B |
Section B | C | B | C | B | A |
Section C | A | C | C | A | B |
Now here come my question.... How do I automatically update the Your Marks column when I post the correct answers to db2.
Basically I need a way to match db2 results against db1 for each row and update Your Marks with the COUNT of the matching answers for each student.
Example: Here's how db1 should be when the answers are updated in db2.
| Question 1 | Question 2 | Question 3 | Question 4 | Question 5 | Your Marks |
Mickey | A | C | C | A | B | 5 |
Nathan | C | B | C | B | B | 4 |
Jeff | B | B | B | B | B | 1 |
Hope my question is clear. I really appreciate your help. Thank you!